some basic ctables docs
[pspp] / doc / statistics.texi
index 2ec1bc5dc93cc59d6e55a2c8bab01b35240c0f90..6957b3836eae3a2c07f8bad2f64d30d781db1249 100644 (file)
@@ -20,6 +20,7 @@ far.
 * GRAPH::                       Plot data.
 * CORRELATIONS::                Correlation tables.
 * CROSSTABS::                   Crosstabulation tables.
+* CTABLES::                     Custom tables.
 * FACTOR::                      Factor analysis and Principal Components analysis.
 * GLM::                         Univariate Linear Models.
 * LOGISTIC REGRESSION::         Bivariate Logistic Regression.
@@ -29,7 +30,6 @@ far.
 * ONEWAY::                      One way analysis of variance.
 * QUICK CLUSTER::               K-Means clustering.
 * RANK::                        Compute rank scores.
-* REGRESSION::                  Linear regression.
 * RELIABILITY::                 Reliability analysis.
 * ROC::                         Receiver Operating Characteristic.
 @end menu
@@ -142,6 +142,11 @@ first @cmd{DESCRIPTIVES} command.
 @caption {Running two @cmd{DESCRIPTIVES} commands, one with the @subcmd{SAVE} subcommand}
 @end float
 
+@float Screenshot, descriptives:scr
+@psppimage {descriptives}
+@caption {The Descriptives dialog box with two variables and Z-Scores option selected}
+@end float
+
 In @ref{descriptives:res}, we can see that there are 40 valid data for each of the variables
 and no missing values.   The mean average of the height and temperature is 16677.12
 and 37.02 respectively.  The descriptive statistics for temperature seem reasonable.
@@ -290,6 +295,11 @@ If you are using the graphic user interface, the dialog box is set up such that
 by default, several statistics are calculated.   Some are not particularly useful
 for categorical variables, so you may want to disable those.
 
+@float Screenshot, frequencies:scr
+@psppimage {frequencies}
+@caption {The frequencies dialog box with the @exvar{sex} and @exvar{occupation} variables selected}
+@end float
+
 From @ref{frequencies:res} it is evident that there are 33 males, 21 females and
 2 persons for whom their sex has not been entered.
 
@@ -503,9 +513,9 @@ The @cmd{GRAPH} command produces graphical plots of data. Only one of the subcom
 can be produced per call of @cmd{GRAPH}. The @subcmd{MISSING} is optional.
 
 @menu
-* SCATTERPLOT::             Cartesian Plots
-* HISTOGRAM::               Histograms
-* BAR CHART::               Bar Charts
+* SCATTERPLOT::                 Cartesian Plots
+* HISTOGRAM::                   Histograms
+* BAR CHART::                   Bar Charts
 @end menu
 
 @node SCATTERPLOT
