finish docs?
[pspp] / doc / statistics.texi
1 @c PSPP - a program for statistical analysis.
2 @c Copyright (C) 2017, 2020 Free Software Foundation, Inc.
3 @c Permission is granted to copy, distribute and/or modify this document
4 @c under the terms of the GNU Free Documentation License, Version 1.3
5 @c or any later version published by the Free Software Foundation;
6 @c with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
7 @c A copy of the license is included in the section entitled "GNU
8 @c Free Documentation License".
9 @c
10 @node Statistics
11 @chapter Statistics
12
13 This chapter documents the statistical procedures that @pspp{} supports so
14 far.
15
16 @menu
17 * DESCRIPTIVES::                Descriptive statistics.
18 * FREQUENCIES::                 Frequency tables.
19 * EXAMINE::                     Testing data for normality.
20 * GRAPH::                       Plot data.
21 * CORRELATIONS::                Correlation tables.
22 * CROSSTABS::                   Crosstabulation tables.
23 * CTABLES::                     Custom tables.
24 * FACTOR::                      Factor analysis and Principal Components analysis.
25 * GLM::                         Univariate Linear Models.
26 * LOGISTIC REGRESSION::         Bivariate Logistic Regression.
27 * MEANS::                       Average values and other statistics.
28 * NPAR TESTS::                  Nonparametric tests.
29 * T-TEST::                      Test hypotheses about means.
30 * ONEWAY::                      One way analysis of variance.
31 * QUICK CLUSTER::               K-Means clustering.
32 * RANK::                        Compute rank scores.
33 * RELIABILITY::                 Reliability analysis.
34 * ROC::                         Receiver Operating Characteristic.
35 @end menu
36
37 @node DESCRIPTIVES
38 @section DESCRIPTIVES
39
40 @vindex DESCRIPTIVES
41 @display
42 DESCRIPTIVES
43         /VARIABLES=@var{var_list}
44         /MISSING=@{VARIABLE,LISTWISE@} @{INCLUDE,NOINCLUDE@}
45         /FORMAT=@{LABELS,NOLABELS@} @{NOINDEX,INDEX@} @{LINE,SERIAL@}
46         /SAVE
47         /STATISTICS=@{ALL,MEAN,SEMEAN,STDDEV,VARIANCE,KURTOSIS,
48                      SKEWNESS,RANGE,MINIMUM,MAXIMUM,SUM,DEFAULT,
49                      SESKEWNESS,SEKURTOSIS@}
50         /SORT=@{NONE,MEAN,SEMEAN,STDDEV,VARIANCE,KURTOSIS,SKEWNESS,
51                RANGE,MINIMUM,MAXIMUM,SUM,SESKEWNESS,SEKURTOSIS,NAME@}
52               @{A,D@}
53 @end display
54
55 The @cmd{DESCRIPTIVES} procedure reads the active dataset and outputs
56 linear descriptive statistics requested by the user.  In addition, it can optionally
57 compute Z-scores.
58
59 The @subcmd{VARIABLES} subcommand, which is required, specifies the list of
60 variables to be analyzed.  Keyword @subcmd{VARIABLES} is optional.
61
62 All other subcommands are optional:
63
64 The @subcmd{MISSING} subcommand determines the handling of missing variables.  If
65 @subcmd{INCLUDE} is set, then user-missing values are included in the
66 calculations.  If @subcmd{NOINCLUDE} is set, which is the default, user-missing
67 values are excluded.  If @subcmd{VARIABLE} is set, then missing values are
68 excluded on a variable by variable basis; if @subcmd{LISTWISE} is set, then
69 the entire case is excluded whenever any value in that case has a
70 system-missing or, if @subcmd{INCLUDE} is set, user-missing value.
71
72 The @subcmd{FORMAT} subcommand has no effect.  It is accepted for
73 backward compatibility.
74
75 The @subcmd{SAVE} subcommand causes @cmd{DESCRIPTIVES} to calculate Z scores for all
76 the specified variables.  The Z scores are saved to new variables.
77 Variable names are generated by trying first the original variable name
78 with Z prepended and truncated to a maximum of 8 characters, then the
79 names ZSC000 through ZSC999, STDZ00 through STDZ09, ZZZZ00 through
80 ZZZZ09, ZQZQ00 through ZQZQ09, in that sequence.  In addition, Z score
81 variable names can be specified explicitly on @subcmd{VARIABLES} in the variable
82 list by enclosing them in parentheses after each variable.
83 When Z scores are calculated, @pspp{} ignores @cmd{TEMPORARY},
84 treating temporary transformations as permanent.
85
86 The @subcmd{STATISTICS} subcommand specifies the statistics to be displayed:
87
88 @table @code
89 @item @subcmd{ALL}
90 All of the statistics below.
91 @item @subcmd{MEAN}
92 Arithmetic mean.
93 @item @subcmd{SEMEAN}
94 Standard error of the mean.
95 @item @subcmd{STDDEV}
96 Standard deviation.
97 @item @subcmd{VARIANCE}
98 Variance.
99 @item @subcmd{KURTOSIS}
100 Kurtosis and standard error of the kurtosis.
101 @item @subcmd{SKEWNESS}
102 Skewness and standard error of the skewness.
103 @item @subcmd{RANGE}
104 Range.
105 @item MINIMUM
106 Minimum value.
107 @item MAXIMUM
108 Maximum value.
109 @item SUM
110 Sum.
111 @item DEFAULT
112 Mean, standard deviation of the mean, minimum, maximum.
113 @item SEKURTOSIS
114 Standard error of the kurtosis.
115 @item SESKEWNESS
116 Standard error of the skewness.
117 @end table
118
119 The @subcmd{SORT} subcommand specifies how the statistics should be sorted.  Most
120 of the possible values should be self-explanatory.  @subcmd{NAME} causes the
121 statistics to be sorted by name.  By default, the statistics are listed
122 in the order that they are specified on the @subcmd{VARIABLES} subcommand.
123 The @subcmd{A} and @subcmd{D} settings request an ascending or descending
124 sort order, respectively.
125
126 @subsection Descriptives Example
127
128 The @file{physiology.sav} file contains various physiological data for a sample
129 of persons.   Running the @cmd{DESCRIPTIVES} command on the variables @exvar{height}
130 and @exvar{temperature} with the default options allows one to see simple linear
131 statistics for these two variables.  In @ref{descriptives:ex}, these variables
132 are specfied on the @subcmd{VARIABLES} subcommand and the @subcmd{SAVE} option
133 has been used, to request that Z scores be calculated.
134
135 After the command has completed, this example runs @cmd{DESCRIPTIVES} again, this
136 time on the @exvar{zheight} and @exvar{ztemperature} variables,
137 which are the two normalized (Z-score) variables generated by the
138 first @cmd{DESCRIPTIVES} command.
139
140 @float Example, descriptives:ex
141 @psppsyntax {descriptives.sps}
142 @caption {Running two @cmd{DESCRIPTIVES} commands, one with the @subcmd{SAVE} subcommand}
143 @end float
144
145 @float Screenshot, descriptives:scr
146 @psppimage {descriptives}
147 @caption {The Descriptives dialog box with two variables and Z-Scores option selected}
148 @end float
149
150 In @ref{descriptives:res}, we can see that there are 40 valid data for each of the variables
151 and no missing values.   The mean average of the height and temperature is 16677.12
152 and 37.02 respectively.  The descriptive statistics for temperature seem reasonable.
153 However there is a very high standard deviation for @exvar{height} and a suspiciously
154 low minimum.  This is due to a data entry error in the
155 data (@pxref{Identifying incorrect data}).
156
157 In the second Descriptive Statistics command, one can see that the mean and standard
158 deviation of both Z score variables is 0 and 1 respectively.  All Z score statistics
159 should have these properties since they are normalized versions of the original scores.
160
161 @float Result, descriptives:res
162 @psppoutput {descriptives}
163 @caption {Descriptives statistics including two normalized variables (Z-scores)}
164 @end float
165
166 @node FREQUENCIES
167 @section FREQUENCIES
168
169 @vindex FREQUENCIES
170 @display
171 FREQUENCIES
172         /VARIABLES=@var{var_list}
173         /FORMAT=@{TABLE,NOTABLE,LIMIT(@var{limit})@}
174                 @{AVALUE,DVALUE,AFREQ,DFREQ@}
175         /MISSING=@{EXCLUDE,INCLUDE@}
176         /STATISTICS=@{DEFAULT,MEAN,SEMEAN,MEDIAN,MODE,STDDEV,VARIANCE,
177                      KURTOSIS,SKEWNESS,RANGE,MINIMUM,MAXIMUM,SUM,
178                      SESKEWNESS,SEKURTOSIS,ALL,NONE@}
179         /NTILES=@var{ntiles}
180         /PERCENTILES=percent@dots{}
181         /HISTOGRAM=[MINIMUM(@var{x_min})] [MAXIMUM(@var{x_max})]
182                    [@{FREQ[(@var{y_max})],PERCENT[(@var{y_max})]@}] [@{NONORMAL,NORMAL@}]
183         /PIECHART=[MINIMUM(@var{x_min})] [MAXIMUM(@var{x_max})]
184                   [@{FREQ,PERCENT@}] [@{NOMISSING,MISSING@}]
185         /BARCHART=[MINIMUM(@var{x_min})] [MAXIMUM(@var{x_max})]
186                   [@{FREQ,PERCENT@}]
187         /ORDER=@{ANALYSIS,VARIABLE@}
188
189
190 (These options are not currently implemented.)
191         /HBAR=@dots{}
192         /GROUPED=@dots{}
193 @end display
194
195 The @cmd{FREQUENCIES} procedure outputs frequency tables for specified
196 variables.
197 @cmd{FREQUENCIES} can also calculate and display descriptive statistics
198 (including median and mode) and percentiles, and various graphical representations
199 of the frequency distribution.
200
201 The @subcmd{VARIABLES} subcommand is the only required subcommand.  Specify the
202 variables to be analyzed.
203
204 The @subcmd{FORMAT} subcommand controls the output format.  It has several
205 possible settings:
206
207 @itemize @subcmd{}
208 @item
209 @subcmd{TABLE}, the default, causes a frequency table to be output for every
210 variable specified.  @subcmd{NOTABLE} prevents them from being output.  @subcmd{LIMIT}
211 with a numeric argument causes them to be output except when there are
212 more than the specified number of values in the table.
213
214 @item
215 Normally frequency tables are sorted in ascending order by value.  This
216 is @subcmd{AVALUE}.  @subcmd{DVALUE} tables are sorted in descending order by value.
217 @subcmd{AFREQ} and @subcmd{DFREQ} tables are sorted in ascending and descending order,
218 respectively, by frequency count.
219 @end itemize
220
221 The @subcmd{MISSING} subcommand controls the handling of user-missing values.
222 When @subcmd{EXCLUDE}, the default, is set, user-missing values are not included
223 in frequency tables or statistics.  When @subcmd{INCLUDE} is set, user-missing
224 are included.  System-missing values are never included in statistics,
225 but are listed in frequency tables.
226
227 The available @subcmd{STATISTICS} are the same as available
228 in @cmd{DESCRIPTIVES} (@pxref{DESCRIPTIVES}), with the addition
229 of @subcmd{MEDIAN}, the data's median
230 value, and MODE, the mode.  (If there are multiple modes, the smallest
231 value is reported.)  By default, the mean, standard deviation of the
232 mean, minimum, and maximum are reported for each variable.
233
234 @cindex percentiles
235 @subcmd{PERCENTILES} causes the specified percentiles to be reported.
236 The percentiles should  be presented at a list of numbers between 0
237 and 100 inclusive.
238 The @subcmd{NTILES} subcommand causes the percentiles to be reported at the
239 boundaries of the data set divided into the specified number of ranges.
240 For instance, @subcmd{/NTILES=4} would cause quartiles to be reported.
241
242 @cindex histogram
243 The @subcmd{HISTOGRAM} subcommand causes the output to include a histogram for
244 each specified numeric variable.  The X axis by default ranges from
245 the minimum to the maximum value observed in the data, but the @subcmd{MINIMUM}
246 and @subcmd{MAXIMUM} keywords can set an explicit range.
247 @footnote{The number of
248 bins is chosen according to the Freedman-Diaconis rule:
249 @math{2 \times IQR(x)n^{-1/3}}, where @math{IQR(x)} is the interquartile range of @math{x}
250 and @math{n} is the number of samples.    Note that
251 @cmd{EXAMINE} uses a different algorithm to determine bin sizes.}
252 Histograms are not created for string variables.
253
254 Specify @subcmd{NORMAL} to superimpose a normal curve on the
255 histogram.
256
257 @cindex piechart
258 The @subcmd{PIECHART} subcommand adds a pie chart for each variable to the data.  Each
259 slice represents one value, with the size of the slice proportional to
260 the value's frequency.  By default, all non-missing values are given
261 slices.
262 The @subcmd{MINIMUM} and @subcmd{MAXIMUM} keywords can be used to limit the
263 displayed slices to a given range of values.
264 The keyword @subcmd{NOMISSING} causes missing values to be omitted from the
265 piechart.  This is the default.
266 If instead, @subcmd{MISSING} is specified, then the pie chart includes
267 a single slice representing all system missing and user-missing cases.
268
269 @cindex bar chart
270 The @subcmd{BARCHART} subcommand produces a bar chart for each variable.
271 The @subcmd{MINIMUM} and @subcmd{MAXIMUM} keywords can be used to omit
272 categories whose counts which lie outside the specified limits.
273 The @subcmd{FREQ} option (default) causes the ordinate to display the frequency
274 of each category, whereas the @subcmd{PERCENT} option displays relative
275 percentages.
276
277 The @subcmd{FREQ} and @subcmd{PERCENT} options on @subcmd{HISTOGRAM} and
278 @subcmd{PIECHART} are accepted but not currently honoured.
279
280 The @subcmd{ORDER} subcommand is accepted but ignored.
281
282 @subsection Frequencies Example
283
284 @ref{frequencies:ex} runs a frequency analysis on the @exvar{sex}
285 and @exvar{occupation} variables from the @file{personnel.sav} file.
286 This is useful to get an general idea of the way in which these nominal
287 variables are distributed.
288
289 @float Example, frequencies:ex
290 @psppsyntax {frequencies.sps}
291 @caption {Running frequencies on the @exvar{sex} and @exvar{occupation} variables}
292 @end float
293
294 If you are using the graphic user interface, the dialog box is set up such that
295 by default, several statistics are calculated.   Some are not particularly useful
296 for categorical variables, so you may want to disable those.
297
298 @float Screenshot, frequencies:scr
299 @psppimage {frequencies}
300 @caption {The frequencies dialog box with the @exvar{sex} and @exvar{occupation} variables selected}
301 @end float
302
303 From @ref{frequencies:res} it is evident that there are 33 males, 21 females and
304 2 persons for whom their sex has not been entered.
305
306 One can also see how many of each occupation there are in the data.
307 When dealing with string variables used as nominal values, running a frequency
308 analysis is useful to detect data input entries.  Notice that
309 one @exvar{occupation} value has been mistyped as ``Scrientist''.  This entry should
310 be corrected, or marked as missing before using the data.
311
312 @float Result, frequencies:res
313 @psppoutput {frequencies}
314 @caption {The relative frequencies of @exvar{sex} and @exvar{occupation}}
315 @end float
316
317 @node EXAMINE
318 @section EXAMINE
319
320 @vindex EXAMINE
321 @cindex Exploratory data analysis
322 @cindex normality, testing
323
324 @display
325 EXAMINE
326         VARIABLES= @var{var1} [@var{var2}] @dots{} [@var{varN}]
327            [BY @var{factor1} [BY @var{subfactor1}]
328              [ @var{factor2} [BY @var{subfactor2}]]
329              @dots{}
330              [ @var{factor3} [BY @var{subfactor3}]]
331             ]
332         /STATISTICS=@{DESCRIPTIVES, EXTREME[(@var{n})], ALL, NONE@}
333         /PLOT=@{BOXPLOT, NPPLOT, HISTOGRAM, SPREADLEVEL[(@var{t})], ALL, NONE@}
334         /CINTERVAL @var{p}
335         /COMPARE=@{GROUPS,VARIABLES@}
336         /ID=@var{identity_variable}
337         /@{TOTAL,NOTOTAL@}
338         /PERCENTILE=[@var{percentiles}]=@{HAVERAGE, WAVERAGE, ROUND, AEMPIRICAL, EMPIRICAL @}
339         /MISSING=@{LISTWISE, PAIRWISE@} [@{EXCLUDE, INCLUDE@}]
340                 [@{NOREPORT,REPORT@}]
341
342 @end display
343
344 The @cmd{EXAMINE} command is used to perform exploratory data analysis.
345 In particular, it is useful for testing how closely a distribution follows a
346 normal distribution, and for finding outliers and extreme values.
347
348 The @subcmd{VARIABLES} subcommand is mandatory.
349 It specifies the dependent variables and optionally variables to use as
350 factors for the analysis.
351 Variables listed before the first @subcmd{BY} keyword (if any) are the
352 dependent variables.
353 The dependent variables may optionally be followed by a list of
354 factors which tell @pspp{} how to break down the analysis for each
355 dependent variable.
356
357 Following the dependent variables, factors may be specified.
358 The factors (if desired) should be preceded by a single @subcmd{BY} keyword.
359 The format for each factor is
360 @display
361 @var{factorvar} [BY @var{subfactorvar}].
362 @end display
363 Each unique combination of the values of  @var{factorvar} and
364 @var{subfactorvar} divide the dataset into @dfn{cells}.
365 Statistics are calculated for each cell
366 and for the entire dataset (unless @subcmd{NOTOTAL} is given).
367
368 The @subcmd{STATISTICS} subcommand specifies which statistics to show.
369 @subcmd{DESCRIPTIVES} produces a table showing some parametric and
370 non-parametrics statistics.
371 @subcmd{EXTREME} produces a table showing the extremities of each cell.
372 A number in parentheses, @var{n} determines
373 how many upper and lower extremities to show.
374 The default number is 5.
375
376 The subcommands @subcmd{TOTAL} and @subcmd{NOTOTAL} are mutually exclusive.
377 If @subcmd{TOTAL} appears, then statistics for the entire dataset
378 as well as for each cell are produced.
379 If @subcmd{NOTOTAL} appears, then statistics are produced only for the cells
380 (unless no factor variables have been given).
381 These subcommands have no effect if there have  been no factor variables
382 specified.
383
384 @cindex boxplot
385 @cindex histogram
386 @cindex npplot
387 @cindex spreadlevel plot
388 The @subcmd{PLOT} subcommand specifies which plots are to be produced if any.
389 Available plots are @subcmd{HISTOGRAM}, @subcmd{NPPLOT},  @subcmd{BOXPLOT} and
390 @subcmd{SPREADLEVEL}.
391 The first three can be used to visualise how closely each cell conforms to a
392 normal distribution, whilst the spread vs.@: level plot can be useful to visualise
393 how the variance differs between factors.
394 Boxplots show you the outliers and extreme values.
395 @footnote{@subcmd{HISTOGRAM} uses Sturges' rule to determine the number of
396 bins, as approximately @math{1 + \log2(n)}, where @math{n} is the number of samples.
397 Note that @cmd{FREQUENCIES} uses a different algorithm to find the bin size.}
398
399 The @subcmd{SPREADLEVEL} plot displays the interquartile range versus the
400 median.  It takes an optional parameter @var{t}, which specifies how the data
401 should be transformed prior to plotting.
402 The given value @var{t} is a power to which the data are raised.  For example, if
403 @var{t} is given as 2, then the square of the data is used.
404 Zero, however is a special value.  If @var{t} is 0 or
405 is omitted, then data are transformed by taking its natural logarithm instead of
406 raising to the power of @var{t}.
407
408 @cindex Shapiro-Wilk
409 When one or more plots are requested, @subcmd{EXAMINE} also performs the
410 Shapiro-Wilk test for each category.
411 There are however a number of provisos:
412 @itemize
413 @item All weight values must be integer.
414 @item The cumulative weight value must be in the range [3, 5000]
415 @end itemize
416
417 The @subcmd{COMPARE} subcommand is only relevant if producing boxplots, and it is only
418 useful there is more than one dependent variable and at least one factor.
419 If
420 @subcmd{/COMPARE=GROUPS} is specified, then one plot per dependent variable is produced,
421 each of which contain boxplots for all the cells.
422 If @subcmd{/COMPARE=VARIABLES} is specified, then one plot per cell is produced,
423 each containing one boxplot per dependent variable.
424 If the @subcmd{/COMPARE} subcommand is omitted, then @pspp{} behaves as if
425 @subcmd{/COMPARE=GROUPS} were given.
426
427 The @subcmd{ID} subcommand is relevant only if @subcmd{/PLOT=BOXPLOT} or
428 @subcmd{/STATISTICS=EXTREME} has been given.
429 If given, it should provide the name of a variable which is to be used
430 to labels extreme values and outliers.
431 Numeric or string variables are permissible.
432 If the @subcmd{ID} subcommand is not given, then the case number is used for
433 labelling.
434
435 The @subcmd{CINTERVAL} subcommand specifies the confidence interval to use in
436 calculation of the descriptives command.  The default is 95%.
437
438 @cindex percentiles
439 The @subcmd{PERCENTILES} subcommand specifies which percentiles are to be calculated,
440 and which algorithm to use for calculating them.  The default is to
441 calculate the 5, 10, 25, 50, 75, 90, 95 percentiles using the
442 @subcmd{HAVERAGE} algorithm.
443
444 The @subcmd{TOTAL} and @subcmd{NOTOTAL} subcommands are mutually exclusive.  If @subcmd{NOTOTAL}
445 is given and factors have been specified in the @subcmd{VARIABLES} subcommand,
446 then statistics for the unfactored dependent variables are
447 produced in addition to the factored variables.  If there are no
448 factors specified then @subcmd{TOTAL} and @subcmd{NOTOTAL} have no effect.
449
450
451 The following example generates descriptive statistics and histograms for
452 two variables @var{score1} and @var{score2}.
453 Two factors are given, @i{viz}: @var{gender} and @var{gender} BY @var{culture}.
454 Therefore, the descriptives and histograms are generated for each
455 distinct  value
456 of @var{gender} @emph{and} for each distinct combination of the values
457 of @var{gender} and @var{race}.
458 Since the @subcmd{NOTOTAL} keyword is given, statistics and histograms for
459 @var{score1} and @var{score2} covering the  whole dataset are not produced.
460 @example
461 EXAMINE @var{score1} @var{score2} BY
462         @var{gender}
463         @var{gender} BY @var{culture}
464         /STATISTICS = DESCRIPTIVES
465         /PLOT = HISTOGRAM
466         /NOTOTAL.
467 @end example
468
469 Here is a second example showing how the @cmd{examine} command can be used to find extremities.
470 @example
471 EXAMINE @var{height} @var{weight} BY
472         @var{gender}
473         /STATISTICS = EXTREME (3)
474         /PLOT = BOXPLOT
475         /COMPARE = GROUPS
476         /ID = @var{name}.
477 @end example
478 In this example, we look at the height and weight of a sample of individuals and
479 how they differ between male and female.
480 A table showing the 3 largest and the 3 smallest values of @exvar{height} and
481 @exvar{weight} for each gender, and for the whole dataset as are shown.
482 In addition, the @subcmd{/PLOT} subcommand requests boxplots.
483 Because @subcmd{/COMPARE = GROUPS} was specified, boxplots for male and female are
484 shown in juxtaposed in the same graphic, allowing us to easily see the difference between
485 the genders.
486 Since the variable @var{name} was specified on the @subcmd{ID} subcommand,
487 values of the @var{name} variable are used to label the extreme values.
488
489 @strong{Warning!}
490 If you specify many dependent variables or factor variables
491 for which there are many distinct values, then @cmd{EXAMINE} will produce a very
492 large quantity of output.
493
494 @node GRAPH
495 @section GRAPH
496
497 @vindex GRAPH
498 @cindex Exploratory data analysis
499 @cindex normality, testing
500
501 @display
502 GRAPH
503         /HISTOGRAM [(NORMAL)]= @var{var}
504         /SCATTERPLOT [(BIVARIATE)] = @var{var1} WITH @var{var2} [BY @var{var3}]
505         /BAR = @{@var{summary-function}(@var{var1}) | @var{count-function}@} BY @var{var2} [BY @var{var3}]
506         [ /MISSING=@{LISTWISE, VARIABLE@} [@{EXCLUDE, INCLUDE@}] ]
507                 [@{NOREPORT,REPORT@}]
508
509 @end display
510
511 The @cmd{GRAPH} command produces graphical plots of data. Only one of the subcommands
512 @subcmd{HISTOGRAM}, @subcmd{BAR} or @subcmd{SCATTERPLOT} can be specified, @i{i.e.} only one plot
513 can be produced per call of @cmd{GRAPH}. The @subcmd{MISSING} is optional.
514
515 @menu
516 * SCATTERPLOT::             Cartesian Plots
517 * HISTOGRAM::               Histograms
518 * BAR CHART::               Bar Charts
519 @end menu
520
521 @node SCATTERPLOT
522 @subsection Scatterplot
523 @cindex scatterplot
524
525 The subcommand @subcmd{SCATTERPLOT} produces an xy plot of the
526 data.
527 @cmd{GRAPH} uses the third variable @var{var3}, if specified, to determine
528 the colours and/or markers for the plot.
529 The following is an example for producing a scatterplot.
530
531 @example
532 GRAPH
533         /SCATTERPLOT = @var{height} WITH @var{weight} BY @var{gender}.
534 @end example
535
536 This example produces a scatterplot where @var{height} is plotted versus @var{weight}. Depending
537 on the value of the @var{gender} variable, the colour of the datapoint is different. With
538 this plot it is possible to analyze gender differences for @var{height} versus @var{weight} relation.
539
540 @node HISTOGRAM
541 @subsection Histogram
542 @cindex histogram
543
544 The subcommand @subcmd{HISTOGRAM} produces a histogram. Only one variable is allowed for
545 the histogram plot.
546 The keyword @subcmd{NORMAL} may be specified in parentheses, to indicate that the ideal normal curve
547 should be superimposed over the histogram.
548 For an alternative method to produce histograms @pxref{EXAMINE}. The
549 following example produces a histogram plot for the variable @var{weight}.
550
551 @example
552 GRAPH
553         /HISTOGRAM = @var{weight}.
554 @end example
555
556 @node BAR CHART
557 @subsection Bar Chart
558 @cindex bar chart
559
560 The subcommand @subcmd{BAR} produces a bar chart.
561 This subcommand requires that a @var{count-function} be specified (with no arguments) or a @var{summary-function} with a variable @var{var1} in parentheses.
562 Following the summary or count function, the keyword @subcmd{BY} should be specified and then a catagorical variable, @var{var2}.
563 The values of the variable @var{var2} determine the labels of the bars to be plotted.
564 Optionally a second categorical variable @var{var3} may be specified in which case a clustered (grouped) bar chart is produced.
565
566 Valid count functions are
567 @table @subcmd
568 @item COUNT
569 The weighted counts of the cases in each category.
570 @item PCT
571 The weighted counts of the cases in each category expressed as a percentage of the total weights of the cases.
572 @item CUFREQ
573 The cumulative weighted counts of the cases in each category.
574 @item CUPCT
575 The cumulative weighted counts of the cases in each category expressed as a percentage of the total weights of the cases.
576 @end table
577
578 The summary function is applied to @var{var1} across all cases in each category.
579 The recognised summary functions are:
580 @table @subcmd
581 @item SUM
582 The sum.
583 @item MEAN
584 The arithmetic mean.
585 @item MAXIMUM
586 The maximum value.
587 @item MINIMUM
588 The minimum value.
589 @end table
590
591 The following examples assume a dataset which is the results of a survey.
592 Each respondent has indicated annual income, their sex and city of residence.
593 One could create a bar chart showing how the mean income varies between of residents of different cities, thus:
594 @example
595 GRAPH  /BAR  = MEAN(@var{income}) BY @var{city}.
596 @end example
597
598 This can be extended to also indicate how income in each city differs between the sexes.
599 @example
600 GRAPH  /BAR  = MEAN(@var{income}) BY @var{city} BY @var{sex}.
601 @end example
602
603 One might also want to see how many respondents there are from each city.  This can be achieved as follows:
604 @example
605 GRAPH  /BAR  = COUNT BY @var{city}.
606 @end example
607
608 Bar charts can also be produced using the @ref{FREQUENCIES} and @ref{CROSSTABS} commands.
609
610 @node CORRELATIONS
611 @section CORRELATIONS
612
613 @vindex CORRELATIONS
614 @display
615 CORRELATIONS
616      /VARIABLES = @var{var_list} [ WITH @var{var_list} ]
617      [
618       .
619       .
620       .
621       /VARIABLES = @var{var_list} [ WITH @var{var_list} ]
622       /VARIABLES = @var{var_list} [ WITH @var{var_list} ]
623      ]
624
625      [ /PRINT=@{TWOTAIL, ONETAIL@} @{SIG, NOSIG@} ]
626      [ /STATISTICS=DESCRIPTIVES XPROD ALL]
627      [ /MISSING=@{PAIRWISE, LISTWISE@} @{INCLUDE, EXCLUDE@} ]
628 @end display
629
630 @cindex correlation
631 The @cmd{CORRELATIONS} procedure produces tables of the Pearson correlation coefficient
632 for a set of variables.  The significance of the coefficients are also given.
633
634 At least one @subcmd{VARIABLES} subcommand is required. If you specify the @subcmd{WITH}
635 keyword, then a non-square correlation table is produced.
636 The variables preceding @subcmd{WITH}, are used as the rows of the table,
637 and the variables following @subcmd{WITH} are used as the columns of the table.
638 If no @subcmd{WITH} subcommand is specified, then @cmd{CORRELATIONS} produces a
639 square, symmetrical table using all variables.
640
641 The @cmd{MISSING} subcommand determines the handling of missing variables.
642 If @subcmd{INCLUDE} is set, then user-missing values are included in the
643 calculations, but system-missing values are not.
644 If @subcmd{EXCLUDE} is set, which is the default, user-missing
645 values are excluded as well as system-missing values.
646
647 If @subcmd{LISTWISE} is set, then the entire case is excluded from analysis
648 whenever any variable  specified in any @cmd{/VARIABLES} subcommand
649 contains a missing value.
650 If @subcmd{PAIRWISE} is set, then a case is considered missing only if either of the
651 values  for the particular coefficient are missing.
652 The default is @subcmd{PAIRWISE}.
653
654 The @subcmd{PRINT} subcommand is used to control how the reported significance values are printed.
655 If the @subcmd{TWOTAIL} option is used, then a two-tailed test of significance is
656 printed.  If the @subcmd{ONETAIL} option is given, then a one-tailed test is used.
657 The default is @subcmd{TWOTAIL}.
658
659 If the @subcmd{NOSIG} option is specified, then correlation coefficients with significance less than
660 0.05 are highlighted.
661 If @subcmd{SIG} is specified, then no highlighting is performed.  This is the default.
662
663 @cindex covariance
664 The @subcmd{STATISTICS} subcommand requests additional statistics to be displayed.  The keyword
665 @subcmd{DESCRIPTIVES} requests that the mean, number of non-missing cases, and the non-biased
666 estimator of the standard deviation are displayed.
667 These statistics are displayed in a separated table, for all the variables listed
668 in any @subcmd{/VARIABLES} subcommand.
669 The @subcmd{XPROD} keyword requests cross-product deviations and covariance estimators to
670 be displayed for each pair of variables.
671 The keyword @subcmd{ALL} is the union of @subcmd{DESCRIPTIVES} and @subcmd{XPROD}.
672
673 @node CROSSTABS
674 @section CROSSTABS
675
676 @vindex CROSSTABS
677 @display
678 CROSSTABS
679         /TABLES=@var{var_list} BY @var{var_list} [BY @var{var_list}]@dots{}
680         /MISSING=@{TABLE,INCLUDE,REPORT@}
681         /FORMAT=@{TABLES,NOTABLES@}
682                 @{AVALUE,DVALUE@}
683         /CELLS=@{COUNT,ROW,COLUMN,TOTAL,EXPECTED,RESIDUAL,SRESIDUAL,
684                 ASRESIDUAL,ALL,NONE@}
685         /COUNT=@{ASIS,CASE,CELL@}
686                @{ROUND,TRUNCATE@}
687         /STATISTICS=@{CHISQ,PHI,CC,LAMBDA,UC,BTAU,CTAU,RISK,GAMMA,D,
688                      KAPPA,ETA,CORR,ALL,NONE@}
689         /BARCHART
690
691 (Integer mode.)
692         /VARIABLES=@var{var_list} (@var{low},@var{high})@dots{}
693 @end display
694
695 The @cmd{CROSSTABS} procedure displays crosstabulation
696 tables requested by the user.  It can calculate several statistics for
697 each cell in the crosstabulation tables.  In addition, a number of
698 statistics can be calculated for each table itself.
699
700 The @subcmd{TABLES} subcommand is used to specify the tables to be reported.  Any
701 number of dimensions is permitted, and any number of variables per
702 dimension is allowed.  The @subcmd{TABLES} subcommand may be repeated as many
703 times as needed.  This is the only required subcommand in @dfn{general
704 mode}.
705
706 Occasionally, one may want to invoke a special mode called @dfn{integer
707 mode}.  Normally, in general mode, @pspp{} automatically determines
708 what values occur in the data.  In integer mode, the user specifies the
709 range of values that the data assumes.  To invoke this mode, specify the
710 @subcmd{VARIABLES} subcommand, giving a range of data values in parentheses for
711 each variable to be used on the @subcmd{TABLES} subcommand.  Data values inside
712 the range are truncated to the nearest integer, then assigned to that
713 value.  If values occur outside this range, they are discarded.  When it
714 is present, the @subcmd{VARIABLES} subcommand must precede the @subcmd{TABLES}
715 subcommand.
716
717 In general mode, numeric and string variables may be specified on
718 TABLES.  In integer mode, only numeric variables are allowed.
719
720 The @subcmd{MISSING} subcommand determines the handling of user-missing values.
721 When set to @subcmd{TABLE}, the default, missing values are dropped on a table by
722 table basis.  When set to @subcmd{INCLUDE}, user-missing values are included in
723 tables and statistics.  When set to @subcmd{REPORT}, which is allowed only in
724 integer mode, user-missing values are included in tables but marked with
725 a footnote and excluded from statistical calculations.
726
727 The @subcmd{FORMAT} subcommand controls the characteristics of the
728 crosstabulation tables to be displayed.  It has a number of possible
729 settings:
730
731 @itemize @w{}
732 @item
733 @subcmd{TABLES}, the default, causes crosstabulation tables to be output.
734 @subcmd{NOTABLES}, which is equivalent to @code{CELLS=NONE}, suppresses them.
735
736 @item
737 @subcmd{AVALUE}, the default, causes values to be sorted in ascending order.
738 @subcmd{DVALUE} asserts a descending sort order.
739 @end itemize
740
741 The @subcmd{CELLS} subcommand controls the contents of each cell in the displayed
742 crosstabulation table.  The possible settings are:
743
744 @table @asis
745 @item COUNT
746 Frequency count.
747 @item ROW
748 Row percent.
749 @item COLUMN
750 Column percent.
751 @item TOTAL
752 Table percent.
753 @item EXPECTED
754 Expected value.
755 @item RESIDUAL
756 Residual.
757 @item SRESIDUAL
758 Standardized residual.
759 @item ASRESIDUAL
760 Adjusted standardized residual.
761 @item ALL
762 All of the above.
763 @item NONE
764 Suppress cells entirely.
765 @end table
766
767 @samp{/CELLS} without any settings specified requests @subcmd{COUNT}, @subcmd{ROW},
768 @subcmd{COLUMN}, and @subcmd{TOTAL}.
769 If @subcmd{CELLS} is not specified at all then only @subcmd{COUNT}
770 is selected.
771
772 By default, crosstabulation and statistics use raw case weights,
773 without rounding.  Use the @subcmd{/COUNT} subcommand to perform
774 rounding: CASE rounds the weights of individual weights as cases are
775 read, CELL rounds the weights of cells within each crosstabulation
776 table after it has been constructed, and ASIS explicitly specifies the
777 default non-rounding behavior.  When rounding is requested, ROUND, the
778 default, rounds to the nearest integer and TRUNCATE rounds toward
779 zero.
780
781 The @subcmd{STATISTICS} subcommand selects statistics for computation:
782
783 @table @asis
784 @item CHISQ
785 @cindex chi-square
786
787 Pearson chi-square, likelihood ratio, Fisher's exact test, continuity
788 correction, linear-by-linear association.
789 @item PHI
790 Phi.
791 @item CC
792 Contingency coefficient.
793 @item LAMBDA
794 Lambda.
795 @item UC
796 Uncertainty coefficient.
797 @item BTAU
798 Tau-b.
799 @item CTAU
800 Tau-c.
801 @item RISK
802 Risk estimate.
803 @item GAMMA
804 Gamma.
805 @item D
806 Somers' D.
807 @item KAPPA
808 Cohen's Kappa.
809 @item ETA
810 Eta.
811 @item CORR
812 Spearman correlation, Pearson's r.
813 @item ALL
814 All of the above.
815 @item NONE
816 No statistics.
817 @end table
818
819 Selected statistics are only calculated when appropriate for the
820 statistic.  Certain statistics require tables of a particular size, and
821 some statistics are calculated only in integer mode.
822
823 @samp{/STATISTICS} without any settings selects CHISQ.  If the
824 @subcmd{STATISTICS} subcommand is not given, no statistics are calculated.
825
826 @cindex bar chart
827 The @samp{/BARCHART} subcommand produces a clustered bar chart for the first two
828 variables on each table.
829 If a table has more than two variables, the counts for the third and subsequent levels
830 are aggregated and the chart is produced as if there were only two variables.
831
832
833 @strong{Please note:} Currently the implementation of @cmd{CROSSTABS} has the
834 following limitations:
835
836 @itemize @bullet
837 @item
838 Significance of some symmetric and directional measures is not calculated.
839 @item
840 Asymptotic standard error is not calculated for
841 Goodman and Kruskal's tau or symmetric Somers' d.
842 @item
843 Approximate T is not calculated for symmetric uncertainty coefficient.
844 @end itemize
845
846 Fixes for any of these deficiencies would be welcomed.
847
848 @subsection Crosstabs Example
849
850 @cindex chi-square test of independence
851
852 A researcher wishes to know if, in an industry, a person's sex is related to
853 the person's occupation.  To investigate this, she has determined that the
854 @file{personnel.sav} is a representative, randomly selected sample of persons.
855 The researcher's null hypothesis is that a person's sex has no relation to a
856 person's occupation. She uses a chi-squared test of independence to investigate
857 the hypothesis.
858
859 @float Example, crosstabs:ex
860 @psppsyntax {crosstabs.sps}
861 @caption {Running crosstabs on the @exvar{sex} and @exvar{occupation} variables}
862 @end float
863
864 The syntax in @ref{crosstabs:ex} conducts a chi-squared test of independence.
865 The line @code{/tables = occupation by sex} indicates that @exvar{occupation}
866 and @exvar{sex} are the variables to be tabulated.  To do this using the @gui{}
867 you must place these variable names respectively in the @samp{Row} and
868 @samp{Column} fields as shown in @ref{crosstabs:scr}.
869
870 @float Screenshot, crosstabs:scr
871 @psppimage {crosstabs}
872 @caption {The Crosstabs dialog box with the @exvar{sex} and @exvar{occupation} variables selected}
873 @end float
874
875 Similarly, the @samp{Cells} button shows a dialog box to select the @code{count}
876 and @code{expected} options.  All other cell options can be deselected for this
877 test.
878
879 You would use the @samp{Format} and @samp{Statistics}  buttons to select options
880 for the @subcmd{FORMAT} and @subcmd{STATISTICS} subcommands.  In this example,
881 the @samp{Statistics} requires only the @samp{Chisq} option to be checked.  All
882 other options should be unchecked.  No special settings are required from the
883 @samp{Format} dialog.
884
885 As shown in @ref{crosstabs:res} @cmd{CROSSTABS} generates a contingency table
886 containing the observed count and the expected count of each sex and each
887 occupation.  The expected count is the count which would be observed if the
888 null hypothesis were true.
889
890 The significance of the Pearson Chi-Square value is very much larger than the
891 normally accepted value of 0.05 and so one cannot reject the null hypothesis.
892 Thus the researcher must conclude that a person's sex has no relation to the
893 person's occupation.
894
895 @float Results, crosstabs:res
896 @psppoutput {crosstabs}
897 @caption {The results of a test of independence between @exvar{sex} and @exvar{occupation}}
898 @end float
899
900 @node CTABLES
901 @section CTABLES
902
903 @vindex CTABLES
904 @cindex custom tables
905 @cindex tables, custom
906
907 @code{CTABLES} has the following overall syntax.  At least one
908 @code{TABLE} subcommand is required:
909
910 @display
911 @t{CTABLES}
912   @dots{}@i{global subcommands}@dots{}
913   [@t{/TABLE} @i{axis} [@t{BY} @i{axis} [@t{BY} @i{axis}]]
914    @dots{}@i{per-table subcommands}@dots{}]@dots{}
915 @end display
916
917 @noindent
918 where each @i{axis} may be empty or take one of the following forms:
919
920 @display
921 @i{variable}
922 @i{variable} @t{[}@{@t{C} @math{|} @t{S}@}@t{]}
923 @i{axis} + @i{axis}
924 @i{axis} > @i{axis}
925 (@i{axis})
926 @i{axis} @t{[}@i{summary} [@i{string}] [@i{format}]@t{]}
927 @end display
928
929 The following subcommands precede the first @code{TABLE} subcommand
930 and apply to all of the output tables.  All of these subcommands are
931 optional:
932
933 @display
934 @t{/FORMAT}
935     [@t{MINCOLWIDTH=}@{@t{DEFAULT} @math{|} @i{width}@}]
936     [@t{MAXCOLWIDTH=}@{@t{DEFAULT} @math{|} @i{width}@}]
937     [@t{UNITS=}@{@t{POINTS} @math{|} @t{INCHES} @math{|} @t{CM}@}]
938     [@t{EMPTY=}@{@t{ZERO} @math{|} @t{BLANK} @math{|} @i{string}@}]
939     [@t{MISSING=}@i{string}]
940 @t{/VLABELS}
941     @t{VARIABLES=}@i{variables}
942     @t{DISPLAY}=@{@t{DEFAULT} @math{|} @t{NAME} @math{|} @t{LABEL} @math{|} @t{BOTH} @math{|} @t{NONE}@}
943 @ignore @c not yet implemented
944 @t{/MRSETS COUNTDUPLICATES=}@{@t{YES} @math{|} @t{NO}@}
945 @end ignore
946 @t{/SMISSING} @{@t{VARIABLE} @math{|} @t{LISTWISE}@}
947 @t{/PCOMPUTE} @t{&}@i{postcompute}@t{=EXPR(}@i{expression}@t{)}
948 @t{/PPROPERTIES} @t{&}@i{postcompute}@dots{}
949     [@t{LABEL=}@i{string}]
950     [@t{FORMAT=}[@i{summary} @i{format}]@dots{}]
951     [@t{HIDESOURCECATS=}@{@t{NO} @math{|} @t{YES}@}
952 @t{/WEIGHT VARIABLE=}@i{variable}
953 @t{/HIDESMALLCOUNTS COUNT=@i{count}}
954 @end display
955
956 The following subcommands follow @code{TABLE} and apply only to the
957 previous @code{TABLE}.  All of these subcommands are optional:
958
959 @display
960 @t{/SLABELS}
961     [@t{POSITION=}@{@t{COLUMN} @math{|} @t{ROW} @math{|} @t{LAYER}@}]
962     [@t{VISIBLE=}@{@t{YES} @math{|} @t{NO}@}]
963 @t{/CLABELS} @{@t{AUTO} @math{|} @{@t{ROWLABELS}@math{|}@t{COLLABELS}@}@t{=}@{@t{OPPOSITE}@math{|}@t{LAYER}@}@}
964 @t{/CATEGORIES} @t{VARIABLES=}@i{variables}
965     @{@t{[}@i{value}@t{,} @i{value}@dots{}@t{]}
966    @math{|} [@t{ORDER=}@{@t{A} @math{|} @t{D}@}]
967      [@t{KEY=}@{@t{VALUE} @math{|} @t{LABEL} @math{|} @i{summary}@t{(}@i{variable}@t{)}@}]
968      [@t{MISSING=}@{@t{EXCLUDE} @math{|} @t{INCLUDE}@}]@}
969     [@t{TOTAL=}@{@t{NO} @math{|} @t{YES}@} [@t{LABEL=}@i{string}] [@t{POSITION=}@{@t{AFTER} @math{|} @t{BEFORE}@}]]
970     [@t{EMPTY=}@{@t{INCLUDE} @math{|} @t{EXCLUDE}@}]
971 @t{/TITLES}
972     [@t{TITLE=}@i{string}@dots{}]
973     [@t{CAPTION=}@i{string}@dots{}]
974     [@t{CORNER=}@i{string}@dots{}]
975 @ignore  @c not yet implemented
976 @t{/CRITERIA CILEVEL=}@i{percentage}
977 @t{/SIGTEST TYPE=CHISQUARE}
978     [@t{ALPHA=}@i{siglevel}]
979     [@t{INCLUDEMRSETS=}@{@t{YES} @math{|} @t{NO}@}]
980     [@t{CATEGORIES=}@{@t{ALLVISIBLE} @math{|} @t{SUBTOTALS}@}]
981 @t{/COMPARETEST TYPE=}@{@t{PROP} @math{|} @t{MEAN}@}
982     [@t{ALPHA=}@i{value}[@t{,} @i{value}]]
983     [@t{ADJUST=}@{@t{BONFERRONI} @math{|} @t{BH} @math{|} @t{NONE}@}]
984     [@t{INCLUDEMRSETS=}@{@t{YES} @math{|} @t{NO}@}]
985     [@t{MEANSVARIANCE=}@{@t{ALLCATS} @math{|} @t{TESTEDCATS}@}]
986     [@t{CATEGORIES=}@{@t{ALLVISIBLE} @math{|} @t{SUBTOTALS}@}]
987     [@t{MERGE=}@{@t{NO} @math{|} @t{YES}@}]
988     [@t{STYLE=}@{@t{APA} @math{|} @t{SIMPLE}@}]
989     [@t{SHOWSIG=}@{@t{NO} @math{|} @t{YES}@}]
990 @end ignore
991 @end display
992
993 The @code{CTABLES} (aka ``custom tables'') command produces
994 multi-dimensional tables from categorical and scale data.  It offers
995 many options for data summarization and formatting.
996
997 This section's examples use data from the 2008 (USA) National Survey
998 of Drinking and Driving Attitudes and Behaviors, a public domain data
999 set from the (USA) National Highway Traffic Administration and
1000 available at @url{https://data.transportation.gov}.  @pspp{} includes
1001 this data set, with a slightly modified dictionary, as
1002 @file{examples/nhtsa.sav}.
1003
1004 @node CTABLES Basics
1005 @subsection Basics
1006
1007 The only required subcommand is @code{TABLE}, which specifies the
1008 variables to include along each axis:
1009 @display
1010 @t{/TABLE} @i{rows} [@t{BY} @i{columns} [@t{BY} @i{layers}]]
1011 @end display
1012 @noindent
1013 In @code{TABLE}, each of @var{rows}, @var{columns}, and @var{layers}
1014 is either empty or an axis expression that specifies one or more
1015 variables.  At least one must specify an axis expression.
1016
1017 @node CTABLES Categorical Variable Basics
1018 @subsubsection Categorical Variables
1019
1020 An axis expression that names a categorical variable divides the data
1021 into cells according to the values of that variable.  When all the
1022 variables named on @code{TABLE} are categorical, by default each cell
1023 displays the number of cases that it contains, so specifying a single
1024 variable yields a frequency table, much like the output of the
1025 @code{FREQUENCIES} command (@pxref{FREQUENCIES}):
1026
1027 @example
1028 CTABLES /TABLE=AgeGroup.
1029 @end example
1030 @psppoutput {ctables1}
1031
1032 @noindent
1033 Specifying a row and a column categorical variable yields a
1034 crosstabulation, much like the output of the @code{CROSSTABS} command
1035 (@pxref{CROSSTABS}):
1036
1037 @example
1038 CTABLES /TABLE=AgeGroup BY qns3a.
1039 @end example
1040 @psppoutput {ctables2}
1041
1042 @noindent
1043 The @samp{>} ``nesting'' operator nests multiple variables on a single
1044 axis, e.g.:
1045
1046 @example
1047 CTABLES /TABLE qn105ba BY AgeGroup > qns3a.
1048 @end example
1049 @psppoutput {ctables3}
1050
1051 @noindent
1052 The @samp{+} ``stacking'' operator allows a single output table to
1053 include multiple data analyses.  With @samp{+}, @code{CTABLES} divides
1054 the output table into multiple @dfn{sections}, each of which includes
1055 an analysis of the full data set.  For example, the following command
1056 separately tabulates age group and driving frequency by gender:
1057
1058 @example
1059 CTABLES /TABLE AgeGroup + qn1 BY qns3a.
1060 @end example
1061 @psppoutput {ctables4}
1062
1063 @noindent
1064 When @samp{+} and @samp{>} are used together, @samp{>} binds more
1065 tightly.  Use parentheses to override operator precedence.  Thus:
1066
1067 @example
1068 CTABLES /TABLE qn26 + qn27 > qns3a.
1069 CTABLES /TABLE (qn26 + qn27) > qns3a.
1070 @end example
1071 @psppoutput {ctables5}
1072
1073 @node CTABLES Scalar Variable Basics
1074 @subsubsection Scalar Variables
1075
1076 For a categorical variable, @code{CTABLES} divides the table into a
1077 cell per category.  For a scalar variable, @code{CTABLES} instead
1078 calculates a summary measure, by default the mean, of the values that
1079 fall into a cell.  For example, if the only variable specified is a
1080 scalar variable, then the output is a single cell that holds the mean
1081 of all of the data:
1082
1083 @example
1084 CTABLES /TABLE qnd1.
1085 @end example
1086 @psppoutput {ctables6}
1087
1088 A scalar variable may nest with categorical variables.  The following
1089 example shows the mean age of survey respondents across gender and
1090 language groups:
1091
1092 @example
1093 CTABLES /TABLE qns3a > qnd1 BY region.
1094 @end example
1095 @psppoutput {ctables7}
1096
1097 The order of nesting of scalar and categorical variables affects table
1098 labeling, but it does not affect the data displayed in the table.  The
1099 following example shows how the output changes when the nesting order
1100 of the scalar and categorical variable are interchanged:
1101
1102 @example
1103 CTABLES /TABLE qnd1 > qns3a BY region.
1104 @end example
1105 @psppoutput {ctables8}
1106
1107 Only a single scalar variable may appear in each section; that is, a
1108 scalar variable may not nest inside a scalar variable directly or
1109 indirectly.  Scalar variables may only appear on one axis within
1110 @code{TABLE}.
1111
1112 @node CTABLES Overriding Measurement Level
1113 @subsubsection Overriding Measurement Level
1114
1115 By default, @code{CTABLES} uses a variable's measurement level to
1116 decide whether to treat it as categorical or scalar.  Variables
1117 assigned the nominal or ordinal measurement level are treated as
1118 categorical, and scalar variables are treated as scalar.
1119
1120 When @pspp{} reads data from a file in an external format, such as a
1121 text file, variables' measurement levels are often unknown.  If
1122 @code{CTABLES} runs when a variable has an unknown measurement level,
1123 it makes an initial pass through the data to guess measurement levels
1124 using the rules described in an earlier section (@pxref{Measurement
1125 Level}).  Use the @code{VARIABLE LEVEL} command to set or change a
1126 variable's measurement level (@pxref{VARIABLE LEVEL}).
1127
1128 To treat a variable as categorical or scalar only for one use on
1129 @code{CTABLES}, add @samp{[C]} or @samp{[S]}, respectively, after the
1130 variable name.  The following example shows the output when variable
1131 @code{qn20} is analyzed as scalar (the default for its measurement
1132 level) and as categorical:
1133
1134 @example
1135 CTABLES
1136     /TABLE qn20 BY qns3a
1137     /TABLE qn20 [C] BY qns3a.
1138 @end example
1139 @psppoutput {ctables9}
1140
1141 @ignore
1142 @node CTABLES Multiple Response Sets
1143 @subsubheading Multiple Response Sets
1144
1145 The @code{CTABLES} command does not yet support multiple response
1146 sets.
1147 @end ignore
1148
1149 @node CTABLES Data Summarization
1150 @subsection Data Summarization
1151
1152 The @code{CTABLES} command allows the user to control how the data are
1153 summarized with @dfn{summary specifications}, syntax that lists one or
1154 more summary function names, optionally separated by commas, and which
1155 are enclosed in square brackets following a variable name on the
1156 @code{TABLE} subcommand.  When all the variables are categorical,
1157 summary specifications can be given for the innermost nested variables
1158 on any one axis.  When a scalar variable is present, only the scalar
1159 variable may have summary specifications.
1160
1161 The following example includes a summary specification for column and
1162 row percentages for categorical variables, and mean and median for a
1163 scalar variable:
1164
1165 @example
1166 CTABLES
1167     /TABLE=qnd1 [MEAN, MEDIAN] BY qns3a
1168     /TABLE=AgeGroup [COLPCT, ROWPCT] BY qns3a.
1169 @end example
1170 @psppoutput {ctables10}
1171
1172 A summary specification may override the default label and format by
1173 appending a string or format specification or both (in that order) to
1174 the summary function name.  For example:
1175
1176 @example
1177 CTABLES /TABLE=AgeGroup [COLPCT 'Gender %' PCT5.0,
1178                          ROWPCT 'Age Group %' PCT5.0]
1179                BY qns3a.
1180 @end example
1181 @psppoutput {ctables11}
1182
1183 In addition to the standard formats, @code{CTABLES} allows the user to
1184 specify the following special formats:
1185
1186 @multitable {@code{NEGPAREN@i{w}.@i{d}}} {Encloses all numbers in parentheses.} {@t{(42.96%)}} {@t{(-42.96%)}}
1187 @item @code{NEGPAREN@i{w}.@i{d}}
1188 @tab Encloses negative numbers in parentheses.
1189 @tab @t{@w{    }42.96}
1190 @tab @t{@w{  }(42.96)}
1191
1192 @item @code{NEQUAL@i{w}.@i{d}}
1193 @tab Adds a @code{N=} prefix.
1194 @tab @t{@w{  }N=42.96}
1195 @tab @t{@w{ }N=-42.96}
1196
1197 @item @code{@code{PAREN@i{w}.@i{d}}}
1198 @tab Encloses all numbers in parentheses.
1199 @tab @t{@w{  }(42.96)}
1200 @tab @t{@w{ }(-42.96)}
1201
1202 @item @code{PCTPAREN@i{w}.@i{d}}
1203 @tab Encloses all numbers in parentheses with a @samp{%} suffix.
1204 @tab @t{@w{ }(42.96%)}
1205 @tab @t{(-42.96%)}
1206 @end multitable
1207
1208 Parentheses provide a shorthand to apply summary specifications to
1209 multiple variables.  For example, both of these commands:
1210
1211 @example
1212 CTABLES /TABLE=AgeGroup[COLPCT] + qns1[COLPCT] BY qns3a.
1213 CTABLES /TABLE=(AgeGroup + qns1)[COLPCT] BY qns3a.
1214 @end example
1215
1216 @noindent
1217 produce the same output shown below:
1218
1219 @psppoutput {ctables12}
1220
1221 The following sections list the available summary functions.  After
1222 each function's name is given its default label and format.  If no
1223 format is listed, then the default format is the print format for the
1224 variable being summarized.
1225
1226 @node CTABLES Summary Functions for Individual Cells
1227 @subsubsection Summary Functions for Individual Cells
1228
1229 This section lists the summary functions that consider only an
1230 individual cell in @code{CTABLES}.  Only one such summary function,
1231 @code{COUNT}, may be applied to both categorical and scale variables:
1232
1233 @table @asis
1234 @item @code{COUNT} (``Count'', F40.0)
1235 The sum of weights in a cell.
1236
1237 If @code{CATEGORIES} for one or more of the variables in a table
1238 include missing values (@pxref{CTABLES Per-Variable Category
1239 Options}), then some or all of the categories for a cell might be
1240 missing values.  @code{COUNT} counts data included in a cell
1241 regardless of whether its categories are missing.
1242 @end table
1243
1244 The following summary functions apply only to scale variables or
1245 totals and subtotals for categorical variables.  Be cautious about
1246 interpreting the summary value in the latter case, because it is not
1247 necessarily meaningful; however, the mean of a Likert scale, etc.@:
1248 may have a straightforward interpreation.
1249
1250 @table @asis
1251 @item @code{MAXIMUM} (``Maximum'')
1252 The largest value.
1253
1254 @item @code{MEAN} (``Mean'')
1255 The mean.
1256
1257 @item @code{MEDIAN} (``Median'')
1258 The median value.
1259
1260 @item @code{MINIMUM} (``Minimum'')
1261 The smallest value.
1262
1263 @item @code{MISSING} (``Missing'')
1264 Sum of weights of user- and system-missing values.
1265
1266 @item @code{MODE} (``Mode'')
1267 The highest-frequency value.  Ties are broken by taking the smallest mode.
1268
1269 @item @code{PTILE} @i{n} (``Percentile @i{n}'')
1270 The @var{n}th percentile, where @math{0 @leq{} @var{n} @leq{} 100}.
1271
1272 @item @code{RANGE} (``Range'')
1273 The maximum minus the minimum.
1274
1275 @item @code{SEMEAN} (``Std Error of Mean'')
1276 The standard error of the mean.
1277
1278 @item @code{STDDEV} (``Std Deviation'')
1279 The standard deviation.
1280
1281 @item @code{SUM} (``Sum'')
1282 The sum.
1283
1284 @item @code{TOTALN} (``Total N'', F40.0)
1285 The sum of weights in a cell.
1286
1287 For scale data, @code{COUNT} and @code{TOTALN} are the same.
1288
1289 For categorical data, @code{TOTALN} counts missing values in excluded
1290 categories, that is, user-missing values not in an explicit category
1291 list on @code{CATEGORIES} (@pxref{CTABLES Per-Variable Category
1292 Options}), or user-missing values excluded because
1293 @code{MISSING=EXCLUDE} is in effect on @code{CATEGORIES}, or
1294 system-missing values.  @code{COUNT} does not count these.
1295
1296 @xref{CTABLES Missing Values for Summary Variables}, for details of
1297 how @code{CTABLES} summarizes missing values.
1298
1299 @item @code{VALIDN} (``Valid N'', F40.0)
1300 The sum of valid count weights in included categories.
1301
1302 For categorical variables, @code{VALIDN} does not count missing values
1303 regardless of whether they are in included categories via
1304 @code{CATEGORIES}.  @code{VALIDN} does not count valid values that are
1305 in excluded categories.  @xref{CTABLES Missing Values for Summary
1306 Variables}, for details.
1307
1308 @item @code{VARIANCE} (``Variance'')
1309 The variance.
1310 @end table
1311
1312 @node CTABLES Summary Functions for Groups of Cells
1313 @subsubsection Summary Functions for Groups of Cells
1314
1315 These summary functions summarize over multiple cells within an area
1316 of the output chosen by the user and specified as part of the function
1317 name.  The following basic @var{area}s are supported, in decreasing
1318 order of size:
1319
1320 @table @code
1321 @item TABLE
1322 A @dfn{section}.  Stacked variables divide sections of the output from
1323 each other.  sections may span multiple layers.
1324
1325 @item LAYER
1326 A section within a single layer.
1327
1328 @item SUBTABLE
1329 A @dfn{subtable}, whose contents are the cells that pair an innermost
1330 row variable and an innermost column variable within a single layer.
1331 @end table
1332
1333 The following shows how the output for the table expression @code{qn61
1334 > qn57 BY qnd7a > qn86 + qn64b BY qns3a}@footnote{This is not
1335 necessarily a meaningful table, so for clarity variable labels are
1336 omitted.} is divided up into @code{TABLE}, @code{LAYER}, and
1337 @code{SUBTABLE} areas.  Each unique value for Table ID is one section,
1338 and similarly for Layer ID and Subtable ID.  Thus, this output has two
1339 @code{TABLE} areas (one for @code{qnd7a} and one for @code{qn64b}),
1340 four @code{LAYER} areas (for those two variables, per layer), and 12
1341 @code{SUBTABLE} areas.
1342 @psppoutput {ctables22}
1343
1344 @code{CTABLES} also supports the following @var{area}s that further
1345 divide a subtable or a layer within a section:
1346
1347 @table @code
1348 @item LAYERROW
1349 @itemx LAYERCOL
1350 A row or column, respectively, in one layer of a section.
1351
1352 @item ROW
1353 @itemx COL
1354 A row or column, respectively, in a subtable.
1355 @end table
1356
1357 The following summary functions for groups of cells are available for
1358 each @var{area} described above, for both categorical and scale
1359 variables:
1360
1361 @table @asis
1362 @item @code{@i{area}PCT} or @code{@i{area}PCT.COUNT} (``@i{Area} %'', PCT40.1)
1363 A percentage of total counts within @var{area}.
1364
1365 @item @code{@i{area}PCT.VALIDN} (``@i{Area} Valid N %'', PCT40.1)
1366 A percentage of total counts for valid values within @var{area}.
1367
1368 @item @code{@i{area}PCT.TOTALN} (``@i{Area} Total N %'', PCT40.1)
1369 A percentage of total counts for all values within @var{area}.
1370 @end table
1371
1372 Scale variables and totals and subtotals for categorical variables may
1373 use the following additional group cell summary function:
1374
1375 @table @asis
1376 @item @code{@i{area}PCT.SUM} (``@i{Area} Sum %'', PCT40.1)
1377 Percentage of the sum of the values within @var{area}.
1378 @end table
1379
1380 @node CTABLES Summary Functions for Adjusted Weights
1381 @subsubsection Summary Functions for Adjusted Weights
1382
1383 If the @code{WEIGHT} subcommand specified an effective weight variable
1384 (@pxref{CTABLES Effective Weight}), then the following summary functions
1385 use its value instead of the dictionary weight variable.  Otherwise,
1386 they are equivalent to the summary function without the
1387 @samp{E}-prefix:
1388
1389 @itemize @bullet
1390 @item
1391 @code{ECOUNT} (``Adjusted Count'', F40.0)
1392
1393 @item
1394 @code{ETOTALN} (``Adjusted Total N'', F40.0)
1395
1396 @item
1397 @code{EVALIDN} (``Adjusted Valid N'', F40.0)
1398 @end itemize
1399
1400 @node CTABLES Unweighted Summary Functions
1401 @subsubsection Unweighted Summary Functions
1402
1403 The following summary functions with a @samp{U}-prefix are equivalent
1404 to the same ones without the prefix, except that they use unweighted
1405 counts:
1406
1407 @itemize @bullet
1408 @item
1409 @code{UCOUNT} (``Unweighted Count'', F40.0)
1410
1411 @item
1412 @code{U@i{area}PCT} or @code{U@i{area}PCT.COUNT} (``Unweighted @i{Area} %'', PCT40.1)
1413
1414 @item
1415 @code{U@i{area}PCT.VALIDN} (``Unweighted @i{Area} Valid N %'', PCT40.1)
1416
1417 @item
1418 @code{U@i{area}PCT.TOTALN} (``Unweighted @i{Area} Total N %'', PCT40.1)
1419
1420 @item
1421 @code{UMEAN} (``Unweighted Mean'')
1422
1423 @item
1424 @code{UMEDIAN} (``Unweighted Median'')
1425
1426 @item
1427 @code{UMISSING} (``Unweighted Missing'')
1428
1429 @item
1430 @code{UMODE} (``Unweighted Mode'')
1431
1432 @item
1433 @code{U@i{area}PCT.SUM} (``Unweighted @i{Area} Sum %'', PCT40.1)
1434
1435 @item
1436 @code{UPTILE} @i{n} (``Unweighted Percentile @i{n}'') 
1437
1438 @item
1439 @code{USEMEAN} (``Unweighted Std Error of Mean'')
1440
1441 @item
1442 @code{USTDDEV} (``Unweighted Std Deviation'')
1443
1444 @item
1445 @code{USUM} (``Unweighted Sum'')
1446
1447 @item
1448 @code{UTOTALN} (``Unweighted Total N'', F40.0)
1449
1450 @item
1451 @code{UVALIDN} (``Unweighted Valid N'', F40.0)
1452
1453 @item
1454 @code{UVARIANCE} (``Unweighted Variance'', F40.0)
1455 @end itemize
1456
1457 @node CTABLES Statistics Positions and Labels
1458 @subsection Statistics Positions and Labels
1459
1460 @display
1461 @t{/SLABELS}
1462     [@t{POSITION=}@{@t{COLUMN} @math{|} @t{ROW} @math{|} @t{LAYER}@}]
1463     [@t{VISIBLE=}@{@t{YES} @math{|} @t{NO}@}]
1464 @end display
1465
1466 The @code{SLABELS} subcommand controls the position and visibility of
1467 summary statistics for the @code{TABLE} subcommand that it follows.
1468
1469 @code{POSITION} sets the axis on which summary statistics appear.
1470 With @t{POSITION=COLUMN}, which is the default, each summary statistic
1471 appears in a column.  For example:
1472
1473 @example
1474 CTABLES /TABLE=qnd1 [MEAN, MEDIAN] BY qns3a.
1475 @end example
1476 @psppoutput {ctables13}
1477
1478 @noindent
1479 With @t{POSITION=ROW}, each summary statistic appears in a row, as
1480 shown below:
1481
1482 @example
1483 CTABLES /TABLE=qnd1 [MEAN, MEDIAN] BY qns3a /SLABELS POSITION=ROW.
1484 @end example
1485 @psppoutput {ctables14}
1486
1487 @noindent
1488 @t{POSITION=LAYER} is also available to place each summary statistic in
1489 a separate layer.
1490
1491 Labels for summary statistics are shown by default.  Use
1492 @t{VISIBLE=NO} to suppress them.  Because unlabeled data can cause
1493 confusion, it should only be considered if the meaning of the data is
1494 evident, as in a simple case like this:
1495
1496 @example
1497 CTABLES /TABLE=AgeGroup [TABLEPCT] /SLABELS VISIBLE=NO.
1498 @end example
1499 @psppoutput {ctables15}
1500
1501 @node CTABLES Category Label Positions
1502 @subsection Category Label Positions
1503
1504 @display
1505 @t{/CLABELS} @{@t{AUTO} @math{|} @{@t{ROWLABELS}@math{|}@t{COLLABELS}@}@t{=}@{@t{OPPOSITE}@math{|}@t{LAYER}@}@}
1506 @end display
1507
1508 The @code{CLABELS} subcommand controls the position of category labels
1509 for the @code{TABLE} subcommand that it follows.  By default, or if
1510 @t{AUTO} is specified, category labels for a given variable nest
1511 inside the variable's label on the same axis.  For example, the
1512 command below results in age categories nesting within the age group
1513 variable on the rows axis and gender categories within the gender
1514 variable on the columns axis:
1515
1516 @example
1517 CTABLES /TABLE AgeGroup BY qns3a.
1518 @end example
1519 @psppoutput {ctables16}
1520
1521 @t{ROWLABELS=OPPOSITE} or @t{COLLABELS=OPPOSITE} move row or column
1522 variable category labels, respectively, to the opposite axis.  The
1523 setting affects only the innermost variable or variables, which must
1524 be categorical, on the given axis.  For example:
1525
1526 @example
1527 CTABLES /TABLE AgeGroup BY qns3a /CLABELS ROWLABELS=OPPOSITE.
1528 CTABLES /TABLE AgeGroup BY qns3a /CLABELS COLLABELS=OPPOSITE.
1529 @end example
1530 @psppoutput {ctables17}
1531
1532 @t{ROWLABELS=LAYER} or @t{COLLABELS=LAYER} move the innermost row or
1533 column variable category labels, respectively, to the layer axis.
1534
1535 Only one axis's labels may be moved, whether to the opposite axis or
1536 to the layer axis.
1537
1538 @subsubheading Effect on Summary Statistics
1539
1540 @code{CLABELS} primarily affects the appearance of tables, not the
1541 data displayed in them.  However, @code{CTABLES} can affect the values
1542 displayed for statistics that summarize areas of a table, since it can
1543 change the definitions of these areas.
1544
1545 For example, consider the following syntax and output:
1546
1547 @example
1548 CTABLES /TABLE AgeGroup BY qns3a [ROWPCT, COLPCT].
1549 @end example
1550 @psppoutput {ctables23}
1551
1552 @noindent
1553 Using @code{COLLABELS=OPPOSITE} changes the definitions of rows and
1554 columns, so that column percentages display what were previously row
1555 percentages and the new row percentages become meaningless (because
1556 there is only one cell per row):
1557
1558 @example
1559 CTABLES
1560     /TABLE AgeGroup BY qns3a [ROWPCT, COLPCT]
1561     /CLABELS COLLABELS=OPPOSITE.
1562 @end example
1563 @psppoutput {ctables24}
1564
1565 @subsubheading Moving Categories for Stacked Variables
1566
1567 If @code{CLABELS} moves category labels from an axis with stacked
1568 variables, the variables that are moved must have the same category
1569 specifications (@pxref{CTABLES Per-Variable Category Options}) and the
1570 same value labels.
1571
1572 The following shows both moving stacked category variables and
1573 adapting to the changing definitions of rows and columns:
1574
1575 @example
1576 CTABLES /TABLE (qn105ba + qn105bb) [COLPCT].
1577 CTABLES /TABLE (qn105ba + qn105bb) [ROWPCT]
1578   /CLABELS ROW=OPPOSITE.
1579 @end example
1580 @psppoutput {ctables25}
1581
1582 @node CTABLES Per-Variable Category Options
1583 @subsection Per-Variable Category Options
1584
1585 @display
1586 @t{/CATEGORIES} @t{VARIABLES=}@i{variables}
1587     @{@t{[}@i{value}@t{,} @i{value}@dots{}@t{]}
1588    @math{|} [@t{ORDER=}@{@t{A} @math{|} @t{D}@}]
1589      [@t{KEY=}@{@t{VALUE} @math{|} @t{LABEL} @math{|} @i{summary}@t{(}@i{variable}@t{)}@}]
1590      [@t{MISSING=}@{@t{EXCLUDE} @math{|} @t{INCLUDE}@}]@}
1591     [@t{TOTAL=}@{@t{NO} @math{|} @t{YES}@} [@t{LABEL=}@i{string}] [@t{POSITION=}@{@t{AFTER} @math{|} @t{BEFORE}@}]]
1592     [@t{EMPTY=}@{@t{INCLUDE} @math{|} @t{EXCLUDE}@}]
1593 @end display
1594
1595 The @code{CATEGORIES} subcommand specifies, for one or more
1596 categorical variables, the categories to include and exclude, the sort
1597 order for included categories, and treatment of missing values.  It
1598 also controls the totals and subtotals to display.  It may be
1599 specified any number of times, each time for a different set of
1600 variables.  @code{CATEGORIES} applies to the table produced by the
1601 @code{TABLE} subcommand that it follows.
1602
1603 @code{CATEGORIES} does not apply to scalar variables.
1604
1605 @t{VARIABLES} is required and must list the variables for the subcommand
1606 to affect.
1607
1608 The syntax may specify the categories to include and their sort order
1609 either explicitly or implicitly.  The following sections give the
1610 details of each form of syntax, followed by information on totals and
1611 subtotals and the @code{EMPTY} setting.
1612
1613 @node CTABLES Explicit Categories
1614 @subsubsection Explicit Categories
1615
1616 @anchor{CTABLES Explicit Category List}
1617
1618 To use @code{CTABLES} to explicitly specify categories to include,
1619 list the categories within square brackets in the desired sort order.
1620 Use spaces or commas to separate values.  Categories not covered by
1621 the list are excluded from analysis.
1622
1623 Each element of the list takes one of the following forms:
1624
1625 @table @t
1626 @item @i{number}
1627 @itemx '@i{string}'
1628 A numeric or string category value, for variables that have the
1629 corresponding type.
1630
1631 @item '@i{date}'
1632 @itemx '@i{time}'
1633 A date or time category value, for variables that have a date or time
1634 print format.
1635
1636 @item @i{min} THRU @i{max}
1637 @itemx LO THRU @i{max}
1638 @itemx @i{min} THRU HI
1639 A range of category values, where @var{min} and @var{max} each takes
1640 one of the forms above, in increasing order.
1641
1642 @item MISSING
1643 All user-missing values.  (To match individual user-missing values,
1644 specify their category values.)
1645
1646 @item OTHERNM
1647 Any non-missing value not covered by any other element of the list
1648 (regardless of where @t{OTHERNM} is placed in the list).
1649
1650 @item &@i{postcompute}
1651 A computed category name (@pxref{CTABLES Computed Categories}).
1652
1653 @item SUBTOTAL
1654 @itemx HSUBTOTAL
1655 A subtotal (@pxref{CTABLES Totals and Subtotals}).
1656 @end table
1657
1658 If multiple elements of the list cover a given category, the last one
1659 in the list takes precedence.
1660
1661 The following example syntax and output show how an explicit category
1662 can limit the displayed categories:
1663
1664 @example
1665 CTABLES /TABLE qn1.
1666 CTABLES /TABLE qn1 /CATEGORIES VARIABLES=qn1 [1, 2, 3].
1667 @end example
1668 @psppoutput {ctables27}
1669
1670 @node CTABLES Implicit Categories
1671 @subsubsection Implicit Categories
1672
1673 In the absence of an explicit list of categories, @code{CATEGORIES}
1674 allows @code{KEY}, @code{ORDER}, and @code{MISSING} to specify how to
1675 select and sort categories.
1676
1677 The @code{KEY} setting specifies the sort key.  By default, or with
1678 @code{KEY=VALUE}, categories are sorted by default.  Categories may
1679 also be sorted by value label, with @code{KEY=LABEL}, or by the value
1680 of a summary function, e.g.@: @code{KEY=COUNT}.
1681 @ignore  @c Not yet implemented
1682 For summary functions, a variable name may be specified in
1683 parentheses, e.g.@: @code{KEY=MAXIUM(qnd1)}, and this is required for
1684 functions that apply only to scalar variables.  The @code{PTILE}
1685 function also requires a percentage argument, e.g.@:
1686 @code{KEY=PTILE(qnd1, 90)}.  Only summary functions used in the table
1687 may be used, except that @code{COUNT} is always allowed.
1688 @end ignore
1689
1690 By default, or with @code{ORDER=A}, categories are sorted in ascending
1691 order.  Specify @code{ORDER=D} to sort in descending order.
1692
1693 User-missing values are excluded by default, or with
1694 @code{MISSING=EXCLUDE}.  Specify @code{MISSING=INCLUDE} to include
1695 user-missing values.  The system-missing value is always excluded.
1696
1697 The following example syntax and output show how
1698 @code{MISSING=INCLUDE} causes missing values to be included in a
1699 category list.
1700
1701 @example
1702 CTABLES /TABLE qn1.
1703 CTABLES /TABLE qn1 /CATEGORIES VARIABLES=qn1 MISSING=INCLUDE.
1704 @end example
1705 @psppoutput {ctables28}
1706
1707 @node CTABLES Totals and Subtotals
1708 @subsubsection Totals and Subtotals
1709
1710 @code{CATEGORIES} also controls display of totals and subtotals.  By
1711 default, or with @code{TOTAL=NO}, totals are not displayed.  Use
1712 @code{TOTAL=YES} to display a total.  By default, the total is labeled
1713 ``Total''; use @code{LABEL="@i{label}"} to override it.
1714
1715 Subtotals are also not displayed by default.  To add one or more
1716 subtotals, use an explicit category list and insert @code{SUBTOTAL} or
1717 @code{HSUBTOTAL} in the position or positions where the subtotal
1718 should appear.  The subtotal becomes an extra row or column or layer.
1719 @code{HSUBTOTAL} additionally hides the categories that make up the
1720 subtotal.  Either way, the default label is ``Subtotal'', use
1721 @code{SUBTOTAL="@i{label}"} or @code{HSUBTOTAL="@i{label}"} to specify
1722 a custom label.
1723
1724 The following example syntax and output show how to use
1725 @code{TOTAL=YES} and @code{SUBTOTAL}:
1726
1727 @example
1728 CTABLES
1729     /TABLE qn1
1730     /CATEGORIES VARIABLES=qn1 [OTHERNM, SUBTOTAL='Valid Total',
1731                                MISSING, SUBTOTAL='Missing Total']
1732                               TOTAL=YES LABEL='Overall Total'.
1733 @end example
1734 @psppoutput {ctables29}
1735
1736 By default, or with @code{POSITION=AFTER}, totals are displayed in the
1737 output after the last category and subtotals apply to categories that
1738 precede them.  With @code{POSITION=BEFORE}, totals come before the
1739 first category and subtotals apply to categories that follow them.
1740
1741 Only categorical variables may have totals and subtotals.  Scalar
1742 variables may be ``totaled'' indirectly by enabling totals and
1743 subtotals on a categorical variable within which the scalar variable
1744 is summarized.  For example, the following syntax produces a mean,
1745 count, and valid count across all data by adding a total on the
1746 categorical @code{region} variable, as shown:
1747
1748 @example
1749 CTABLES /TABLE=region > qn20 [MEAN, VALIDN]
1750     /CATEGORIES VARIABLES=region TOTAL=YES LABEL='All regions'.
1751 @end example
1752 @psppoutput {ctables30}
1753
1754 By default, @pspp{} uses the same summary functions for totals and
1755 subtotals as other categories.  To summarize totals and subtotals
1756 differently, specify the summary functions for totals and subtotals
1757 after the ordinary summary functions inside a nested set of @code{[]}
1758 following @code{TOTALS}.  For example, the following syntax displays
1759 @code{COUNT} for individual categories and totals and @code{VALIDN}
1760 for totals, as shown:
1761
1762 @example
1763 CTABLES
1764     /TABLE qnd7a [COUNT, TOTALS[COUNT, VALIDN]]
1765     /CATEGORIES VARIABLES=qnd7a TOTAL=YES MISSING=INCLUDE.
1766 @end example
1767 @psppoutput {ctables26}
1768
1769 @node CTABLES Categories Without Values
1770 @subsubsection Categories Without Values
1771
1772 Some categories might not be included in the data set being analyzed.
1773 For example, our example data set has no cases in the ``15 or
1774 younger'' age group.  By default, or with @code{EMPTY=INCLUDE},
1775 @pspp{} includes these empty categories in output tables.  To exclude
1776 them, specify @code{EMPTY=EXCLUDE}.
1777
1778 For implicit categories, empty categories potentially include all the
1779 values with value labels for a given variable; for explicit
1780 categories, they include all the values listed individually and all
1781 values with value labels that are covered by ranges or @code{MISSING}
1782 or @code{OTHERNM}.
1783
1784 The following example syntax and output show the effect of
1785 @code{EMPTY=EXCLUDE} for the @code{qns1} variable, in which 0 is labeled
1786 ``None'' but no cases exist with that value:
1787
1788 @example
1789 CTABLES /TABLE=qns1.
1790 CTABLES /TABLE=qns1 /CATEGORIES VARIABLES=qns1 EMPTY=EXCLUDE.
1791 @end example
1792 @psppoutput {ctables31}
1793
1794 @node CTABLES Titles
1795 @subsection Titles
1796
1797 @display
1798 @t{/TITLES}
1799     [@t{TITLE=}@i{string}@dots{}]
1800     [@t{CAPTION=}@i{string}@dots{}]
1801     [@t{CORNER=}@i{string}@dots{}]
1802 @end display
1803
1804 The @code{TITLES} subcommand sets the title, caption, and corner text
1805 for the table output for the previous @code{TABLE} subcommand.  Any
1806 number of strings may be specified for each kind of text, with each
1807 string appearing on a separate line in the output.  The title appears
1808 above the table, the caption below the table, and the corner text
1809 appears in the table's upper left corner.  By default, the title is
1810 ``Custom Tables'' and the caption and corner text are empty.  With
1811 some table output styles, the corner text is not displayed.
1812
1813 The strings provided in this subcommand may contain the following
1814 macro-like keywords that @pspp{} substitutes at the time that it runs
1815 the command:
1816
1817 @table @code @c (
1818 @item )DATE
1819 The current date, e.g.@: MM/DD/YY.  The format is locale-dependent.
1820
1821 @c (
1822 @item )TIME
1823 The current time, e.g.@: HH:MM:SS.  The format is locale-dependent.
1824
1825 @c (
1826 @item )TABLE
1827 The expression specified on the @code{TABLE} command.  Summary
1828 and measurement level specifications are omitted, and variable labels are used in place of variable names.
1829 @end table
1830
1831 @node CTABLES Table Formatting
1832 @subsection Table Formatting
1833
1834 @display
1835 @t{/FORMAT}
1836     [@t{MINCOLWIDTH=}@{@t{DEFAULT} @math{|} @i{width}@}]
1837     [@t{MAXCOLWIDTH=}@{@t{DEFAULT} @math{|} @i{width}@}]
1838     [@t{UNITS=}@{@t{POINTS} @math{|} @t{INCHES} @math{|} @t{CM}@}]
1839     [@t{EMPTY=}@{@t{ZERO} @math{|} @t{BLANK} @math{|} @i{string}@}]
1840     [@t{MISSING=}@i{string}]
1841 @end display
1842
1843 The @code{FORMAT} subcommand, which must precede the first
1844 @code{TABLE} subcommand, controls formatting for all the output
1845 tables.  @code{FORMAT} and all of its settings are optional.
1846
1847 Use @code{MINCOLWIDTH} and @code{MAXCOLWIDTH} to control the minimum
1848 or maximum width of columns in output tables.  By default, with
1849 @code{DEFAULT}, column width varies based on content.  Otherwise,
1850 specify a number for either or both of these settings.  If both are
1851 specified, @code{MAXCOLWIDTH} must be greater than or equal to
1852 @code{MINCOLWIDTH}.  The default unit, or with @code{UNITS=POINTS}, is
1853 points (1/72 inch), or specify @code{UNITS=INCHES} to use inches or
1854 @code{UNITS=CM} for centimeters.  @pspp{} does not currently honor any
1855 of these settings.
1856
1857 By default, or with @code{EMPTY=ZERO}, zero values are displayed in
1858 their usual format.  Use @code{EMPTY=BLANK} to use an empty cell
1859 instead, or @code{EMPTY="@i{string}"} to use the specified string.
1860
1861 By default, missing values are displayed as @samp{.}, the same as in
1862 other tables.  Specify @code{MISSING="@i{string}"} to instead use a
1863 custom string.
1864
1865 @node CTABLES Display of Variable Labels
1866 @subsection Display of Variable Labels
1867
1868 @display
1869 @t{/VLABELS}
1870     @t{VARIABLES=}@i{variables}
1871     @t{DISPLAY}=@{@t{DEFAULT} @math{|} @t{NAME} @math{|} @t{LABEL} @math{|} @t{BOTH} @math{|} @t{NONE}@}
1872 @end display
1873
1874 The @code{VLABELS} subcommand, which must precede the first
1875 @code{TABLE} subcommand, controls display of variable labels in all
1876 the output tables.  @code{VLABELS} is optional.  It may appear
1877 multiple times to adjust settings for different variables.
1878
1879 @code{VARIABLES} and @code{DISPLAY} are required.  The value of
1880 @code{DISPLAY} controls how variable labels are displayed for the
1881 variables listed on @code{VARIABLES}.  The supported values are:
1882
1883 @table @code
1884 @item DEFAULT
1885 Use the setting from @code{SET TVARS} (@pxref{SET TVARS}).
1886
1887 @item NAME
1888 Show only a variable name.
1889
1890 @item LABEL
1891 Show only a variable label.
1892
1893 @item BOTH
1894 Show variable name and label.
1895
1896 @item NONE
1897 Show nothing.
1898 @end table
1899
1900 @node CTABLES Missing Value Treatment
1901 @subsection Missing Value Treatment
1902
1903 The @code{TABLE} subcommand on @code{CTABLES} specifies two different
1904 kinds of variables: variables that divide tables into cells (which are
1905 always categorical) and variables being summarized (which may be
1906 categorical or scale).  @pspp{} treats missing values differently in
1907 each kind of variable, as described in the sections below.
1908
1909 @node CTABLES Missing Values for Cell-Defining Variables
1910 @subsubsection Missing Values for Cell-Defining Variables
1911
1912 For variables that divide tables into cells, per-variable category
1913 options, as described in @ref{CTABLES Per-Variable Category Options},
1914 determine which data is analyzed.  If any of the categories for such a
1915 variable would exclude a case, then that case is not included.
1916
1917 As an example, consider the following entirely artificial dataset, in
1918 which @samp{x} and @samp{y} are categorical variables with missing
1919 value 9, and @samp{z} is scale:
1920
1921 @psppoutput{ctables32}
1922
1923 Using @samp{x} and @samp{y} to define cells, and summarizing @samp{z},
1924 by default @pspp{} omits all the cases that have @samp{x} or @samp{y} (or both)
1925 missing:
1926
1927 @example
1928 CTABLES /TABLE x > y > z [SUM].
1929 @end example
1930 @psppoutput{ctables33}
1931
1932 If, however, we add @code{CATEGORIES} specifications to include
1933 missing values for @samp{y} or for @samp{x} and @samp{y}, the output
1934 table includes them, like so:
1935
1936 @example
1937 CTABLES /TABLE x > y > z [SUM] /CATEGORIES VARIABLES=y MISSING=INCLUDE.
1938 CTABLES /TABLE x > y > z [SUM] /CATEGORIES VARIABLES=x y MISSING=INCLUDE.
1939 @end example
1940 @psppoutput{ctables34}
1941
1942 @node CTABLES Missing Values for Summary Variables
1943 @subsubsection Missing Values for Summary Variables
1944
1945 For summary variables, values that are valid and in included
1946 categories are analyzed, and values that are missing or in excluded
1947 categories are not analyzed, with the following exceptions:
1948
1949 @itemize @bullet
1950 @item
1951 The ``@t{VALIDN}'' summary functions (@code{VALIDN}, @code{EVALIDN},
1952 @code{UVALIDN}, @code{@i{area}PCT.VALIDN}, and
1953 @code{U@i{area}PCT.VALIDN}) only count valid values in included
1954 categories (not missing values in included categories).
1955
1956 @item
1957 The ``@t{TOTALN}'' summary functions (@code{TOTALN}, @code{ETOTALN},
1958 @code{UTOTALN}, @code{@i{area}PCT.TOTALN}), and
1959 @code{U@i{area}PCT.TOTALN} count all values (valid and missing) in
1960 included categories and missing (but not valid) values in excluded
1961 categories.
1962 @end itemize
1963
1964 @noindent
1965 For categorical variables, system-missing values are never in included
1966 categories.  For scale variables, there is no notion of included and
1967 excluded categories, so all values are effectively included.
1968
1969 The following table provides another view of the above rules:
1970
1971 @multitable {@w{ }@w{ }@w{ }@w{ }Missing values in excluded categories} {@t{VALIDN}} {other} {@t{TOTALN}}
1972 @headitem @tab @t{VALIDN} @tab other @tab @t{TOTALN}
1973 @item @headitemfont{Categorical variables:}
1974 @item @w{ }@w{ }@w{ }@w{ }Valid values in included categories   @tab yes @tab yes @tab yes
1975 @item @w{ }@w{ }@w{ }@w{ }Missing values in included categories @tab --- @tab yes @tab yes
1976 @item @w{ }@w{ }@w{ }@w{ }Missing values in excluded categories @tab --- @tab --- @tab yes
1977 @item @w{ }@w{ }@w{ }@w{ }Valid values in excluded categories   @tab --- @tab --- @tab ---
1978 @item @headitemfont{Scale variables:}
1979 @item @w{ }@w{ }@w{ }@w{ }Valid values                          @tab yes @tab yes @tab yes
1980 @item @w{ }@w{ }@w{ }@w{ }User- or system-missing values        @tab --- @tab yes @tab yes
1981 @end multitable
1982
1983 @node CTABLES Scale Missing Values
1984 @subsubsection Scale Missing Values
1985
1986 @display
1987 @t{/SMISSING} @{@t{VARIABLE} @math{|} @t{LISTWISE}@}
1988 @end display
1989
1990 The @code{SMISSING} subcommand, which must precede the first
1991 @code{TABLE} subcommand, controls treatment of missing values for
1992 scalar variables in producing all the output tables.  @code{SMISSING}
1993 is optional.
1994
1995 With @code{SMISSING=VARIABLE}, which is the default, missing values
1996 are excluded on a variable-by-variable basis.  With
1997 @code{SMISSING=LISTWISE}, when stacked scalar variables are nested
1998 together with a categorical variable, a missing value for any of the
1999 scalar variables causes the case to be excluded for all of them.
2000
2001 As an example, consider the following dataset, in which @samp{x} is a
2002 categorical variable and @samp{y} and @samp{z} are scale:
2003
2004 @psppoutput{ctables18}
2005
2006 @noindent
2007 With the default missing-value treatment, @samp{x}'s mean is 20, based
2008 on the values 10, 20, and 30, and @samp{y}'s mean is 50, based on 40,
2009 50, and 60:
2010
2011 @example
2012 CTABLES /TABLE (y + z) > x.
2013 @end example
2014 @psppoutput{ctables19}
2015
2016 @noindent
2017 By adding @code{SMISSING=LISTWISE}, only cases where @samp{y} and
2018 @samp{z} are both non-missing are considered, so @samp{x}'s mean
2019 becomes 15, as the average of 10 and 20, and @samp{y}'s mean becomes
2020 55, the average of 50 and 60:
2021
2022 @example
2023 CTABLES /SMISSING LISTWISE /TABLE (y + z) > x.
2024 @end example
2025 @psppoutput{ctables20}
2026
2027 @noindent
2028 Even with @code{SMISSING=LISTWISE}, if @samp{y} and @samp{z} are
2029 separately nested with @samp{x}, instead of using a single @samp{>}
2030 operator, missing values revert to being considered on a
2031 variable-by-variable basis:
2032
2033 @example
2034 CTABLES /SMISSING LISTWISE /TABLE (y > x) + (z > x).
2035 @end example
2036 @psppoutput{ctables21}
2037
2038 @node CTABLES Computed Categories
2039 @subsection Computed Categories
2040
2041 @display
2042 @t{/PCOMPUTE} @t{&}@i{postcompute}@t{=EXPR(}@i{expression}@t{)}
2043 @t{/PPROPERTIES} @t{&}@i{postcompute}@dots{}
2044     [@t{LABEL=}@i{string}]
2045     [@t{FORMAT=}[@i{summary} @i{format}]@dots{}]
2046     [@t{HIDESOURCECATS=}@{@t{NO} @math{|} @t{YES}@}
2047 @end display
2048
2049 @dfn{Computed categories}, also called @dfn{postcomputes}, are
2050 categories created using arithmetic on categories obtained from the
2051 data.  The @code{PCOMPUTE} subcommand creates a postcompute, which may
2052 then be used on @code{CATEGORIES} within an explicit category list
2053 (@pxref{CTABLES Explicit Category List}).  Optionally,
2054 @code{PPROPERTIES} refines how a postcompute is displayed.  The
2055 following sections provide the details.
2056
2057 @node CTABLES PCOMPUTE
2058 @subsubsection PCOMPUTE
2059
2060 @display
2061 @t{/PCOMPUTE} @t{&}@i{postcompute}@t{=EXPR(}@i{expression}@t{)}
2062 @end display
2063
2064 The @code{PCOMPUTE} subcommand, which must precede the first
2065 @code{TABLE} command, defines computed categories.  It is optional and
2066 may be used any number of times to define multiple postcomputes.
2067
2068 Each @code{PCOMPUTE} defines one postcompute.  Its syntax consists of
2069 a name to identify the postcompute as a @pspp{} identifier prefixed by
2070 @samp{&}, followed by @samp{=} and a postcompute expression enclosed
2071 in @code{EXPR(@dots{})}.  A postcompute expression consists of:
2072
2073 @table @t
2074 @item [@i{category}]
2075 This form evaluates to the summary statistic for @i{category}, e.g.@:
2076 @code{[1]} evaluates to the value of the summary statistic associated
2077 with category 1.  The @i{category} may be a number, a quoted string,
2078 or a quoted time or date value.  All of the categories for a given
2079 postcompute must have the same form.  The category must appear in all
2080 the @code{CATEGORIES} list in which the postcompute is used.
2081
2082 @item [@i{min} THRU @i{max}]
2083 @itemx [LO THRU @i{max}]
2084 @itemx [@i{min} THRU HI]
2085 @itemx MISSING
2086 @itemx OTHERNM
2087 These forms evaluate to the summary statistics for a category
2088 specified with the same syntax, as described in previous section
2089 (@pxref{CTABLES Explicit Category List}).  The category must appear in
2090 all the @code{CATEGORIES} list in which the postcompute is used.
2091
2092 @item SUBTOTAL
2093 The summary statistic for the subtotal category.  This form is allowed
2094 only if the @code{CATEGORIES} lists that include this postcompute have
2095 exactly one subtotal.
2096
2097 @item SUBTOTAL[@i{index}]
2098 The summary statistic for subtotal category @i{index}, where 1 is the
2099 first subtotal, 2 is the second, and so on.  This form may be used for
2100 @code{CATEGORIES} lists with any number of subtotals.
2101
2102 @item TOTAL
2103 The summary statistic for the total.  The @code{CATEGORIES} lsits that
2104 include this postcompute must have a total enabled.
2105
2106 @item @i{a} + @i{b}
2107 @itemx @i{a} - @i{b}
2108 @itemx @i{a} * @i{b}
2109 @itemx @i{a} / @i{b}
2110 @itemx @i{a} ** @i{b}
2111 These forms perform arithmetic on the values of postcompute
2112 expressions @i{a} and @i{b}.  The usual operator precedence rules
2113 apply.
2114
2115 @item @i{number}
2116 Numeric constants may be used in postcompute expressions.
2117
2118 @item (@i{a})
2119 Parentheses override operator precedence.
2120 @end table
2121
2122 A postcompute is not associated with any particular variable.
2123 Instead, it may be referenced within @code{CATEGORIES} for any
2124 suitable variable (e.g.@: only a string variable is suitable for a
2125 postcompute expression that refers to a string category, only a
2126 variable with subtotals for an expression that refers to subtotals,
2127 @dots{}).
2128
2129 Normally a named postcompute is defined only once, but if a later
2130 @code{PCOMPUTE} redefines a postcompute with the same name as an
2131 earlier one, the later one take precedence.
2132
2133 The following syntax and output shows how @code{PCOMPUTE} can compute
2134 a total over subtotals, summing the ``Frequent Drivers'' and
2135 ``Infrequent Drivers'' subtotals to form an ``All Drivers''
2136 postcompute.  It also shows how to calculate and display a percentage,
2137 in this case the percentage of valid responses that report never
2138 driving.  It uses @code{PPROPERTIES} (@pxref{CTABLES PPROPERTIES}) to
2139 display the latter in @code{PCT} format.
2140
2141 @example
2142 CTABLES
2143     /PCOMPUTE &all_drivers=EXPR([1 THRU 2] + [3 THRU 4])
2144     /PPROPERTIES &all_drivers LABEL='All Drivers'
2145     /PCOMPUTE &pct_never=EXPR([5] / ([1 THRU 2] + [3 THRU 4] + [5]) * 100)
2146     /PPROPERTIES &pct_never LABEL='% Not Drivers' FORMAT=COUNT PCT40.1
2147     /TABLE=qn1 BY qns3a
2148     /CATEGORIES VARIABLES=qn1 [1 THRU 2, SUBTOTAL='Frequent Drivers',
2149                                3 THRU 4, SUBTOTAL='Infrequent Drivers',
2150                                &all_drivers, 5, &pct_never,
2151                                MISSING, SUBTOTAL='Not Drivers or Missing'].
2152 @end example
2153 @psppoutput{ctables35}
2154
2155 @node CTABLES PPROPERTIES
2156 @subsubsection PPROPERTIES
2157
2158 @display
2159 @t{/PPROPERTIES} @t{&}@i{postcompute}@dots{}
2160     [@t{LABEL=}@i{string}]
2161     [@t{FORMAT=}[@i{summary} @i{format}]@dots{}]
2162     [@t{HIDESOURCECATS=}@{@t{NO} @math{|} @t{YES}@}
2163 @end display
2164
2165 The @code{PPROPERTIES} subcommand, which must appear before
2166 @code{TABLE}, sets properties for one or more postcomputes defined on
2167 prior @code{PCOMPUTE} subcommands.  The subcommand syntax begins with
2168 the list of postcomputes, each prefixed with @samp{&} as specified on
2169 @code{PCOMPUTE}.
2170
2171 All of the settings on @code{PPROPERTIES} are optional.  Use
2172 @code{LABEL} to set the label shown for the postcomputes in table
2173 output.  The default label for a postcompute is the expression used to
2174 define it.
2175
2176 A postcompute always uses same summary functions as the variable whose
2177 categories contain it, but @code{FORMAT} allows control over the
2178 format used to display their values.  It takes a list of summary
2179 function names and format specifiers.
2180
2181 By default, or with @code{HIDESOURCECATS=NO}, categories referred to
2182 by computed categories are displayed like other categories.  Use
2183 @code{HIDESOURCECATS=YES} to hide them.
2184
2185 The previous section provides an example for @code{PPROPERTIES}.
2186
2187 @node CTABLES Effective Weight
2188 @subsection Effective Weight
2189
2190 @display
2191 @t{/WEIGHT VARIABLE=}@i{variable}
2192 @end display
2193
2194 The @code{WEIGHT} subcommand is optional and must appear before
2195 @code{TABLE}.  If it appears, it must name a numeric variable, known
2196 as the @dfn{effective weight} or @dfn{adjustment weight}.  The
2197 effective weight variable stands in for the dictionary's weight
2198 variable (@pxref{WEIGHT}), if any, in most calculations in
2199 @code{CTABLES}.  The only exceptions are the @code{COUNT},
2200 @code{TOTALN}, and @code{VALIDN} summary functions, which use the
2201 dictionary weight instead.
2202
2203 Weights obtained from the @pspp{} dictionary are rounded to the
2204 nearest integer at the case level.  Effective weights are not rounded.
2205 Regardless of the weighting source, @pspp{} does not analyze cases
2206 with zero, missing, or negative effective weights.
2207
2208 @node CTABLES Hiding Small Counts
2209 @subsection Hiding Small Counts
2210
2211 @display
2212 @t{/HIDESMALLCOUNTS COUNT=@i{count}}
2213 @end display
2214
2215 The @code{HIDESMALLCOUNTS} subcommand is optional.  If it specified,
2216 then @code{COUNT}, @code{ECOUNT}, and @code{UCOUNT} values in output
2217 tables less than the value of @i{count} are shown as @code{<@i{count}}
2218 instead of their true values.  The value of @i{count} must be an
2219 integer and must be at least 2.
2220
2221 The following syntax and example shows how to use
2222 @code{HIDESMALLCOUNTS}:
2223
2224 @example
2225 CTABLES /HIDESMALLCOUNTS COUNT=10 /TABLE qn37.
2226 @end example
2227 @psppoutput{ctables36}
2228
2229 @node FACTOR
2230 @section FACTOR
2231
2232 @vindex FACTOR
2233 @cindex factor analysis
2234 @cindex principal components analysis
2235 @cindex principal axis factoring
2236 @cindex data reduction
2237
2238 @display
2239 FACTOR  @{
2240          VARIABLES=@var{var_list},
2241          MATRIX IN (@{CORR,COV@}=@{*,@var{file_spec}@})
2242         @}
2243
2244         [ /METHOD = @{CORRELATION, COVARIANCE@} ]
2245
2246         [ /ANALYSIS=@var{var_list} ]
2247
2248         [ /EXTRACTION=@{PC, PAF@}]
2249
2250         [ /ROTATION=@{VARIMAX, EQUAMAX, QUARTIMAX, PROMAX[(@var{k})], NOROTATE@}]
2251
2252         [ /PRINT=[INITIAL] [EXTRACTION] [ROTATION] [UNIVARIATE] [CORRELATION] [COVARIANCE] [DET] [KMO] [AIC] [SIG] [ALL] [DEFAULT] ]
2253
2254         [ /PLOT=[EIGEN] ]
2255
2256         [ /FORMAT=[SORT] [BLANK(@var{n})] [DEFAULT] ]
2257
2258         [ /CRITERIA=[FACTORS(@var{n})] [MINEIGEN(@var{l})] [ITERATE(@var{m})] [ECONVERGE (@var{delta})] [DEFAULT] ]
2259
2260         [ /MISSING=[@{LISTWISE, PAIRWISE@}] [@{INCLUDE, EXCLUDE@}] ]
2261 @end display
2262
2263 The @cmd{FACTOR} command performs Factor Analysis or Principal Axis Factoring on a dataset.  It may be used to find
2264 common factors in the data or for data reduction purposes.
2265
2266 The @subcmd{VARIABLES} subcommand is required (unless the @subcmd{MATRIX IN}
2267 subcommand is used).
2268 It lists the variables which are to partake in the analysis.  (The @subcmd{ANALYSIS}
2269 subcommand may optionally further limit the variables that
2270 participate; it is useful primarily in conjunction with @subcmd{MATRIX IN}.)
2271
2272 If @subcmd{MATRIX IN} instead of @subcmd{VARIABLES} is specified, then the analysis
2273 is performed on a pre-prepared correlation or covariance matrix file instead of on
2274 individual data cases.  Typically the matrix file will have been generated by
2275 @cmd{MATRIX DATA} (@pxref{MATRIX DATA}) or provided by a third party.
2276 If specified, @subcmd{MATRIX IN} must be followed by @samp{COV} or @samp{CORR},
2277 then by @samp{=} and @var{file_spec} all in parentheses.
2278 @var{file_spec} may either be an asterisk, which indicates the currently loaded
2279 dataset, or it may be a file name to be loaded. @xref{MATRIX DATA}, for the expected
2280 format of the file.
2281
2282 The @subcmd{/EXTRACTION} subcommand is used to specify the way in which factors
2283 (components) are extracted from the data.
2284 If @subcmd{PC} is specified, then Principal Components Analysis is used.
2285 If @subcmd{PAF} is specified, then Principal Axis Factoring is
2286 used. By default Principal Components Analysis is used.
2287
2288 The @subcmd{/ROTATION} subcommand is used to specify the method by which the
2289 extracted solution is rotated.  Three orthogonal rotation methods are available:
2290 @subcmd{VARIMAX} (which is the default), @subcmd{EQUAMAX}, and @subcmd{QUARTIMAX}.
2291 There is one oblique rotation method, @i{viz}: @subcmd{PROMAX}.
2292 Optionally you may enter the power of the promax rotation @var{k}, which must be enclosed in parentheses.
2293 The default value of @var{k} is 5.
2294 If you don't want any rotation to be performed, the word @subcmd{NOROTATE}
2295 prevents the command from performing any rotation on the data.
2296
2297 The @subcmd{/METHOD} subcommand should be used to determine whether the
2298 covariance matrix or the correlation matrix of the data is
2299 to be analysed.  By default, the correlation matrix is analysed.
2300
2301 The @subcmd{/PRINT} subcommand may be used to select which features of the analysis are reported:
2302
2303 @itemize
2304 @item @subcmd{UNIVARIATE}
2305       A table of mean values, standard deviations and total weights are printed.
2306 @item @subcmd{INITIAL}
2307       Initial communalities and eigenvalues are printed.
2308 @item @subcmd{EXTRACTION}
2309       Extracted communalities and eigenvalues are printed.
2310 @item @subcmd{ROTATION}
2311       Rotated communalities and eigenvalues are printed.
2312 @item @subcmd{CORRELATION}
2313       The correlation matrix is printed.
2314 @item @subcmd{COVARIANCE}
2315       The covariance matrix is printed.
2316 @item @subcmd{DET}
2317       The determinant of the correlation or covariance matrix is printed.
2318 @item @subcmd{AIC}
2319       The anti-image covariance and anti-image correlation matrices are printed.
2320 @item @subcmd{KMO}
2321       The Kaiser-Meyer-Olkin measure of sampling adequacy and the Bartlett test of sphericity is printed.
2322 @item @subcmd{SIG}
2323       The significance of the elements of correlation matrix is printed.
2324 @item @subcmd{ALL}
2325       All of the above are printed.
2326 @item @subcmd{DEFAULT}
2327       Identical to @subcmd{INITIAL} and @subcmd{EXTRACTION}.
2328 @end itemize
2329
2330 If @subcmd{/PLOT=EIGEN} is given, then a ``Scree'' plot of the eigenvalues is
2331 printed.  This can be useful for visualizing the factors and deciding
2332 which factors (components) should be retained.
2333
2334 The @subcmd{/FORMAT} subcommand determined how data are to be
2335 displayed in loading matrices.  If @subcmd{SORT} is specified, then
2336 the variables are sorted in descending order of significance.  If
2337 @subcmd{BLANK(@var{n})} is specified, then coefficients whose absolute
2338 value is less than @var{n} are not printed.  If the keyword
2339 @subcmd{DEFAULT} is specified, or if no @subcmd{/FORMAT} subcommand is
2340 specified, then no sorting is performed, and all coefficients are printed.
2341
2342 You can use the @subcmd{/CRITERIA} subcommand to specify how the number of
2343 extracted factors (components) are chosen.  If @subcmd{FACTORS(@var{n})} is
2344 specified, where @var{n} is an integer, then @var{n} factors are
2345 extracted.  Otherwise, the @subcmd{MINEIGEN} setting is used.
2346 @subcmd{MINEIGEN(@var{l})} requests that all factors whose eigenvalues
2347 are greater than or equal to @var{l} are extracted. The default value
2348 of @var{l} is 1. The @subcmd{ECONVERGE} setting has effect only when
2349 using iterative algorithms for factor extraction (such as Principal Axis
2350 Factoring).  @subcmd{ECONVERGE(@var{delta})} specifies that
2351 iteration should cease when the maximum absolute value of the
2352 communality estimate between one iteration and the previous is less
2353 than @var{delta}. The default value of @var{delta} is 0.001.
2354
2355 The @subcmd{ITERATE(@var{m})} may appear any number of times and is
2356 used for two different purposes. It is used to set the maximum number
2357 of iterations (@var{m}) for convergence and also to set the maximum
2358 number of iterations for rotation.
2359 Whether it affects convergence or rotation depends upon which
2360 subcommand follows the @subcmd{ITERATE} subcommand.
2361 If @subcmd{EXTRACTION} follows, it affects convergence.
2362 If @subcmd{ROTATION} follows, it affects rotation.
2363 If neither @subcmd{ROTATION} nor @subcmd{EXTRACTION} follow a
2364 @subcmd{ITERATE} subcommand, then the entire subcommand is ignored.
2365 The default value of @var{m} is 25.
2366
2367 The @cmd{MISSING} subcommand determines the handling of missing
2368 variables.  If @subcmd{INCLUDE} is set, then user-missing values are
2369 included in the calculations, but system-missing values are not.
2370 If @subcmd{EXCLUDE} is set, which is the default, user-missing
2371 values are excluded as well as system-missing values.  This is the
2372 default. If @subcmd{LISTWISE} is set, then the entire case is excluded
2373 from analysis whenever any variable  specified in the @cmd{VARIABLES}
2374 subcommand contains a missing value.
2375
2376 If @subcmd{PAIRWISE} is set, then a case is considered missing only if
2377 either of the values  for the particular coefficient are missing.
2378 The default is @subcmd{LISTWISE}.
2379
2380 @node GLM
2381 @section GLM
2382
2383 @vindex GLM
2384 @cindex univariate analysis of variance
2385 @cindex fixed effects
2386 @cindex factorial anova
2387 @cindex analysis of variance
2388 @cindex ANOVA
2389
2390
2391 @display
2392 GLM @var{dependent_vars} BY @var{fixed_factors}
2393      [/METHOD = SSTYPE(@var{type})]
2394      [/DESIGN = @var{interaction_0} [@var{interaction_1} [... @var{interaction_n}]]]
2395      [/INTERCEPT = @{INCLUDE|EXCLUDE@}]
2396      [/MISSING = @{INCLUDE|EXCLUDE@}]
2397 @end display
2398
2399 The @cmd{GLM} procedure can be used for fixed effects factorial Anova.
2400
2401 The @var{dependent_vars} are the variables to be analysed.
2402 You may analyse several variables in the same command in which case they should all
2403 appear before the @code{BY} keyword.
2404
2405 The @var{fixed_factors} list must be one or more categorical variables.  Normally it
2406 does not make sense to enter a scalar variable in the @var{fixed_factors} and doing
2407 so may cause @pspp{} to do a lot of unnecessary processing.
2408
2409 The @subcmd{METHOD} subcommand is used to change the method for producing the sums of
2410 squares.  Available values of @var{type} are 1, 2 and 3.  The default is type 3.
2411
2412 You may specify a custom design using the @subcmd{DESIGN} subcommand.
2413 The design comprises a list of interactions where each interaction is a
2414 list of variables separated by a @samp{*}.  For example the command
2415 @display
2416 GLM subject BY sex age_group race
2417     /DESIGN = age_group sex group age_group*sex age_group*race
2418 @end display
2419 @noindent specifies the model @math{subject = age_group + sex + race + age_group*sex + age_group*race}.
2420 If no @subcmd{DESIGN} subcommand is specified, then the default is all possible combinations
2421 of the fixed factors.  That is to say
2422 @display
2423 GLM subject BY sex age_group race
2424 @end display
2425 implies the model
2426 @math{subject = age_group + sex + race + age_group*sex + age_group*race + sex*race + age_group*sex*race}.
2427
2428
2429 The @subcmd{MISSING} subcommand determines the handling of missing
2430 variables.
2431 If @subcmd{INCLUDE} is set then, for the purposes of GLM analysis,
2432 only system-missing values are considered
2433 to be missing; user-missing values are not regarded as missing.
2434 If @subcmd{EXCLUDE} is set, which is the default, then user-missing
2435 values are considered to be missing as well as system-missing values.
2436 A case for which any dependent variable or any factor
2437 variable has a missing value is excluded from the analysis.
2438
2439 @node LOGISTIC REGRESSION
2440 @section LOGISTIC REGRESSION
2441
2442 @vindex LOGISTIC REGRESSION
2443 @cindex logistic regression
2444 @cindex bivariate logistic regression
2445
2446 @display
2447 LOGISTIC REGRESSION [VARIABLES =] @var{dependent_var} WITH @var{predictors}
2448
2449      [/CATEGORICAL = @var{categorical_predictors}]
2450
2451      [@{/NOCONST | /ORIGIN | /NOORIGIN @}]
2452
2453      [/PRINT = [SUMMARY] [DEFAULT] [CI(@var{confidence})] [ALL]]
2454
2455      [/CRITERIA = [BCON(@var{min_delta})] [ITERATE(@var{max_interations})]
2456                   [LCON(@var{min_likelihood_delta})] [EPS(@var{min_epsilon})]
2457                   [CUT(@var{cut_point})]]
2458
2459      [/MISSING = @{INCLUDE|EXCLUDE@}]
2460 @end display
2461
2462 Bivariate Logistic Regression is used when you want to explain a dichotomous dependent
2463 variable in terms of one or more predictor variables.
2464
2465 The minimum command is
2466 @example
2467 LOGISTIC REGRESSION @var{y} WITH @var{x1} @var{x2} @dots{} @var{xn}.
2468 @end example
2469 Here, @var{y} is the dependent variable, which must be dichotomous and @var{x1} @dots{} @var{xn}
2470 are the predictor variables whose coefficients the procedure estimates.
2471
2472 By default, a constant term is included in the model.
2473 Hence, the full model is
2474 @math{
2475 {\bf y}
2476 = b_0 + b_1 {\bf x_1}
2477 + b_2 {\bf x_2}
2478 + \dots
2479 + b_n {\bf x_n}
2480 }
2481
2482 Predictor variables which are categorical in nature should be listed on the @subcmd{/CATEGORICAL} subcommand.
2483 Simple variables as well as interactions between variables may be listed here.
2484
2485 If you want a model without the constant term @math{b_0}, use the keyword @subcmd{/ORIGIN}.
2486 @subcmd{/NOCONST} is a synonym for @subcmd{/ORIGIN}.
2487
2488 An iterative Newton-Raphson procedure is used to fit the model.
2489 The @subcmd{/CRITERIA} subcommand is used to specify the stopping criteria of the procedure,
2490 and other parameters.
2491 The value of @var{cut_point} is used in the classification table.  It is the
2492 threshold above which predicted values are considered to be 1.  Values
2493 of @var{cut_point} must lie in the range [0,1].
2494 During iterations, if any one of the stopping criteria are satisfied, the procedure is
2495 considered complete.
2496 The stopping criteria are:
2497 @itemize
2498 @item The number of iterations exceeds @var{max_iterations}.
2499       The default value of @var{max_iterations} is 20.
2500 @item The change in the all coefficient estimates are less than @var{min_delta}.
2501 The default value of @var{min_delta} is 0.001.
2502 @item The magnitude of change in the likelihood estimate is less than @var{min_likelihood_delta}.
2503 The default value of @var{min_delta} is zero.
2504 This means that this criterion is disabled.
2505 @item The differential of the estimated probability for all cases is less than @var{min_epsilon}.
2506 In other words, the probabilities are close to zero or one.
2507 The default value of @var{min_epsilon} is 0.00000001.
2508 @end itemize
2509
2510
2511 The @subcmd{PRINT} subcommand controls the display of optional statistics.
2512 Currently there is one such option, @subcmd{CI}, which indicates that the
2513 confidence interval of the odds ratio should be displayed as well as its value.
2514 @subcmd{CI} should be followed by an integer in parentheses, to indicate the
2515 confidence level of the desired confidence interval.
2516
2517 The @subcmd{MISSING} subcommand determines the handling of missing
2518 variables.
2519 If @subcmd{INCLUDE} is set, then user-missing values are included in the
2520 calculations, but system-missing values are not.
2521 If @subcmd{EXCLUDE} is set, which is the default, user-missing
2522 values are excluded as well as system-missing values.
2523 This is the default.
2524
2525 @node MEANS
2526 @section MEANS
2527
2528 @vindex MEANS
2529 @cindex means
2530
2531 @display
2532 MEANS [TABLES =]
2533       @{@var{var_list}@}
2534         [ BY @{@var{var_list}@} [BY @{@var{var_list}@} [BY @{@var{var_list}@} @dots{} ]]]
2535
2536       [ /@{@var{var_list}@}
2537          [ BY @{@var{var_list}@} [BY @{@var{var_list}@} [BY @{@var{var_list}@} @dots{} ]]] ]
2538
2539       [/CELLS = [MEAN] [COUNT] [STDDEV] [SEMEAN] [SUM] [MIN] [MAX] [RANGE]
2540         [VARIANCE] [KURT] [SEKURT]
2541         [SKEW] [SESKEW] [FIRST] [LAST]
2542         [HARMONIC] [GEOMETRIC]
2543         [DEFAULT]
2544         [ALL]
2545         [NONE] ]
2546
2547       [/MISSING = [INCLUDE] [DEPENDENT]]
2548 @end display
2549
2550 You can use the @cmd{MEANS} command to calculate the arithmetic mean and similar
2551 statistics, either for the dataset as a whole or for categories of data.
2552
2553 The simplest form of the command is
2554 @example
2555 MEANS @var{v}.
2556 @end example
2557 @noindent which calculates the mean, count and standard deviation for @var{v}.
2558 If you specify a grouping variable, for example
2559 @example
2560 MEANS @var{v} BY @var{g}.
2561 @end example
2562 @noindent then the means, counts and standard deviations for @var{v} after having
2563 been grouped by @var{g} are calculated.
2564 Instead of the mean, count and standard deviation, you could specify the statistics
2565 in which you are interested:
2566 @example
2567 MEANS @var{x} @var{y} BY @var{g}
2568       /CELLS = HARMONIC SUM MIN.
2569 @end example
2570 This example calculates the harmonic mean, the sum and the minimum values of @var{x} and @var{y}
2571 grouped by @var{g}.
2572
2573 The @subcmd{CELLS} subcommand specifies which statistics to calculate.  The available statistics
2574 are:
2575 @itemize
2576 @item @subcmd{MEAN}
2577 @cindex arithmetic mean
2578       The arithmetic mean.
2579 @item @subcmd{COUNT}
2580       The count of the values.
2581 @item @subcmd{STDDEV}
2582       The standard deviation.
2583 @item @subcmd{SEMEAN}
2584       The standard error of the mean.
2585 @item @subcmd{SUM}
2586       The sum of the values.
2587 @item @subcmd{MIN}
2588       The minimum value.
2589 @item @subcmd{MAX}
2590       The maximum value.
2591 @item @subcmd{RANGE}
2592       The difference between the maximum and minimum values.
2593 @item @subcmd{VARIANCE}
2594       The variance.
2595 @item @subcmd{FIRST}
2596       The first value in the category.
2597 @item @subcmd{LAST}
2598       The last value in the category.
2599 @item @subcmd{SKEW}
2600       The skewness.
2601 @item @subcmd{SESKEW}
2602       The standard error of the skewness.
2603 @item @subcmd{KURT}
2604       The kurtosis
2605 @item @subcmd{SEKURT}
2606       The standard error of the kurtosis.
2607 @item @subcmd{HARMONIC}
2608 @cindex harmonic mean
2609       The harmonic mean.
2610 @item @subcmd{GEOMETRIC}
2611 @cindex geometric mean
2612       The geometric mean.
2613 @end itemize
2614
2615 In addition, three special keywords are recognized:
2616 @itemize
2617 @item @subcmd{DEFAULT}
2618       This is the same as @subcmd{MEAN} @subcmd{COUNT} @subcmd{STDDEV}.
2619 @item @subcmd{ALL}
2620       All of the above statistics are calculated.
2621 @item @subcmd{NONE}
2622       No statistics are calculated (only a summary is shown).
2623 @end itemize
2624
2625
2626 More than one @dfn{table} can be specified in a single command.
2627 Each table is separated by a @samp{/}. For
2628 example
2629 @example
2630 MEANS TABLES =
2631       @var{c} @var{d} @var{e} BY @var{x}
2632       /@var{a} @var{b} BY @var{x} @var{y}
2633       /@var{f} BY @var{y} BY @var{z}.
2634 @end example
2635 has three tables (the @samp{TABLE =} is optional).
2636 The first table has three dependent variables @var{c}, @var{d} and @var{e}
2637 and a single categorical variable @var{x}.
2638 The second table has two dependent variables @var{a} and @var{b},
2639 and two categorical variables @var{x} and @var{y}.
2640 The third table has a single dependent variables @var{f}
2641 and a categorical variable formed by the combination of @var{y} and @var{z}.
2642
2643
2644 By default values are omitted from the analysis only if missing values
2645 (either system missing or user missing)
2646 for any of the variables directly involved in their calculation are
2647 encountered.
2648 This behaviour can be modified with the  @subcmd{/MISSING} subcommand.
2649 Three options are possible: @subcmd{TABLE}, @subcmd{INCLUDE} and @subcmd{DEPENDENT}.
2650
2651 @subcmd{/MISSING = INCLUDE} says that user missing values, either in the dependent
2652 variables or in the categorical variables should be taken at their face
2653 value, and not excluded.
2654
2655 @subcmd{/MISSING = DEPENDENT} says that user missing values, in the dependent
2656 variables should be taken at their face value, however cases which
2657 have user missing values for the categorical variables should be omitted
2658 from the calculation.
2659
2660 @subsection Example Means
2661
2662 The dataset in @file{repairs.sav} contains the mean time between failures (@exvar{mtbf})
2663 for a sample of artifacts produced by different factories and trialed under
2664 different operating conditions.
2665 Since there are four combinations of categorical variables, by simply looking
2666 at the list of data, it would be hard to how the scores vary for each category.
2667 @ref{means:ex} shows one way of tabulating the @exvar{mtbf} in a way which is
2668 easier to understand.
2669
2670 @float Example, means:ex
2671 @psppsyntax {means.sps}
2672 @caption {Running @cmd{MEANS} on the @exvar{mtbf} score with categories @exvar{factory} and @exvar{environment}}
2673 @end float
2674
2675 The results are shown in @ref{means:res}.   The figures shown indicate the mean,
2676 standard deviation and number of samples in each category.
2677 These figures however do not indicate whether the results are statistically
2678 significant.  For that, you would need to use the procedures @cmd{ONEWAY}, @cmd{GLM} or
2679 @cmd{T-TEST} depending on the hypothesis being tested.
2680
2681 @float Result, means:res
2682 @psppoutput {means}
2683 @caption {The @exvar{mtbf} categorised by @exvar{factory} and @exvar{environment}}
2684 @end float
2685
2686 Note that there is no limit to the number of variables for which you can calculate
2687 statistics, nor to the number of categorical variables per layer, nor the number
2688 of layers.
2689 However, running @cmd{MEANS} on a large numbers of variables, or with categorical variables
2690 containing a large number of distinct values may result in an extremely large output, which
2691 will not be easy to interpret.
2692 So you should consider carefully which variables to select for participation in the analysis.
2693
2694 @node NPAR TESTS
2695 @section NPAR TESTS
2696
2697 @vindex NPAR TESTS
2698 @cindex nonparametric tests
2699
2700 @display
2701 NPAR TESTS
2702
2703      nonparametric test subcommands
2704      .
2705      .
2706      .
2707
2708      [ /STATISTICS=@{DESCRIPTIVES@} ]
2709
2710      [ /MISSING=@{ANALYSIS, LISTWISE@} @{INCLUDE, EXCLUDE@} ]
2711
2712      [ /METHOD=EXACT [ TIMER [(@var{n})] ] ]
2713 @end display
2714
2715 @cmd{NPAR TESTS} performs nonparametric tests.
2716 Non parametric tests make very few assumptions about the distribution of the
2717 data.
2718 One or more tests may be specified by using the corresponding subcommand.
2719 If the @subcmd{/STATISTICS} subcommand is also specified, then summary statistics are
2720 produces for each variable that is the subject of any test.
2721
2722 Certain tests may take a long time to execute, if an exact figure is required.
2723 Therefore, by default asymptotic approximations are used unless the
2724 subcommand @subcmd{/METHOD=EXACT} is specified.
2725 Exact tests give more accurate results, but may take an unacceptably long
2726 time to perform.  If the @subcmd{TIMER} keyword is used, it sets a maximum time,
2727 after which the test is abandoned, and a warning message printed.
2728 The time, in minutes, should be specified in parentheses after the @subcmd{TIMER} keyword.
2729 If the @subcmd{TIMER} keyword is given without this figure, then a default value of 5 minutes
2730 is used.
2731
2732
2733 @menu
2734 * BINOMIAL::                Binomial Test
2735 * CHISQUARE::               Chi-square Test
2736 * COCHRAN::                 Cochran Q Test
2737 * FRIEDMAN::                Friedman Test
2738 * KENDALL::                 Kendall's W Test
2739 * KOLMOGOROV-SMIRNOV::      Kolmogorov Smirnov Test
2740 * KRUSKAL-WALLIS::          Kruskal-Wallis Test
2741 * MANN-WHITNEY::            Mann Whitney U Test
2742 * MCNEMAR::                 McNemar Test
2743 * MEDIAN::                  Median Test
2744 * RUNS::                    Runs Test
2745 * SIGN::                    The Sign Test
2746 * WILCOXON::                Wilcoxon Signed Ranks Test
2747 @end menu
2748
2749
2750 @node    BINOMIAL
2751 @subsection Binomial test
2752 @vindex BINOMIAL
2753 @cindex binomial test
2754
2755 @display
2756      [ /BINOMIAL[(@var{p})]=@var{var_list}[(@var{value1}[, @var{value2})] ] ]
2757 @end display
2758
2759 The @subcmd{/BINOMIAL} subcommand compares the observed distribution of a dichotomous
2760 variable with that of a binomial distribution.
2761 The variable @var{p} specifies the test proportion of the binomial
2762 distribution.
2763 The default value of 0.5 is assumed if @var{p} is omitted.
2764
2765 If a single value appears after the variable list, then that value is
2766 used as the threshold to partition the observed values. Values less
2767 than or equal to the threshold value form the first category.  Values
2768 greater than the threshold form the second category.
2769
2770 If two values appear after the variable list, then they are used
2771 as the values which a variable must take to be in the respective
2772 category.
2773 Cases for which a variable takes a value equal to neither of the specified
2774 values, take no part in the test for that variable.
2775
2776 If no values appear, then the variable must assume dichotomous
2777 values.
2778 If more than two distinct, non-missing values for a variable
2779 under test are encountered then an error occurs.
2780
2781 If the test proportion is equal to 0.5, then a two tailed test is
2782 reported.   For any other test proportion, a one tailed test is
2783 reported.
2784 For one tailed tests, if the test proportion is less than
2785 or equal to the observed proportion, then the significance of
2786 observing the observed proportion or more is reported.
2787 If the test proportion is more than the observed proportion, then the
2788 significance of observing the observed proportion or less is reported.
2789 That is to say, the test is always performed in the observed
2790 direction.
2791
2792 @pspp{} uses a very precise approximation to the gamma function to
2793 compute the binomial significance.  Thus, exact results are reported
2794 even for very large sample sizes.
2795
2796
2797 @node    CHISQUARE
2798 @subsection Chi-square Test
2799 @vindex CHISQUARE
2800 @cindex chi-square test
2801
2802
2803 @display
2804      [ /CHISQUARE=@var{var_list}[(@var{lo},@var{hi})] [/EXPECTED=@{EQUAL|@var{f1}, @var{f2} @dots{} @var{fn}@}] ]
2805 @end display
2806
2807
2808 The @subcmd{/CHISQUARE} subcommand produces a chi-square statistic for the differences
2809 between the expected and observed frequencies of the categories of a variable.
2810 Optionally, a range of values may appear after the variable list.
2811 If a range is given, then non integer values are truncated, and values
2812 outside the  specified range are excluded from the analysis.
2813
2814 The @subcmd{/EXPECTED} subcommand specifies the expected values of each
2815 category.
2816 There must be exactly one non-zero expected value, for each observed
2817 category, or the @subcmd{EQUAL} keyword must be specified.
2818 You may use the notation @subcmd{@var{n}*@var{f}} to specify @var{n}
2819 consecutive expected categories all taking a frequency of @var{f}.
2820 The frequencies given are proportions, not absolute frequencies.  The
2821 sum of the frequencies need not be 1.
2822 If no @subcmd{/EXPECTED} subcommand is given, then equal frequencies
2823 are expected.
2824
2825 @subsubsection Chi-square Example
2826
2827 A researcher wishes to investigate whether there are an equal number of
2828 persons of each sex in a population.   The sample chosen for invesigation
2829 is that from the @file {physiology.sav} dataset.   The null hypothesis for
2830 the test is that the population comprises an equal number of males and females.
2831 The analysis is performed as shown in @ref{chisquare:ex}.
2832
2833 @float Example, chisquare:ex
2834 @psppsyntax {chisquare.sps}
2835 @caption {Performing a chi-square test to check for equal distribution of sexes}
2836 @end float
2837
2838 There is only one test variable, @i{viz:} @exvar{sex}.  The other variables in the dataset
2839 are ignored.
2840
2841 @float Screenshot, chisquare:scr
2842 @psppimage {chisquare}
2843 @caption {Performing a chi-square test using the graphic user interface}
2844 @end float
2845
2846 In @ref{chisquare:res} the summary box shows that in the sample, there are more males
2847 than females.  However the significance of chi-square result is greater than 0.05
2848 --- the most commonly accepted p-value --- and therefore
2849 there is not enough evidence to reject the null hypothesis and one must conclude
2850 that the evidence does not indicate that there is an imbalance of the sexes
2851 in the population.
2852
2853 @float Result, chisquare:res
2854 @psppoutput {chisquare}
2855 @caption {The results of running a chi-square test on @exvar{sex}}
2856 @end float
2857
2858
2859 @node COCHRAN
2860 @subsection Cochran Q Test
2861 @vindex Cochran
2862 @cindex Cochran Q test
2863 @cindex Q, Cochran Q
2864
2865 @display
2866      [ /COCHRAN = @var{var_list} ]
2867 @end display
2868
2869 The Cochran Q test is used to test for differences between three or more groups.
2870 The data for @var{var_list} in all cases must assume exactly two
2871 distinct values (other than missing values).
2872
2873 The value of Q is displayed along with its Asymptotic significance
2874 based on a chi-square distribution.
2875
2876 @node FRIEDMAN
2877 @subsection Friedman Test
2878 @vindex FRIEDMAN
2879 @cindex Friedman test
2880
2881 @display
2882      [ /FRIEDMAN = @var{var_list} ]
2883 @end display
2884
2885 The Friedman test is used to test for differences between repeated measures when
2886 there is no indication that the distributions are normally distributed.
2887
2888 A list of variables which contain the measured data must be given.  The procedure
2889 prints the sum of ranks for each variable, the test statistic and its significance.
2890
2891 @node KENDALL
2892 @subsection Kendall's W Test
2893 @vindex KENDALL
2894 @cindex Kendall's W test
2895 @cindex coefficient of concordance
2896
2897 @display
2898      [ /KENDALL = @var{var_list} ]
2899 @end display
2900
2901 The Kendall test investigates whether an arbitrary number of related samples come from the
2902 same population.
2903 It is identical to the Friedman test except that the additional statistic W, Kendall's Coefficient of Concordance is printed.
2904 It has the range [0,1] --- a value of zero indicates no agreement between the samples whereas a value of
2905 unity indicates complete agreement.
2906
2907
2908 @node KOLMOGOROV-SMIRNOV
2909 @subsection Kolmogorov-Smirnov Test
2910 @vindex KOLMOGOROV-SMIRNOV
2911 @vindex K-S
2912 @cindex Kolmogorov-Smirnov test
2913
2914 @display
2915      [ /KOLMOGOROV-SMIRNOV (@{NORMAL [@var{mu}, @var{sigma}], UNIFORM [@var{min}, @var{max}], POISSON [@var{lambda}], EXPONENTIAL [@var{scale}] @}) = @var{var_list} ]
2916 @end display
2917
2918 The one sample Kolmogorov-Smirnov subcommand is used to test whether or not a dataset is
2919 drawn from a particular distribution.  Four distributions are supported, @i{viz:}
2920 Normal, Uniform, Poisson and Exponential.
2921
2922 Ideally you should provide the parameters of the distribution against
2923 which you wish to test the data. For example, with the normal
2924 distribution  the mean (@var{mu})and standard deviation (@var{sigma})
2925 should be given; with the uniform distribution, the minimum
2926 (@var{min})and maximum (@var{max}) value should be provided.
2927 However, if the parameters are omitted they are imputed from the
2928 data.  Imputing the parameters reduces the power of the test so should
2929 be avoided if possible.
2930
2931 In the following example, two variables @var{score} and @var{age} are
2932 tested to see if they follow a normal distribution with a mean of 3.5
2933 and a standard deviation of 2.0.
2934 @example
2935   NPAR TESTS
2936         /KOLMOGOROV-SMIRNOV (normal 3.5 2.0) = @var{score} @var{age}.
2937 @end example
2938 If the variables need to be tested against different distributions, then a separate
2939 subcommand must be used.  For example the following syntax tests @var{score} against
2940 a normal distribution with mean of 3.5 and standard deviation of 2.0 whilst @var{age}
2941 is tested against a normal distribution of mean 40 and standard deviation 1.5.
2942 @example
2943   NPAR TESTS
2944         /KOLMOGOROV-SMIRNOV (normal 3.5 2.0) = @var{score}
2945         /KOLMOGOROV-SMIRNOV (normal 40 1.5) =  @var{age}.
2946 @end example
2947
2948 The abbreviated subcommand  @subcmd{K-S} may be used in place of @subcmd{KOLMOGOROV-SMIRNOV}.
2949
2950 @node KRUSKAL-WALLIS
2951 @subsection Kruskal-Wallis Test
2952 @vindex KRUSKAL-WALLIS
2953 @vindex K-W
2954 @cindex Kruskal-Wallis test
2955
2956 @display
2957      [ /KRUSKAL-WALLIS = @var{var_list} BY var (@var{lower}, @var{upper}) ]
2958 @end display
2959
2960 The Kruskal-Wallis test is used to compare data from an
2961 arbitrary number of populations.  It does not assume normality.
2962 The data to be compared are specified by @var{var_list}.
2963 The categorical variable determining the groups to which the
2964 data belongs is given by @var{var}. The limits @var{lower} and
2965 @var{upper} specify the valid range of @var{var}.
2966 If @var{upper} is smaller than @var{lower}, the PSPP will assume their values
2967 to be reversed. Any cases for which @var{var} falls outside
2968 [@var{lower}, @var{upper}] are ignored.
2969
2970 The mean rank of each group as well as the chi-squared value and
2971 significance of the test are printed.
2972 The abbreviated subcommand  @subcmd{K-W} may be used in place of
2973 @subcmd{KRUSKAL-WALLIS}.
2974
2975
2976 @node MANN-WHITNEY
2977 @subsection Mann-Whitney U Test
2978 @vindex MANN-WHITNEY
2979 @vindex M-W
2980 @cindex Mann-Whitney U test
2981 @cindex U, Mann-Whitney U
2982
2983 @display
2984      [ /MANN-WHITNEY = @var{var_list} BY var (@var{group1}, @var{group2}) ]
2985 @end display
2986
2987 The Mann-Whitney subcommand is used to test whether two groups of data
2988 come from different populations. The variables to be tested should be
2989 specified in @var{var_list} and the grouping variable, that determines
2990 to which group the test variables belong, in @var{var}.
2991 @var{Var} may be either a string or an alpha variable.
2992 @var{Group1} and @var{group2} specify the
2993 two values of @var{var} which determine the groups of the test data.
2994 Cases for which the @var{var} value is neither @var{group1} or
2995 @var{group2} are ignored.
2996
2997 The value of the Mann-Whitney U statistic, the Wilcoxon W, and the
2998 significance are printed.
2999 You may abbreviated the subcommand @subcmd{MANN-WHITNEY} to
3000 @subcmd{M-W}.
3001
3002
3003 @node MCNEMAR
3004 @subsection McNemar Test
3005 @vindex MCNEMAR
3006 @cindex McNemar test
3007
3008 @display
3009      [ /MCNEMAR @var{var_list} [ WITH @var{var_list} [ (PAIRED) ]]]
3010 @end display
3011
3012 Use McNemar's test to analyse the significance of the difference between
3013 pairs of correlated proportions.
3014
3015 If the @code{WITH} keyword is omitted, then tests for all
3016 combinations of the listed variables are performed.
3017 If the @code{WITH} keyword is given, and the @code{(PAIRED)} keyword
3018 is also given, then the number of variables preceding @code{WITH}
3019 must be the same as the number following it.
3020 In this case, tests for each respective pair of variables are
3021 performed.
3022 If the @code{WITH} keyword is given, but the
3023 @code{(PAIRED)} keyword is omitted, then tests for each combination
3024 of variable preceding @code{WITH} against variable following
3025 @code{WITH} are performed.
3026
3027 The data in each variable must be dichotomous.  If there are more
3028 than two distinct variables an error will occur and the test will
3029 not be run.
3030
3031 @node MEDIAN
3032 @subsection Median Test
3033 @vindex MEDIAN
3034 @cindex Median test
3035
3036 @display
3037      [ /MEDIAN [(@var{value})] = @var{var_list} BY @var{variable} (@var{value1}, @var{value2}) ]
3038 @end display
3039
3040 The median test is used to test whether independent samples come from
3041 populations with a common median.
3042 The median of the populations against which the samples are to be tested
3043 may be given in parentheses immediately after the
3044 @subcmd{/MEDIAN} subcommand.  If it is not given, the median is imputed from the
3045 union of all the samples.
3046
3047 The variables of the samples to be tested should immediately follow the @samp{=} sign. The
3048 keyword @code{BY} must come next, and then the grouping variable.  Two values
3049 in parentheses should follow.  If the first value is greater than the second,
3050 then a 2 sample test is performed using these two values to determine the groups.
3051 If however, the first variable is less than the second, then a @i{k} sample test is
3052 conducted and the group values used are all values encountered which lie in the
3053 range [@var{value1},@var{value2}].
3054
3055
3056 @node RUNS
3057 @subsection Runs Test
3058 @vindex RUNS
3059 @cindex runs test
3060
3061 @display
3062      [ /RUNS (@{MEAN, MEDIAN, MODE, @var{value}@})  = @var{var_list} ]
3063 @end display
3064
3065 The @subcmd{/RUNS} subcommand tests whether a data sequence is randomly ordered.
3066
3067 It works by examining the number of times a variable's value crosses a given threshold.
3068 The desired threshold must be specified within parentheses.
3069 It may either be specified as a number or as one of @subcmd{MEAN}, @subcmd{MEDIAN} or @subcmd{MODE}.
3070 Following the threshold specification comes the list of variables whose values are to be
3071 tested.
3072
3073 The subcommand shows the number of runs, the asymptotic significance based on the
3074 length of the data.
3075
3076 @node SIGN
3077 @subsection Sign Test
3078 @vindex SIGN
3079 @cindex sign test
3080
3081 @display
3082      [ /SIGN @var{var_list} [ WITH @var{var_list} [ (PAIRED) ]]]
3083 @end display
3084
3085 The @subcmd{/SIGN} subcommand tests for differences between medians of the
3086 variables listed.
3087 The test does not make any assumptions about the
3088 distribution of the data.
3089
3090 If the @code{WITH} keyword is omitted, then tests for all
3091 combinations of the listed variables are performed.
3092 If the @code{WITH} keyword is given, and the @code{(PAIRED)} keyword
3093 is also given, then the number of variables preceding @code{WITH}
3094 must be the same as the number following it.
3095 In this case, tests for each respective pair of variables are
3096 performed.
3097 If the @code{WITH} keyword is given, but the
3098 @code{(PAIRED)} keyword is omitted, then tests for each combination
3099 of variable preceding @code{WITH} against variable following
3100 @code{WITH} are performed.
3101
3102 @node WILCOXON
3103 @subsection Wilcoxon Matched Pairs Signed Ranks Test
3104 @vindex WILCOXON
3105 @cindex wilcoxon matched pairs signed ranks test
3106
3107 @display
3108      [ /WILCOXON @var{var_list} [ WITH @var{var_list} [ (PAIRED) ]]]
3109 @end display
3110
3111 The @subcmd{/WILCOXON} subcommand tests for differences between medians of the
3112 variables listed.
3113 The test does not make any assumptions about the variances of the samples.
3114 It does however assume that the distribution is symmetrical.
3115
3116 If the @subcmd{WITH} keyword is omitted, then tests for all
3117 combinations of the listed variables are performed.
3118 If the @subcmd{WITH} keyword is given, and the @subcmd{(PAIRED)} keyword
3119 is also given, then the number of variables preceding @subcmd{WITH}
3120 must be the same as the number following it.
3121 In this case, tests for each respective pair of variables are
3122 performed.
3123 If the @subcmd{WITH} keyword is given, but the
3124 @subcmd{(PAIRED)} keyword is omitted, then tests for each combination
3125 of variable preceding @subcmd{WITH} against variable following
3126 @subcmd{WITH} are performed.
3127
3128 @node T-TEST
3129 @section T-TEST
3130
3131 @vindex T-TEST
3132
3133 @display
3134 T-TEST
3135         /MISSING=@{ANALYSIS,LISTWISE@} @{EXCLUDE,INCLUDE@}
3136         /CRITERIA=CI(@var{confidence})
3137
3138
3139 (One Sample mode.)
3140         TESTVAL=@var{test_value}
3141         /VARIABLES=@var{var_list}
3142
3143
3144 (Independent Samples mode.)
3145         GROUPS=var(@var{value1} [, @var{value2}])
3146         /VARIABLES=@var{var_list}
3147
3148
3149 (Paired Samples mode.)
3150         PAIRS=@var{var_list} [WITH @var{var_list} [(PAIRED)] ]
3151
3152 @end display
3153
3154
3155 The @cmd{T-TEST} procedure outputs tables used in testing hypotheses about
3156 means.
3157 It operates in one of three modes:
3158 @itemize
3159 @item One Sample mode.
3160 @item Independent Groups mode.
3161 @item Paired mode.
3162 @end itemize
3163
3164 @noindent
3165 Each of these modes are described in more detail below.
3166 There are two optional subcommands which are common to all modes.
3167
3168 The @cmd{/CRITERIA} subcommand tells @pspp{} the confidence interval used
3169 in the tests.  The default value is 0.95.
3170
3171
3172 The @cmd{MISSING} subcommand determines the handling of missing
3173 variables.
3174 If @subcmd{INCLUDE} is set, then user-missing values are included in the
3175 calculations, but system-missing values are not.
3176 If @subcmd{EXCLUDE} is set, which is the default, user-missing
3177 values are excluded as well as system-missing values.
3178 This is the default.
3179
3180 If @subcmd{LISTWISE} is set, then the entire case is excluded from analysis
3181 whenever any variable  specified in the @subcmd{/VARIABLES}, @subcmd{/PAIRS} or
3182 @subcmd{/GROUPS} subcommands contains a missing value.
3183 If @subcmd{ANALYSIS} is set, then missing values are excluded only in the analysis for
3184 which they would be needed. This is the default.
3185
3186
3187 @menu
3188 * One Sample Mode::             Testing against a hypothesized mean
3189 * Independent Samples Mode::    Testing two independent groups for equal mean
3190 * Paired Samples Mode::         Testing two interdependent groups for equal mean
3191 @end menu
3192
3193 @node One Sample Mode
3194 @subsection One Sample Mode
3195
3196 The @subcmd{TESTVAL} subcommand invokes the One Sample mode.
3197 This mode is used to test a population mean against a hypothesized
3198 mean.
3199 The value given to the @subcmd{TESTVAL} subcommand is the value against
3200 which you wish to test.
3201 In this mode, you must also use the @subcmd{/VARIABLES} subcommand to
3202 tell @pspp{} which variables you wish to test.
3203
3204 @subsubsection Example - One Sample T-test
3205
3206 A researcher wishes to know whether the weight of persons in a population
3207 is different from the national average.
3208 The samples are drawn from the population under investigation and recorded
3209 in the file @file{physiology.sav}.
3210 From the Department of Health, she
3211 knows that the national average weight of healthy adults is 76.8kg.
3212 Accordingly the @subcmd{TESTVAL} is set to 76.8.
3213 The null hypothesis therefore is that the mean average weight of the
3214 population from which the sample was drawn is 76.8kg.
3215
3216 As previously noted (@pxref{Identifying incorrect data}), one
3217 sample in the dataset contains a weight value
3218 which is clearly incorrect.  So this is excluded from the analysis
3219 using the @cmd{SELECT} command.
3220
3221 @float Example, one-sample-t:ex
3222 @psppsyntax {one-sample-t.sps}
3223 @caption {Running a one sample T-Test after excluding all non-positive values}
3224 @end float
3225
3226 @float Screenshot, one-sample-t:scr
3227 @psppimage {one-sample-t}
3228 @caption {Using the One Sample T-Test dialog box to test @exvar{weight} for a mean of 76.8kg}
3229 @end float
3230
3231
3232 @ref{one-sample-t:res} shows that the mean of our sample differs from the test value
3233 by -1.40kg.  However the significance is very high (0.610).  So one cannot
3234 reject the null hypothesis, and must conclude there is not enough evidence
3235 to suggest that the mean weight of the persons in our population is different
3236 from 76.8kg.
3237
3238 @float Results, one-sample-t:res
3239 @psppoutput {one-sample-t}
3240 @caption {The results of a one sample T-test of @exvar{weight} using a test value of 76.8kg}
3241 @end float
3242
3243 @node Independent Samples Mode
3244 @subsection Independent Samples Mode
3245
3246 The @subcmd{GROUPS} subcommand invokes Independent Samples mode or
3247 `Groups' mode.
3248 This mode is used to test whether two groups of values have the
3249 same population mean.
3250 In this mode, you must also use the @subcmd{/VARIABLES} subcommand to
3251 tell @pspp{} the dependent variables you wish to test.
3252
3253 The variable given in the @subcmd{GROUPS} subcommand is the independent
3254 variable which determines to which group the samples belong.
3255 The values in parentheses are the specific values of the independent
3256 variable for each group.
3257 If the parentheses are omitted and no values are given, the default values
3258 of 1.0 and 2.0 are assumed.
3259
3260 If the independent variable is numeric,
3261 it is acceptable to specify only one value inside the parentheses.
3262 If you do this, cases where the independent variable is
3263 greater than or equal to this value belong to the first group, and cases
3264 less than this value belong to the second group.
3265 When using this form of the @subcmd{GROUPS} subcommand, missing values in
3266 the independent variable are excluded on a listwise basis, regardless
3267 of whether @subcmd{/MISSING=LISTWISE} was specified.
3268
3269 @subsubsection Example - Independent Samples T-test
3270
3271 A researcher wishes to know whether within a population, adult males
3272 are taller than adult females.
3273 The samples are drawn from the population under investigation and recorded
3274 in the file @file{physiology.sav}.
3275
3276 As previously noted (@pxref{Identifying incorrect data}), one
3277 sample in the dataset contains a height value
3278 which is clearly incorrect.  So this is excluded from the analysis
3279 using the @cmd{SELECT} command.
3280
3281
3282 @float Example, indepdendent-samples-t:ex
3283 @psppsyntax {independent-samples-t.sps}
3284 @caption {Running a independent samples T-Test after excluding all observations less than 200kg}
3285 @end float
3286
3287
3288 The null hypothesis is that both males and females are on average
3289 of equal height.
3290
3291 @float Screenshot, independent-samples-t:scr
3292 @psppimage {independent-samples-t}
3293 @caption {Using the Independent Sample T-test dialog, to test for differences of @exvar{height} between values of @exvar{sex}}
3294 @end float
3295
3296
3297 In this case, the grouping variable is @exvar{sex}, so this is entered
3298 as the variable for the @subcmd{GROUP} subcommand.  The group values are  0 (male) and
3299 1 (female).
3300
3301 If you are running the proceedure using syntax, then you need to enter
3302 the values corresponding to each group within parentheses.
3303 If you are using the graphic user interface, then you have to open
3304 the ``Define Groups'' dialog box and enter the values corresponding
3305 to each group as shown in @ref{define-groups-t:scr}.  If, as in this case, the dataset has defined value
3306 labels for the group variable, then you can enter them by label
3307 or by value.
3308
3309 @float Screenshot, define-groups-t:scr
3310 @psppimage {define-groups-t}
3311 @caption {Setting the values of the grouping variable for an Independent Samples T-test}
3312 @end float
3313
3314 From @ref{independent-samples-t:res}, one can clearly see that the @emph{sample} mean height
3315 is greater for males than for females.  However in order to see if this
3316 is a significant result, one must consult the T-Test table.
3317
3318 The T-Test table contains two rows; one for use if the variance of the samples
3319 in each group may be safely assumed to be equal, and the second row
3320 if the variances in each group may not be safely assumed to be equal.
3321
3322 In this case however, both rows show a 2-tailed significance less than 0.001 and
3323 one must therefore reject the null hypothesis and conclude that within
3324 the population the mean height of males and of females are unequal.
3325
3326 @float Result, independent-samples-t:res
3327 @psppoutput {independent-samples-t}
3328 @caption {The results of an independent samples T-test of @exvar{height} by @exvar{sex}}
3329 @end float
3330
3331 @node Paired Samples Mode
3332 @subsection Paired Samples Mode
3333
3334 The @cmd{PAIRS} subcommand introduces Paired Samples mode.
3335 Use this mode when repeated measures have been taken from the same
3336 samples.
3337 If the @subcmd{WITH} keyword is omitted, then tables for all
3338 combinations of variables given in the @cmd{PAIRS} subcommand are
3339 generated.
3340 If the @subcmd{WITH} keyword is given, and the @subcmd{(PAIRED)} keyword
3341 is also given, then the number of variables preceding @subcmd{WITH}
3342 must be the same as the number following it.
3343 In this case, tables for each respective pair of variables are
3344 generated.
3345 In the event that the @subcmd{WITH} keyword is given, but the
3346 @subcmd{(PAIRED)} keyword is omitted, then tables for each combination
3347 of variable preceding @subcmd{WITH} against variable following
3348 @subcmd{WITH} are generated.
3349
3350
3351 @node ONEWAY
3352 @section ONEWAY
3353
3354 @vindex ONEWAY
3355 @cindex analysis of variance
3356 @cindex ANOVA
3357
3358 @display
3359 ONEWAY
3360         [/VARIABLES = ] @var{var_list} BY @var{var}
3361         /MISSING=@{ANALYSIS,LISTWISE@} @{EXCLUDE,INCLUDE@}
3362         /CONTRAST= @var{value1} [, @var{value2}] ... [,@var{valueN}]
3363         /STATISTICS=@{DESCRIPTIVES,HOMOGENEITY@}
3364         /POSTHOC=@{BONFERRONI, GH, LSD, SCHEFFE, SIDAK, TUKEY, ALPHA ([@var{value}])@}
3365 @end display
3366
3367 The @cmd{ONEWAY} procedure performs a one-way analysis of variance of
3368 variables factored by a single independent variable.
3369 It is used to compare the means of a population
3370 divided into more than two groups.
3371
3372 The dependent variables to be analysed should be given in the @subcmd{VARIABLES}
3373 subcommand.
3374 The list of variables must be followed by the @subcmd{BY} keyword and
3375 the name of the independent (or factor) variable.
3376
3377 You can use the @subcmd{STATISTICS} subcommand to tell @pspp{} to display
3378 ancillary information.  The options accepted are:
3379 @itemize
3380 @item DESCRIPTIVES
3381 Displays descriptive statistics about the groups factored by the independent
3382 variable.
3383 @item HOMOGENEITY
3384 Displays the Levene test of Homogeneity of Variance for the
3385 variables and their groups.
3386 @end itemize
3387
3388 The @subcmd{CONTRAST} subcommand is used when you anticipate certain
3389 differences between the groups.
3390 The subcommand must be followed by a list of numerals which are the
3391 coefficients of the groups to be tested.
3392 The number of coefficients must correspond to the number of distinct
3393 groups (or values of the independent variable).
3394 If the total sum of the coefficients are not zero, then @pspp{} will
3395 display a warning, but will proceed with the analysis.
3396 The @subcmd{CONTRAST} subcommand may be given up to 10 times in order
3397 to specify different contrast tests.
3398 The @subcmd{MISSING} subcommand defines how missing values are handled.
3399 If @subcmd{LISTWISE} is specified then cases which have missing values for
3400 the independent variable or any dependent variable are ignored.
3401 If @subcmd{ANALYSIS} is specified, then cases are ignored if the independent
3402 variable is missing or if the dependent variable currently being
3403 analysed is missing.  The default is @subcmd{ANALYSIS}.
3404 A setting of @subcmd{EXCLUDE} means that variables whose values are
3405 user-missing are to be excluded from the analysis. A setting of
3406 @subcmd{INCLUDE} means they are to be included.  The default is @subcmd{EXCLUDE}.
3407
3408 Using the @code{POSTHOC} subcommand you can perform multiple
3409 pairwise comparisons on the data. The following comparison methods
3410 are available:
3411 @itemize
3412 @item @subcmd{LSD}
3413 Least Significant Difference.
3414 @item @subcmd{TUKEY}
3415 Tukey Honestly Significant Difference.
3416 @item @subcmd{BONFERRONI}
3417 Bonferroni test.
3418 @item @subcmd{SCHEFFE}
3419 Scheff@'e's test.
3420 @item @subcmd{SIDAK}
3421 Sidak test.
3422 @item @subcmd{GH}
3423 The Games-Howell test.
3424 @end itemize
3425
3426 @noindent
3427 Use the optional syntax @code{ALPHA(@var{value})} to indicate that
3428 @cmd{ONEWAY} should perform the posthoc tests at a confidence level of
3429 @var{value}.  If @code{ALPHA(@var{value})} is not specified, then the
3430 confidence level used is 0.05.
3431
3432 @node QUICK CLUSTER
3433 @section QUICK CLUSTER
3434 @vindex QUICK CLUSTER
3435
3436 @cindex K-means clustering
3437 @cindex clustering
3438
3439 @display
3440 QUICK CLUSTER @var{var_list}
3441       [/CRITERIA=CLUSTERS(@var{k}) [MXITER(@var{max_iter})] CONVERGE(@var{epsilon}) [NOINITIAL]]
3442       [/MISSING=@{EXCLUDE,INCLUDE@} @{LISTWISE, PAIRWISE@}]
3443       [/PRINT=@{INITIAL@} @{CLUSTER@}]
3444       [/SAVE[=[CLUSTER[(@var{membership_var})]] [DISTANCE[(@var{distance_var})]]]
3445 @end display
3446
3447 The @cmd{QUICK CLUSTER} command performs k-means clustering on the
3448 dataset.  This is useful when you wish to allocate cases into clusters
3449 of similar values and you already know the number of clusters.
3450
3451 The minimum specification is @samp{QUICK CLUSTER} followed by the names
3452 of the variables which contain the cluster data.  Normally you will also
3453 want to specify @subcmd{/CRITERIA=CLUSTERS(@var{k})} where @var{k} is the
3454 number of clusters.  If this is not specified, then @var{k} defaults to 2.
3455
3456 If you use @subcmd{/CRITERIA=NOINITIAL} then a naive algorithm to select
3457 the initial clusters is used.   This will provide for faster execution but
3458 less well separated initial clusters and hence possibly an inferior final
3459 result.
3460
3461
3462 @cmd{QUICK CLUSTER} uses an iterative algorithm to select the clusters centers.
3463 The subcommand  @subcmd{/CRITERIA=MXITER(@var{max_iter})} sets the maximum number of iterations.
3464 During classification, @pspp{} will continue iterating until until @var{max_iter}
3465 iterations have been done or the convergence criterion (see below) is fulfilled.
3466 The default value of @var{max_iter} is 2.
3467
3468 If however, you specify @subcmd{/CRITERIA=NOUPDATE} then after selecting the initial centers,
3469 no further update to the cluster centers is done.  In this case, @var{max_iter}, if specified.
3470 is ignored.
3471
3472 The subcommand  @subcmd{/CRITERIA=CONVERGE(@var{epsilon})} is used
3473 to set the convergence criterion.  The value of convergence criterion is  @var{epsilon}
3474 times the minimum distance between the @emph{initial} cluster centers.  Iteration stops when
3475 the  mean cluster distance between  one iteration and the next
3476 is less than the convergence criterion.  The default value of @var{epsilon} is zero.
3477
3478 The @subcmd{MISSING} subcommand determines the handling of missing variables.
3479 If @subcmd{INCLUDE} is set, then user-missing values are considered at their face
3480 value and not as missing values.
3481 If @subcmd{EXCLUDE} is set, which is the default, user-missing
3482 values are excluded as well as system-missing values.
3483
3484 If @subcmd{LISTWISE} is set, then the entire case is excluded from the analysis
3485 whenever any of the clustering variables contains a missing value.
3486 If @subcmd{PAIRWISE} is set, then a case is considered missing only if all the
3487 clustering variables contain missing values.  Otherwise it is clustered
3488 on the basis of the non-missing values.
3489 The default is @subcmd{LISTWISE}.
3490
3491 The @subcmd{PRINT} subcommand requests additional output to be printed.
3492 If @subcmd{INITIAL} is set, then the initial cluster memberships will
3493 be printed.
3494 If @subcmd{CLUSTER} is set, the cluster memberships of the individual
3495 cases are displayed (potentially generating lengthy output).
3496
3497 You can specify the subcommand @subcmd{SAVE} to ask that each case's cluster membership
3498 and the euclidean distance between the case and its cluster center be saved to
3499 a new variable in the active dataset.   To save the cluster membership use the
3500 @subcmd{CLUSTER} keyword and to save the distance use the @subcmd{DISTANCE} keyword.
3501 Each keyword may optionally be followed by a variable name in parentheses to specify
3502 the new variable which is to contain the saved parameter.  If no variable name is specified,
3503 then PSPP will create one.
3504
3505 @node RANK
3506 @section RANK
3507
3508 @vindex RANK
3509 @display
3510 RANK
3511         [VARIABLES=] @var{var_list} [@{A,D@}] [BY @var{var_list}]
3512         /TIES=@{MEAN,LOW,HIGH,CONDENSE@}
3513         /FRACTION=@{BLOM,TUKEY,VW,RANKIT@}
3514         /PRINT[=@{YES,NO@}
3515         /MISSING=@{EXCLUDE,INCLUDE@}
3516
3517         /RANK [INTO @var{var_list}]
3518         /NTILES(k) [INTO @var{var_list}]
3519         /NORMAL [INTO @var{var_list}]
3520         /PERCENT [INTO @var{var_list}]
3521         /RFRACTION [INTO @var{var_list}]
3522         /PROPORTION [INTO @var{var_list}]
3523         /N [INTO @var{var_list}]
3524         /SAVAGE [INTO @var{var_list}]
3525 @end display
3526
3527 The @cmd{RANK} command ranks variables and stores the results into new
3528 variables.
3529
3530 The @subcmd{VARIABLES} subcommand, which is mandatory, specifies one or
3531 more variables whose values are to be ranked.
3532 After each variable, @samp{A} or @samp{D} may appear, indicating that
3533 the variable is to be ranked in ascending or descending order.
3534 Ascending is the default.
3535 If a @subcmd{BY} keyword appears, it should be followed by a list of variables
3536 which are to serve as group variables.
3537 In this case, the cases are gathered into groups, and ranks calculated
3538 for each group.
3539
3540 The @subcmd{TIES} subcommand specifies how tied values are to be treated.  The
3541 default is to take the mean value of all the tied cases.
3542
3543 The @subcmd{FRACTION} subcommand specifies how proportional ranks are to be
3544 calculated.  This only has any effect if @subcmd{NORMAL} or @subcmd{PROPORTIONAL} rank
3545 functions are requested.
3546
3547 The @subcmd{PRINT} subcommand may be used to specify that a summary of the rank
3548 variables created should appear in the output.
3549
3550 The function subcommands are @subcmd{RANK}, @subcmd{NTILES}, @subcmd{NORMAL}, @subcmd{PERCENT}, @subcmd{RFRACTION},
3551 @subcmd{PROPORTION} and @subcmd{SAVAGE}.  Any number of function subcommands may appear.
3552 If none are given, then the default is RANK.
3553 The @subcmd{NTILES} subcommand must take an integer specifying the number of
3554 partitions into which values should be ranked.
3555 Each subcommand may be followed by the @subcmd{INTO} keyword and a list of
3556 variables which are the variables to be created and receive the rank
3557 scores.  There may be as many variables specified as there are
3558 variables named on the @subcmd{VARIABLES} subcommand.  If fewer are specified,
3559 then the variable names are automatically created.
3560
3561 The @subcmd{MISSING} subcommand determines how user missing values are to be
3562 treated. A setting of @subcmd{EXCLUDE} means that variables whose values are
3563 user-missing are to be excluded from the rank scores. A setting of
3564 @subcmd{INCLUDE} means they are to be included.  The default is @subcmd{EXCLUDE}.
3565
3566 @include regression.texi
3567
3568
3569 @node RELIABILITY
3570 @section RELIABILITY
3571
3572 @vindex RELIABILITY
3573 @display
3574 RELIABILITY
3575         /VARIABLES=@var{var_list}
3576         /SCALE (@var{name}) = @{@var{var_list}, ALL@}
3577         /MODEL=@{ALPHA, SPLIT[(@var{n})]@}
3578         /SUMMARY=@{TOTAL,ALL@}
3579         /MISSING=@{EXCLUDE,INCLUDE@}
3580 @end display
3581
3582 @cindex Cronbach's Alpha
3583 The @cmd{RELIABILITY} command performs reliability analysis on the data.
3584
3585 The @subcmd{VARIABLES} subcommand is required. It determines the set of variables
3586 upon which analysis is to be performed.
3587
3588 The @subcmd{SCALE} subcommand determines the  variables for which
3589 reliability is to be calculated.  If @subcmd{SCALE} is omitted, then analysis for
3590 all variables named in the @subcmd{VARIABLES} subcommand are used.
3591 Optionally, the @var{name} parameter may be specified to set a string name
3592 for the scale.
3593
3594 The @subcmd{MODEL} subcommand determines the type of analysis. If @subcmd{ALPHA} is specified,
3595 then Cronbach's Alpha is calculated for the scale.  If the model is @subcmd{SPLIT},
3596 then the variables  are divided into 2 subsets.  An optional parameter
3597 @var{n} may be given, to specify how many variables to be in the first subset.
3598 If @var{n} is omitted, then it defaults to one half of the variables in the
3599 scale, or one half minus one if there are an odd number of variables.
3600 The default model is @subcmd{ALPHA}.
3601
3602 By default, any cases with user missing, or system missing values for
3603 any variables given in the @subcmd{VARIABLES} subcommand are omitted
3604 from the analysis.  The @subcmd{MISSING} subcommand determines whether
3605 user missing values are included or excluded in the analysis.
3606
3607 The @subcmd{SUMMARY} subcommand determines the type of summary analysis to be performed.
3608 Currently there is only one type: @subcmd{SUMMARY=TOTAL}, which displays per-item
3609 analysis tested against the totals.
3610
3611 @subsection Example - Reliability
3612
3613 Before analysing the results of a survey -- particularly for a multiple choice survey --
3614 it is desireable to know whether the respondents have considered their answers
3615 or simply provided random answers.
3616
3617 In the following example the survey results from the file @file{hotel.sav} are used.
3618 All five survey questions are included in the reliability analysis.
3619 However, before running the analysis, the data must be preprocessed.
3620 An examination of the survey questions reveals that two questions, @i{viz:} v3 and v5
3621 are negatively worded, whereas the others are positively worded.
3622 All questions must be based upon the same scale for the analysis to be meaningful.
3623 One could use the @cmd{RECODE} command (@pxref{RECODE}), however a simpler way is
3624 to use @cmd{COMPUTE} (@pxref{COMPUTE}) and this is what is done in @ref{reliability:ex}.
3625
3626 @float Example, reliability:ex
3627 @psppsyntax {reliability.sps}
3628 @caption {Investigating the reliability of survey responses}
3629 @end float
3630
3631 In this case, all variables in the data set are used.  So we can use the special
3632 keyword @samp{ALL} (@pxref{BNF}).
3633
3634 @float Screenshot, reliability:src
3635 @psppimage {reliability}
3636 @caption {Reliability dialog box with all variables selected}
3637 @end float
3638
3639 @ref{reliability:res} shows that Cronbach's Alpha is 0.11  which is a value normally considered too
3640 low to indicate consistency within the data.  This is possibly due to the small number of
3641 survey questions.  The survey should be redesigned before serious use of the results are
3642 applied.
3643
3644 @float Result, reliability:res
3645 @psppoutput {reliability}
3646 @caption {The results of the reliability command on @file{hotel.sav}}
3647 @end float
3648
3649
3650 @node ROC
3651 @section ROC
3652
3653 @vindex ROC
3654 @cindex Receiver Operating Characteristic
3655 @cindex Area under curve
3656
3657 @display
3658 ROC     @var{var_list} BY @var{state_var} (@var{state_value})
3659         /PLOT = @{ CURVE [(REFERENCE)], NONE @}
3660         /PRINT = [ SE ] [ COORDINATES ]
3661         /CRITERIA = [ CUTOFF(@{INCLUDE,EXCLUDE@}) ]
3662           [ TESTPOS (@{LARGE,SMALL@}) ]
3663           [ CI (@var{confidence}) ]
3664           [ DISTRIBUTION (@{FREE, NEGEXPO @}) ]
3665         /MISSING=@{EXCLUDE,INCLUDE@}
3666 @end display
3667
3668
3669 The @cmd{ROC} command is used to plot the receiver operating characteristic curve
3670 of a dataset, and to estimate the area under the curve.
3671 This is useful for analysing the efficacy of a variable as a predictor of a state of nature.
3672
3673 The mandatory @var{var_list} is the list of predictor variables.
3674 The variable @var{state_var} is the variable whose values represent the actual states,
3675 and @var{state_value} is the value of this variable which represents the positive state.
3676
3677 The optional subcommand @subcmd{PLOT} is used to determine if and how the @subcmd{ROC} curve is drawn.
3678 The keyword @subcmd{CURVE} means that the @subcmd{ROC} curve should be drawn, and the optional keyword @subcmd{REFERENCE},
3679 which should be enclosed in parentheses, says that the diagonal reference line should be drawn.
3680 If the keyword @subcmd{NONE} is given, then no @subcmd{ROC} curve is drawn.
3681 By default, the curve is drawn with no reference line.
3682
3683 The optional subcommand @subcmd{PRINT} determines which additional
3684 tables should be printed.  Two additional tables are available.  The
3685 @subcmd{SE} keyword says that standard error of the area under the
3686 curve should be printed as well as the area itself.  In addition, a
3687 p-value for the null hypothesis that the area under the curve equals
3688 0.5 is printed.   The @subcmd{COORDINATES} keyword says that a
3689 table of coordinates of the @subcmd{ROC} curve should be printed.
3690
3691 The @subcmd{CRITERIA} subcommand has four optional parameters:
3692 @itemize @bullet
3693 @item The @subcmd{TESTPOS} parameter may be @subcmd{LARGE} or @subcmd{SMALL}.
3694 @subcmd{LARGE} is the default, and says that larger values in the predictor variables are to be
3695 considered positive.  @subcmd{SMALL} indicates that smaller values should be considered positive.
3696
3697 @item The @subcmd{CI} parameter specifies the confidence interval that should be printed.
3698 It has no effect if the @subcmd{SE} keyword in the @subcmd{PRINT} subcommand has not been given.
3699
3700 @item The @subcmd{DISTRIBUTION} parameter determines the method to be used when estimating the area
3701 under the curve.
3702 There are two possibilities, @i{viz}: @subcmd{FREE} and @subcmd{NEGEXPO}.
3703 The @subcmd{FREE} method uses a non-parametric estimate, and the @subcmd{NEGEXPO} method a bi-negative
3704 exponential distribution estimate.
3705 The @subcmd{NEGEXPO} method should only be used when the number of positive actual states is
3706 equal to the number of negative actual states.
3707 The default is @subcmd{FREE}.
3708
3709 @item The @subcmd{CUTOFF} parameter is for compatibility and is ignored.
3710 @end itemize
3711
3712 The @subcmd{MISSING} subcommand determines whether user missing values are to
3713 be included or excluded in the analysis.  The default behaviour is to
3714 exclude them.
3715 Cases are excluded on a listwise basis; if any of the variables in @var{var_list}
3716 or if the variable @var{state_var} is missing, then the entire case is
3717 excluded.
3718
3719 @c  LocalWords:  subcmd subcommand