@@ -668,12 +678,8 @@ The keyword @subcmd{ALL} is the union of @subcmd{DESCRIPTIVES} and @subcmd{XPROD
 CROSSTABS
         /TABLES=@var{var_list} BY @var{var_list} [BY @var{var_list}]@dots{}
         /MISSING=@{TABLE,INCLUDE,REPORT@}
-        /WRITE=@{NONE,CELLS,ALL@}
         /FORMAT=@{TABLES,NOTABLES@}
-                @{PIVOT,NOPIVOT@}
                 @{AVALUE,DVALUE@}
-                @{NOINDEX,INDEX@}
-                @{BOX,NOBOX@}
         /CELLS=@{COUNT,ROW,COLUMN,TOTAL,EXPECTED,RESIDUAL,SRESIDUAL,
                 ASRESIDUAL,ALL,NONE@}
         /COUNT=@{ASIS,CASE,CELL@}
@@ -718,8 +724,6 @@ tables and statistics.  When set to @subcmd{REPORT}, which is allowed only in
 integer mode, user-missing values are included in tables but marked with
 a footnote and excluded from statistical calculations.
 
-Currently the @subcmd{WRITE} subcommand is ignored.
-
 The @subcmd{FORMAT} subcommand controls the characteristics of the
 crosstabulation tables to be displayed.  It has a number of possible
 settings:
@@ -727,22 +731,11 @@ settings:
 @itemize @w{}
 @item
 @subcmd{TABLES}, the default, causes crosstabulation tables to be output.
-@subcmd{NOTABLES} suppresses them.
-
-@item
-@subcmd{PIVOT}, the default, causes each @subcmd{TABLES} subcommand to be displayed in a
-pivot table format.  @subcmd{NOPIVOT} causes the old-style crosstabulation format
-to be used.
+@subcmd{NOTABLES}, which is equivalent to @code{CELLS=NONE}, suppresses them.
 
 @item
 @subcmd{AVALUE}, the default, causes values to be sorted in ascending order.
 @subcmd{DVALUE} asserts a descending sort order.
-
-@item
-@subcmd{INDEX} and @subcmd{NOINDEX} are currently ignored.
-
-@item
-@subcmd{BOX} and @subcmd{NOBOX} is currently ignored.
 @end itemize
 
 The @subcmd{CELLS} subcommand controls the contents of each cell in the displayed
@@ -852,6 +845,223 @@ Approximate T is not calculated for symmetric uncertainty coefficient.
 
 Fixes for any of these deficiencies would be welcomed.
 
+@subsection Crosstabs Example
+
+@cindex chi-square test of independence
+
+A researcher wishes to know if, in an industry, a person's sex is related to
+the person's occupation.  To investigate this, she has determined that the
+@file{personnel.sav} is a representative, randomly selected sample of persons.
+The researcher's null hypothesis is that a person's sex has no relation to a
+person's occupation. She uses a chi-squared test of independence to investigate
+the hypothesis.
+
+@float Example, crosstabs:ex
+@psppsyntax {crosstabs.sps}
+@caption {Running crosstabs on the @exvar{sex} and @exvar{occupation} variables}
+@end float
+
+The syntax in @ref{crosstabs:ex} conducts a chi-squared test of independence.
+The line @code{/tables = occupation by sex} indicates that @exvar{occupation}
+and @exvar{sex} are the variables to be tabulated.  To do this using the @gui{}
+you must place these variable names respectively in the @samp{Row} and
+@samp{Column} fields as shown in @ref{crosstabs:scr}.
+
+@float Screenshot, crosstabs:scr
+@psppimage {crosstabs}
+@caption {The Crosstabs dialog box with the @exvar{sex} and @exvar{occupation} variables selected}
+@end float
+
+Similarly, the @samp{Cells} button shows a dialog box to select the @code{count}
+and @code{expected} options.  All other cell options can be deselected for this
+test.
+
+You would use the @samp{Format} and @samp{Statistics}  buttons to select options
+for the @subcmd{FORMAT} and @subcmd{STATISTICS} subcommands.  In this example,
+the @samp{Statistics} requires only the @samp{Chisq} option to be checked.  All
+other options should be unchecked.  No special settings are required from the
+@samp{Format} dialog.
+
+As shown in @ref{crosstabs:res} @cmd{CROSSTABS} generates a contingency table
+containing the observed count and the expected count of each sex and each
+occupation.  The expected count is the count which would be observed if the
+null hypothesis were true.
+
+The significance of the Pearson Chi-Square value is very much larger than the
+normally accepted value of 0.05 and so one cannot reject the null hypothesis.
+Thus the researcher must conclude that a person's sex has no relation to the
+person's occupation.
+
+@float Results, crosstabs:res
+@psppoutput {crosstabs}
+@caption {The results of a test of independence between @exvar{sex} and @exvar{occupation}}
+@end float
+
+@node CTABLES
+@section CTABLES
+
+@vindex CTABLES
+@cindex custom tables
+@cindex tables, custom
+
+@code{CTABLES} has the following overall syntax.  At least one
+@code{TABLE} subcommand is required:
+
+@display
+@t{CTABLES}
+  @dots{}@i{global subcommands}@dots{}
+  [@t{/TABLE} @i{axis} [@t{BY} @i{axis} [@t{BY} @i{axis}]]
+   @dots{}@i{per-table subcommands}@dots{}]@dots{}
+@end display
+
+@noindent
+where each @i{axis} may be empty or take one of the following forms:
+
+@display
+@i{variable}
+@i{variable} @t{[}@{@t{C} @math{|} @t{S}@}@t{]}
+@i{axis} + @i{axis}
+@i{axis} > @i{axis}
+(@i{axis})
+@i{axis} @t{(}@i{summary} [@i{string}] [@i{format}]@t{)}
+@end display
+
+The following subcommands precede the first @code{TABLE} subcommand
+and apply to all of the output tables.  All of these subcommands are
+optional:
+
+@display
+@t{/FORMAT}
+    [@t{MINCOLWIDTH=}@{@t{DEFAULT} @math{|} @i{width}@}]
+    [@t{MAXCOLWIDTH=}@{@t{DEFAULT} @math{|} @i{width}@}]
+    [@t{UNITS=}@{@t{POINTS} @math{|} @t{INCHES} @math{|} @t{CM}@}]
+    [@t{EMPTY=}@{@t{ZERO} @math{|} @t{BLANK} @math{|} @i{string}@}]
+    [@t{MISSING=}@i{string}]
+@t{/VLABELS}
+    @t{VARIABLES=}@i{variables}
+    @t{DISPLAY}=@{@t{DEFAULT} @math{|} @t{NAME} @math{|} @t{LABEL} @math{|} @t{BOTH} @math{|} @t{NONE}@}
+@t{/MRSETS COUNTDUPLICATES=}@{@t{YES} @math{|} @t{NO}@}
+@t{/SMISSING} @{@t{VARIABLE} @math{|} @t{LISTWISE}@}
+@t{/PCOMPUTE} @t{&}@i{category}@t{=EXPR(}@i{expression}@t{)}
+@t{/PPROPERTIES} @t{&}@i{category}@dots{}
+    [@t{LABEL=}@i{string}]
+    [@t{FORMAT=}[@i{summary} @i{format}]@dots{}]
+    [@t{HIDESOURCECATS=}@{@t{NO} @math{|} @t{YES}@}
+@t{/WEIGHT VARIABLE=}@i{variable}
+@t{/HIDESMALLCOUNTS COUNT=@i{count}}
+@end display
+
+The following subcommands follow @code{TABLE} and apply only to the
+previous @code{TABLE}.  All of these subcommands are optional:
+
+@display
+@t{/SLABELS}
+    [@t{POSITION=}@{@t{COLUMN} @math{|} @t{ROW} @math{|} @t{LAYER}@}]
+    [@t{VISIBLE=}@{@t{YES} @math{|} @t{NO}@}]
+@t{/CLABELS} @{@t{AUTO} @math{|} @{@t{ROWLABELS}@math{|}@t{COLLABELS}@}@t{=}@{@t{OPPOSITE}@math{|}@t{LAYER}@}@}
+@t{/CRITERIA CILEVEL=}@i{percentage}
+@t{/CATEGORIES} @t{VARIABLES=}@i{variables}
+    @{@t{[}@i{value}@t{,} @i{value}@dots{}@t{]}
+   @math{|} [@t{ORDER=}@{@t{A} @math{|} @t{D}@}]
+     [@t{KEY=}@{@t{VALUE} @math{|} @t{LABEL} @math{|} @i{summary}@t{(}@i{variable}@t{)}@}]
+     [@t{MISSING=}@{@t{EXCLUDE} @math{|} @t{INCLUDE}@}]@}
+    [@t{TOTAL=}@{@t{NO} @math{|} @t{YES}@} [@t{LABEL=}@i{string}] [@t{POSITION=}@{@t{AFTER} @math{|} @t{BEFORE}@}]]
+    [@t{EMPTY=}@{@t{INCLUDE} @math{|} @t{EXCLUDE}@}]
+@t{/TITLES}
+    [@t{TITLE=}@i{string}@dots{}]
+    [@t{CAPTION=}@i{string}@dots{}]
+    [@t{CORNER=}@i{string}@dots{}]
+@t{/SIGTEST TYPE=CHISQUARE}
+    [@t{ALPHA=}@i{siglevel}]
+    [@t{INCLUDEMRSETS=}@{@t{YES} @math{|} @t{NO}@}]
+    [@t{CATEGORIES=}@{@t{ALLVISIBLE} @math{|} @t{SUBTOTALS}@}]
+@t{/COMPARETEST TYPE=}@{@t{PROP} @math{|} @t{MEAN}@}
+    [@t{ALPHA=}@i{value}[@t{,} @i{value}]]
+    [@t{ADJUST=}@{@t{BONFERRONI} @math{|} @t{BH} @math{|} @t{NONE}@}]
+    [@t{INCLUDEMRSETS=}@{@t{YES} @math{|} @t{NO}@}]
+    [@t{MEANSVARIANCE=}@{@t{ALLCATS} @math{|} @t{TESTEDCATS}@}]
+    [@t{CATEGORIES=}@{@t{ALLVISIBLE} @math{|} @t{SUBTOTALS}@}]
+    [@t{MERGE=}@{@t{NO} @math{|} @t{YES}@}]
+    [@t{STYLE=}@{@t{APA} @math{|} @t{SIMPLE}@}]
+    [@t{SHOWSIG=}@{@t{NO} @math{|} @t{YES}@}]
+@end display
+
+The @code{CTABLES} (aka ``custom tables'') command produces
+multi-dimensional tables from categorical and scale data.  It offers
+many options for data summarization and formatting.
+
+This section's examples use data from the 2008 (USA) National Survey
+of Drinking and Driving Attitudes and Behaviors, a public domain data
+set from the (USA) National Highway Traffic Administration and
+available at @url{https://data.transportation.gov}.  @pspp{} includes
+this data set, with a slightly modified dictionary, as
+@file{examples/nhtsa.sav}.
+
+@menu
+* CTABLES Basics::
+@end menu
+
+@node CTABLES Basics
+@subsection Basics
+
+The only required subcommand is @code{TABLE}, which specifies the
+variables to include along each axis:
+@display
+@t{/TABLE} @i{rows} [@t{BY} @i{columns} [@t{BY} @i{layers}]]
+@end display
+@noindent
+In @code{TABLE}, each of @var{rows}, @var{columns}, and @var{layers}
+is either empty or an axis expression that specifies one or more
+variables.  An axis expression that names a categorical variable
+divides the data into cells according to the values of that variable.
+When all the variables named on @code{TABLE} are categorical, by
+default each cell displays the number of cases that it contains, so
+specifying a single variable yields a frequency table:
+
+@example
+CTABLES /TABLE=AgeGroup.
+@end example
+@psppoutput {ctables1}
+
+@noindent
+Specifying a row and a column categorical variable yields a
+crosstabulation:
+
+@example
+CTABLES /TABLE=AgeGroup BY qns3a.
+@end example
+@psppoutput {ctables2}
+
+@noindent
+The @samp{>} operator nests multiple variables on a single axis, e.g.:
+
+@example
+CTABLES /TABLE qn105ba BY AgeGroup > qns3a.
+@end example
+@psppoutput {ctables3}
+
+@noindent
+The @samp{+} operator allows a single output table to include multiple
+data analyses.  With @samp{+}, @code{CTABLES} divides the output table
+into multiple sections, each of which includes an analysis of the full
+data set.  For example, the following command separately tabulates age
+group and driving frequency by gender:
+
+@example
+CTABLES /TABLE AgeGroup + qn1 BY qns3a.
+@end example
+@psppoutput {ctables4}
+
+@noindent
+If @samp{+} and @samp{>} are used together, @samp{>} binds more
+tightly.  Use parentheses to override operator precedence.  Thus:
+
+@example
+CTABLES /TABLE qn26 + qn27 > qns3a.
+CTABLES /TABLE (qn26 + qn27) > qns3a.
+@end example
+@psppoutput {ctables5}
+
 @node FACTOR
 @section FACTOR
 
@@ -1357,19 +1567,19 @@ is used.
 
 
 @menu
-* BINOMIAL::                Binomial Test
-* CHISQUARE::               Chi-square Test
-* COCHRAN::                 Cochran Q Test
-* FRIEDMAN::                Friedman Test
-* KENDALL::                 Kendall's W Test
-* KOLMOGOROV-SMIRNOV::      Kolmogorov Smirnov Test
-* KRUSKAL-WALLIS::          Kruskal-Wallis Test
-* MANN-WHITNEY::            Mann Whitney U Test
-* MCNEMAR::                 McNemar Test
-* MEDIAN::                  Median Test
-* RUNS::                    Runs Test
-* SIGN::                    The Sign Test
-* WILCOXON::                Wilcoxon Signed Ranks Test
+* BINOMIAL::                    Binomial Test
+* CHISQUARE::                   Chi-square Test
+* COCHRAN::                     Cochran Q Test
+* FRIEDMAN::                    Friedman Test
+* KENDALL::                     Kendall's W Test
+* KOLMOGOROV-SMIRNOV::          Kolmogorov Smirnov Test
+* KRUSKAL-WALLIS::              Kruskal-Wallis Test
+* MANN-WHITNEY::                Mann Whitney U Test
+* MCNEMAR::                     McNemar Test
+* MEDIAN::                      Median Test
+* RUNS::                        Runs Test
+* SIGN::                        The Sign Test
+* WILCOXON::                    Wilcoxon Signed Ranks Test
 @end menu
 
 
@@ -1464,6 +1674,11 @@ The analysis is performed as shown in @ref{chisquare:ex}.
 There is only one test variable, @i{viz:} @exvar{sex}.  The other variables in the dataset
 are ignored.
 
+@float Screenshot, chisquare:scr
+@psppimage {chisquare}
+@caption {Performing a chi-square test using the graphic user interface}
+@end float
+
 In @ref{chisquare:res} the summary box shows that in the sample, there are more males
 than females.  However the significance of chi-square result is greater than 0.05
 --- the most commonly accepted p-value --- and therefore
@@ -1583,9 +1798,10 @@ arbitrary number of populations.  It does not assume normality.
 The data to be compared are specified by @var{var_list}.
 The categorical variable determining the groups to which the
 data belongs is given by @var{var}. The limits @var{lower} and
-@var{upper} specify the valid range of @var{var}. Any cases for
-which @var{var} falls outside [@var{lower}, @var{upper}] are
-ignored.
+@var{upper} specify the valid range of @var{var}.
+If @var{upper} is smaller than @var{lower}, the PSPP will assume their values
+to be reversed. Any cases for which @var{var} falls outside
+[@var{lower}, @var{upper}] are ignored.
 
 The mean rank of each group as well as the chi-squared value and
 significance of the test are printed.
@@ -1843,6 +2059,12 @@ using the @cmd{SELECT} command.
 @caption {Running a one sample T-Test after excluding all non-positive values}
 @end float
 
+@float Screenshot, one-sample-t:scr
+@psppimage {one-sample-t}
+@caption {Using the One Sample T-Test dialog box to test @exvar{weight} for a mean of 76.8kg}
+@end float
+
+
 @ref{one-sample-t:res} shows that the mean of our sample differs from the test value
 by -1.40kg.  However the significance is very high (0.610).  So one cannot
 reject the null hypothesis, and must conclude there is not enough evidence
@@ -1902,13 +2124,28 @@ using the @cmd{SELECT} command.
 The null hypothesis is that both males and females are on average
 of equal height.
 
+@float Screenshot, independent-samples-t:scr
+@psppimage {independent-samples-t}
+@caption {Using the Independent Sample T-test dialog, to test for differences of @exvar{height} between values of @exvar{sex}}
+@end float
+
+
 In this case, the grouping variable is @exvar{sex}, so this is entered
 as the variable for the @subcmd{GROUP} subcommand.  The group values are  0 (male) and
 1 (female).
 
 If you are running the proceedure using syntax, then you need to enter
 the values corresponding to each group within parentheses.
-
+If you are using the graphic user interface, then you have to open
+the ``Define Groups'' dialog box and enter the values corresponding
+to each group as shown in @ref{define-groups-t:scr}.  If, as in this case, the dataset has defined value
+labels for the group variable, then you can enter them by label
+or by value.
+
+@float Screenshot, define-groups-t:scr
+@psppimage {define-groups-t}
+@caption {Setting the values of the grouping variable for an Independent Samples T-test}
+@end float
 
 From @ref{independent-samples-t:res}, one can clearly see that the @emph{sample} mean height
 is greater for males than for females.  However in order to see if this
@@ -2230,6 +2467,11 @@ to use @cmd{COMPUTE} (@pxref{COMPUTE}) and this is what is done in @ref{reliabil
 In this case, all variables in the data set are used.  So we can use the special
 keyword @samp{ALL} (@pxref{BNF}).
 
+@float Screenshot, reliability:src
+@psppimage {reliability}
+@caption {Reliability dialog box with all variables selected}
+@end float
+
 @ref{reliability:res} shows that Cronbach's Alpha is 0.11  which is a value normally considered too
 low to indicate consistency within the data.  This is possibly due to the small number of
 survey questions.  The survey should be redesigned before serious use of the results are