doc: Add section on how to exit PSPP to the tutorial.
[pspp] / doc / tutorial.texi
1 @alias prompt = sansserif
2
3 @include tut.texi
4
5 @node Using PSPP
6 @chapter Using @pspp{}
7
8 @pspp{} is a tool for the statistical analysis of sampled data.
9 You can use it to discover patterns in the data,
10 to explain differences in one subset of data in terms of another subset
11 and to find out
12 whether certain beliefs about the data are justified.
13 This chapter does not attempt to introduce the theory behind the 
14 statistical analysis,
15 but it shows how such analysis can be performed using @pspp{}.
16
17 For the purposes of this tutorial, it is assumed that you are using @pspp{} in its 
18 interactive mode from the command line.
19 However, the example commands can also be typed into a file and executed in 
20 a post-hoc mode by typing @samp{pspp @var{filename}} at a shell prompt,
21 where @var{filename} is the name of the file containing the commands.
22 Alternatively, from the graphical interface, you can select
23 @clicksequence{File @click{} New @click{} Syntax} to open a new syntax window
24 and use the @clicksequence{Run} menu when a syntax fragment is ready to be 
25 executed.
26 Whichever method you choose, the syntax is identical.
27
28 When using the interactive method, @pspp{} tells you that it's waiting for your
29 data with a string like @prompt{PSPP>} or @prompt{data>}.
30 In the examples of this chapter, whenever you see text like this, it
31 indicates the prompt displayed by @pspp{}, @emph{not} something that you 
32 should type.
33
34 Throughout this chapter reference is made to a number of sample data files.
35 So that you can try the examples for yourself,
36 you should have received these files along with your copy of @pspp{}.@c
37 @footnote{These files contain purely fictitious data.  They should not be used
38 for research purposes.}
39 @note{Normally these files are installed in the directory
40 @file{@value{example-dir}}.
41 If however your system administrator or operating system vendor has
42 chosen to install them in a different location, you will have to adjust
43 the examples accordingly.}
44
45
46 @menu
47 * Preparation of Data Files::   
48 * Data Screening and Transformation::  
49 * Hypothesis Testing::          
50 @end menu
51
52 @node Preparation of Data Files
53 @section Preparation of Data Files
54
55
56 Before analysis can commence,  the data must be loaded into @pspp{} and
57 arranged such that both @pspp{} and humans can understand what
58 the data represents.
59 There are two aspects of data:
60
61 @itemize @bullet
62 @item The variables --- these are the parameters of a quantity
63  which has been measured or estimated in some way.
64  For example height, weight and geographic location are all variables.
65 @item The observations (also called `cases') of the variables ---
66  each observation represents an instance when the variables were measured
67  or observed. 
68 @end itemize
69
70 @noindent
71 For example, a data set which has the variables @var{height}, @var{weight}, and
72 @var{name}, might have the observations:
73 @example
74 1881 89.2 Ahmed
75 1192 107.01 Frank
76 1230 67 Julie
77 @end example
78 @noindent
79 The following sections explain how to define a dataset.
80
81 @menu
82 * Defining Variables::          
83 * Listing the data::            
84 * Reading data from a text file::  
85 * Reading data from a pre-prepared PSPP file::  
86 * Saving data to a PSPP file.::  
87 * Reading data from other sources::  
88 * Exiting PSPP::
89 @end menu
90
91 @node Defining Variables
92 @subsection Defining Variables
93 @cindex variables
94
95 Variables come in two basic types, @i{viz}: @dfn{numeric} and @dfn{string}.
96 Variables such as age, height and satisfaction are numeric,
97 whereas name is a string variable.
98 String variables are best reserved for commentary data to assist the 
99 human observer.
100 However they can also be used for nominal or categorical data.
101
102
103 @ref{data-list} defines two variables @var{forename} and @var{height},
104 and reads data into them by manual input. 
105
106 @float Example, data-list
107 @cartouche
108 @example
109 @prompt{PSPP>} data list list /forename (A12) height.
110 @prompt{PSPP>} begin data.
111 @prompt{data>} Ahmed 188
112 @prompt{data>} Bertram 167
113 @prompt{data>} Catherine 134.231
114 @prompt{data>} David 109.1
115 @prompt{data>} end data
116 @prompt{PSPP>}
117 @end example
118 @end cartouche
119 @caption{Manual entry of data using the @cmd{DATA LIST} command.
120 Two variables
121 @var{forename} and @var{height} are defined and subsequently filled
122 with  manually entered data.}
123 @end float
124
125 There are several things to note about this example.
126
127 @itemize @bullet
128 @item
129 The words @samp{data list list} are an example of the @cmd{DATA LIST}
130 command. @xref{DATA LIST}.
131 It tells @pspp{} to prepare for reading data.
132 The word @samp{list} intentionally appears twice.
133 The first occurrence is part of the @cmd{DATA LIST} call,
134 whilst the second
135 tells @pspp{} that the data is to be read as free format data with
136 one record per line.
137
138 @item
139 The @samp{/} character is important. It marks the start of the list of
140 variables which you wish to define.
141
142 @item
143 The text @samp{forename} is the name of the first variable,
144 and @samp{(A12)} says that the variable @var{forename} is a string
145 variable and that its maximum length is 12 bytes.
146 The second variable's name is specified by the text @samp{height}.
147 Since no format is given, this variable has the default format.
148 Normally the default format expects numeric data, which should be
149 entered in the locale of the operating system.
150 Thus, the example is correct for English locales and other
151 locales which use a period (@samp{.}) as the decimal separator.
152 However if you are using a system with a locale which uses the comma (@samp{,})
153 as the decimal separator, then you should in the subsequent lines substitute
154 @samp{.} with @samp{,}.  
155 Alternatively, you could explicitly tell @pspp{} that the @var{height} 
156 variable is to be read using a period as its decimal separator by appending the
157 text @samp{DOT8.3} after the word @samp{height}.
158 For more information on data formats, @pxref{Input and Output Formats}.
159
160
161 @item
162 Normally, @pspp{} displays the  prompt @prompt{PSPP>} whenever it's
163 expecting a command.
164 However, when it's expecting data, the prompt changes to @prompt{data>}
165 so that you know to enter data and not a command.
166
167 @item
168 At the end of every command there is a terminating @samp{.} which tells
169 @pspp{} that the end of a command has been encountered.
170 You should not enter @samp{.} when data is expected (@i{ie.} when 
171 the @prompt{data>} prompt is current) since it is appropriate only for
172 terminating commands.
173 @end itemize
174
175 @node Listing the data
176 @subsection Listing the data
177 @vindex LIST
178
179 Once the data has been entered,
180 you could type
181 @example
182 @prompt{PSPP>} list /format=numbered.
183 @end example
184 @noindent
185 to list the data.
186 The optional text @samp{/format=numbered} requests the case numbers to be 
187 shown along with the data.
188 It should show the following output:
189 @example
190 @group
191 Case#     forename   height
192 ----- ------------ --------
193     1 Ahmed          188.00 
194     2 Bertram        167.00 
195     3 Catherine      134.23 
196     4 David          109.10 
197 @end group
198 @end example
199 @noindent
200 Note that the numeric variable @var{height} is displayed to 2 decimal 
201 places, because the format for that variable is @samp{F8.2}.
202 For a complete description of the @cmd{LIST} command, @pxref{LIST}.
203
204 @node Reading data from a text file
205 @subsection Reading data from a text file
206 @cindex reading data
207
208 The previous example showed how to define a set of variables and to 
209 manually enter the data for those variables.
210 Manual entering of data is tedious work, and often
211 a file containing the data will be have been previously 
212 prepared.
213 Let us assume that you have a file called @file{mydata.dat} containing the
214 ascii encoded data:
215 @example
216 Ahmed          188.00 
217 Bertram        167.00 
218 Catherine      134.23 
219 David          109.10 
220 @              .
221 @              .
222 @              .
223 Zachariah      113.02
224 @end example
225 @noindent
226 You can can tell the @cmd{DATA LIST} command to read the data directly from
227 this file instead of by manual entry, with a command like:
228 @example
229 @prompt{PSPP>} data list file='mydata.dat' list /forename (A12) height.
230 @end example
231 @noindent
232 Notice however, that it is still necessary to specify the names of the
233 variables and their formats, since this information is not contained
234 in the file.
235 It is also possible to specify the file's character encoding and other 
236 parameters.
237 For full details refer to @pxref{DATA LIST}.
238
239 @node Reading data from a pre-prepared PSPP file
240 @subsection Reading data from a pre-prepared @pspp{} file
241 @cindex system files
242 @vindex GET
243
244 When working with other @pspp{} users, or users of other software which
245 uses the @pspp{} data format, you may be given the data in
246 a pre-prepared @pspp{} file.
247 Such files contain not only the data, but the variable definitions,
248 along with their formats, labels and other meta-data.
249 Conventionally, these files (sometimes called ``system'' files) 
250 have the suffix @file{.sav}, but that is
251 not mandatory.
252 The following syntax loads a file called @file{my-file.sav}.
253 @example
254 @prompt{PSPP>} get file='my-file.sav'.
255 @end example
256 @noindent
257 You will encounter several instances of this in future examples.
258
259
260 @node Saving data to a PSPP file.
261 @subsection Saving data to a @pspp{} file.
262 @cindex saving
263 @vindex SAVE
264
265 If you want to save your data, along with the variable definitions so
266 that you or other @pspp{} users can use it later, you can do this with
267 the @cmd{SAVE} command.
268
269 The following syntax will save the existing data and variables to a
270 file called @file{my-new-file.sav}.
271 @example
272 @prompt{PSPP>} save outfile='my-new-file.sav'.
273 @end example
274 @noindent
275 If @file{my-new-file.sav} already exists, then it will be overwritten.
276 Otherwise it will be created.
277
278
279 @node Reading data from other sources
280 @subsection Reading data from other sources
281 @cindex comma separated values
282 @cindex spreadsheets
283 @cindex databases
284
285 Sometimes it's useful to be able to read data from comma 
286 separated text, from spreadsheets, databases or other sources.
287 In these instances you should
288 use the @cmd{GET DATA} command (@pxref{GET DATA}).
289
290 @node Exiting PSPP
291 @subsection Exiting PSPP
292
293 Use the @cmd{FINISH} command to exit PSPP:
294 @example
295 @prompt{PSPP>} finish.
296 @end example
297   
298 @node Data Screening and Transformation
299 @section Data Screening and Transformation
300
301 @cindex screening
302 @cindex transformation
303
304 Once data has been entered, it is often desirable, or even necessary,
305 to transform it in some way before performing analysis upon it.
306 At the very least, it's good practice to check for errors.
307
308 @menu
309 * Identifying incorrect data::  
310 * Dealing with suspicious data::  
311 * Inverting negatively coded variables::  
312 * Testing data consistency::    
313 * Testing for normality ::      
314 @end menu
315
316 @node Identifying incorrect data
317 @subsection Identifying incorrect data
318 @cindex erroneous data
319 @cindex errors, in data
320
321 Data from real sources is rarely error free.
322 @pspp{} has a number of procedures which can be used to help 
323 identify data which might be incorrect.
324
325 The @cmd{DESCRIPTIVES} command (@pxref{DESCRIPTIVES}) is used to generate
326 simple linear statistics for a dataset.  It is also useful for
327 identifying potential problems in the data.
328 The example file @file{physiology.sav} contains a number of physiological
329 measurements of a sample of healthy adults selected at random.
330 However, the data entry clerk made a number of mistakes when entering
331 the data.
332 @ref{descriptives} illustrates the use of @cmd{DESCRIPTIVES} to screen this
333 data and identify the erroneous values.
334
335 @float Example, descriptives
336 @cartouche
337 @example
338 @prompt{PSPP>} get file='@value{example-dir}/physiology.sav'.
339 @prompt{PSPP>} descriptives sex, weight, height.
340 @end example
341
342 Output:
343 @example
344 DESCRIPTIVES.  Valid cases = 40; cases with missing value(s) = 0.
345 +--------#--+-------+-------+-------+-------+
346 |Variable# N|  Mean |Std Dev|Minimum|Maximum|
347 #========#==#=======#=======#=======#=======#
348 |sex     #40|    .45|    .50|    .00|   1.00|
349 |height  #40|1677.12| 262.87| 179.00|1903.00|
350 |weight  #40|  72.12|  26.70| -55.60|  92.07|
351 +--------#--+-------+-------+-------+-------+
352 @end example
353 @end cartouche
354 @caption{Using the @cmd{DESCRIPTIVES} command to display simple 
355 summary information about the data.
356 In this case, the results show unexpectedly low values in the Minimum
357 column, suggesting incorrect data entry.}
358 @end float
359
360 In the output of @ref{descriptives},
361 the most interesting column is the minimum value.
362 The @var{weight} variable has a minimum value of less than zero,
363 which is clearly erroneous.
364 Similarly, the @var{height} variable's minimum value seems to be very low.
365 In fact, it is more than 5 standard deviations from the mean, and is a 
366 seemingly bizarre height for an adult person.
367 We can examine the data in more detail with the @cmd{EXAMINE}
368 command (@pxref{EXAMINE}):
369
370 In @ref{examine} you can see that the lowest value of @var{height} is
371 179 (which we suspect to be erroneous), but the second lowest is 1598
372 which
373 we know from the @cmd{DESCRIPTIVES} command 
374 is within 1 standard deviation from the mean.
375 Similarly the @var{weight} variable has a lowest value which is
376 negative but a plausible value for the second lowest value.
377 This suggests that the two extreme values are outliers and probably 
378 represent data entry errors. 
379
380 @float Example, examine
381 @cartouche
382 [@dots{} continue from @ref{descriptives}]
383 @example
384 @prompt{PSPP>} examine height, weight /statistics=extreme(3).    
385 @end example
386
387 Output:
388 @example
389 #===============================#===========#=======#
390 #                               #Case Number| Value #
391 #===============================#===========#=======#
392 #Height in millimetres Highest 1#         14|1903.00#
393 #                              2#         15|1884.00#
394 #                              3#         12|1801.65#
395 #                     ----------#-----------+-------#
396 #                       Lowest 1#         30| 179.00#
397 #                              2#         31|1598.00#
398 #                              3#         28|1601.00#
399 #                     ----------#-----------+-------#
400 #Weight in kilograms   Highest 1#         13|  92.07#
401 #                              2#          5|  92.07#
402 #                              3#         17|  91.74#
403 #                     ----------#-----------+-------#
404 #                       Lowest 1#         38| -55.60#
405 #                              2#         39|  54.48#
406 #                              3#         33|  55.45#
407 #===============================#===========#=======#
408 @end example
409 @end cartouche
410 @caption{Using the @cmd{EXAMINE} command to see the extremities of the data
411 for different variables.  Cases 30 and 38 seem to contain values
412 very much lower than the rest of the data.
413 They are possibly erroneous.}
414 @end float
415
416 @node Dealing with suspicious data
417 @subsection Dealing with suspicious data
418
419 @cindex SYSMIS
420 @cindex recoding data
421 If possible, suspect data should be checked and re-measured.
422 However, this may not always be feasible, in which case the researcher may
423 decide to disregard these values.
424 @pspp{} has a feature whereby data can assume the special value `SYSMIS', and
425 will be disregarded in future analysis. @xref{Missing Observations}.
426 You can set the two suspect values to the `SYSMIS' value using the @cmd{RECODE}
427 command.
428 @example
429 @pspp{}> recode height (179 = SYSMIS).
430 @pspp{}> recode weight (LOWEST THRU 0 = SYSMIS).
431 @end example
432 @noindent
433 The first command says that for any observation which has a
434 @var{height} value of 179, that value should be changed to the SYSMIS
435 value.
436 The second command says that any @var{weight} values of zero or less
437 should be changed to SYSMIS.
438 From now on, they will be ignored in analysis.
439 For detailed information about the @cmd{RECODE} command @pxref{RECODE}.
440
441 If you now re-run the @cmd{DESCRIPTIVES} or @cmd{EXAMINE} commands in
442 @ref{descriptives} and @ref{examine} you
443 will see a data summary with more plausible parameters.
444 You will also notice that the data summaries indicate the two missing values.
445
446 @node Inverting negatively coded variables
447 @subsection Inverting negatively coded variables
448
449 @cindex Likert scale
450 @cindex Inverting data
451 Data entry errors are not the only reason for wanting to recode data.
452 The sample file @file{hotel.sav} comprises data gathered from a 
453 customer satisfaction survey of clients at a particular hotel.
454 In @ref{reliability}, this file is loaded for analysis.
455 The line @code{display dictionary.} tells @pspp{} to display the
456 variables and associated data.
457 The output from this command has been omitted from the example for the sake of clarity, but
458 you will notice that each of the variables
459 @var{v1}, @var{v2} @dots{} @var{v5}  are measured on a 5 point Likert scale,
460 with 1 meaning ``Strongly disagree'' and 5 meaning ``Strongly agree''.
461 Whilst variables @var{v1}, @var{v2} and @var{v4} record responses
462 to a positively posed question, variables @var{v3} and @var{v5} are 
463 responses to negatively worded questions.
464 In order to perform meaningful analysis, we need to recode the variables so
465 that they all measure in the same direction.
466 We could use the @cmd{RECODE} command, with syntax such as:
467 @example
468 recode v3 (1 = 5) (2 = 4) (4 = 2) (5 = 1).
469 @end example
470 @noindent
471 However an easier and more elegant way uses the @cmd{COMPUTE}
472 command (@pxref{COMPUTE}).
473 Since the variables are Likert variables in the range (1 @dots{} 5),
474 subtracting their value  from 6 has the effect of inverting them:
475 @example
476 compute @var{var} = 6 - @var{var}.
477 @end example
478 @noindent
479 @ref{reliability} uses this technique to recode the variables 
480 @var{v3} and @var{v5}.
481 After applying  @cmd{COMPUTE} for both variables,
482 all subsequent commands will use the inverted values.
483
484
485 @node Testing data consistency
486 @subsection Testing data consistency
487
488 @cindex reliability
489 @cindex consistency
490
491 A sensible check to perform on survey data is the calculation of
492 reliability.
493 This gives the statistician some confidence that the questionnaires have been 
494 completed thoughtfully.
495 If you examine the labels of variables @var{v1},  @var{v3} and @var{v5},
496 you will notice that they ask very similar questions.
497 One would therefore expect the values of these variables (after recoding) 
498 to closely follow one another, and we can test that with the @cmd{RELIABILITY} 
499 command (@pxref{RELIABILITY}).
500 @ref{reliability} shows a @pspp{} session where the user (after recoding
501 negatively scaled variables) requests reliability statistics for
502 @var{v1}, @var{v3} and @var{v5}.
503
504 @float Example, reliability
505 @cartouche
506 @example
507 @prompt{PSPP>} get file='@value{example-dir}/hotel.sav'.
508 @prompt{PSPP>} display dictionary.
509 @prompt{PSPP>} * recode negatively worded questions.
510 @prompt{PSPP>} compute v3 = 6 - v3.
511 @prompt{PSPP>} compute v5 = 6 - v5.
512 @prompt{PSPP>} reliability v1, v3, v5.
513 @end example
514
515 Output (dictionary information omitted for clarity):
516 @example
517 1.1 RELIABILITY.  Case Processing Summary
518 #==============#==#======#
519 #              # N|   %  #
520 #==============#==#======#
521 #Cases Valid   #17|100.00#
522 #      Excluded# 0|   .00#
523 #      Total   #17|100.00#
524 #==============#==#======#
525
526 1.2 RELIABILITY.  Reliability Statistics
527 #================#==========#
528 #Cronbach's Alpha#N of Items#
529 #================#==========#
530 #             .86#         3#
531 #================#==========#
532 @end example
533 @end cartouche
534 @caption{Recoding negatively scaled variables, and testing for
535 reliability with the @cmd{RELIABILITY} command. The Cronbach Alpha
536 coefficient suggests a high degree of reliability among variables
537 @var{v1}, @var{v2} and @var{v5}.}
538 @end float
539
540 As a rule of thumb, many statisticians consider a value of Cronbach's Alpha of 
541 0.7 or higher to indicate reliable data.
542 Here, the value is 0.86 so the data and the recoding that we performed 
543 are vindicated.
544
545
546 @node Testing for normality 
547 @subsection Testing for normality
548 @cindex normality, testing 
549
550 Many statistical tests rely upon certain properties of the data.
551 One common property, upon which many linear tests depend, is that of
552 normality --- the data must have been drawn from a normal distribution.
553 It is necessary then to ensure normality before deciding upon the
554 test procedure to use.  One way to do this uses the @cmd{EXAMINE} command.
555
556 In @ref{normality}, a researcher was examining the failure rates
557 of equipment produced by an engineering company.
558 The file @file{repairs.sav} contains the mean time between
559 failures (@var{mtbf}) of some items of equipment subject to the study.
560 Before performing linear analysis on the data, 
561 the researcher wanted to ascertain that the data is normally distributed.
562
563 A normal distribution has a skewness and kurtosis of zero.
564 Looking at the skewness of @var{mtbf} in @ref{normality} it is clear
565 that the mtbf figures have a lot of positive skew and are therefore
566 not drawn from a normally distributed variable.
567 Positive skew can often be compensated for by applying a logarithmic 
568 transformation.
569 This is done with the @cmd{COMPUTE} command in the line
570 @example
571 compute mtbf_ln = ln (mtbf).
572 @end example
573 @noindent
574 Rather than redefining the existing variable, this use of @cmd{COMPUTE}
575 defines a new variable @var{mtbf_ln} which is
576 the natural logarithm of @var{mtbf}.
577 The final command in this example calls @cmd{EXAMINE} on this new variable,
578 and it can be seen from the results that both the skewness and
579 kurtosis for @var{mtbf_ln} are very close to zero.
580 This provides some confidence that the @var{mtbf_ln} variable is 
581 normally distributed and thus safe for linear analysis.
582 In the event that no suitable transformation can be found,
583 then it would be worth considering 
584 an appropriate non-parametric test instead of a linear one.
585 @xref{NPAR TESTS}, for information about non-parametric tests.
586
587 @float Example, normality
588 @cartouche
589 @example
590 @prompt{PSPP>} get file='@value{example-dir}/repairs.sav'.
591 @prompt{PSPP>} examine mtbf 
592                 /statistics=descriptives.
593 @prompt{PSPP>} compute mtbf_ln = ln (mtbf).
594 @prompt{PSPP>} examine mtbf_ln
595                 /statistics=descriptives.
596 @end example
597
598 Output:
599 @example
600 1.2 EXAMINE.  Descriptives
601 #====================================================#=========#==========#
602 #                                                    #Statistic|Std. Error#
603 #====================================================#=========#==========#
604 #mtbf    Mean                                        #   8.32  |   1.62   #
605 #        95% Confidence Interval for Mean Lower Bound#   4.85  |          #
606 #                                         Upper Bound#  11.79  |          #
607 #        5% Trimmed Mean                             #   7.69  |          #
608 #        Median                                      #   8.12  |          #
609 #        Variance                                    #  39.21  |          #
610 #        Std. Deviation                              #   6.26  |          #
611 #        Minimum                                     #   1.63  |          #
612 #        Maximum                                     #  26.47  |          #
613 #        Range                                       #  24.84  |          #
614 #        Interquartile Range                         #   5.83  |          #
615 #        Skewness                                    #   1.85  |    .58   #
616 #        Kurtosis                                    #   4.49  |   1.12   #
617 #====================================================#=========#==========#
618
619 2.2 EXAMINE.  Descriptives
620 #====================================================#=========#==========#
621 #                                                    #Statistic|Std. Error#
622 #====================================================#=========#==========#
623 #mtbf_ln Mean                                        #   1.88  |    .19   #
624 #        95% Confidence Interval for Mean Lower Bound#   1.47  |          #
625 #                                         Upper Bound#   2.29  |          #
626 #        5% Trimmed Mean                             #   1.88  |          #
627 #        Median                                      #   2.09  |          #
628 #        Variance                                    #   .54   |          #
629 #        Std. Deviation                              #   .74   |          #
630 #        Minimum                                     #   .49   |          #
631 #        Maximum                                     #   3.28  |          #
632 #        Range                                       #   2.79  |          #
633 #        Interquartile Range                         #   .92   |          #
634 #        Skewness                                    #   -.16  |    .58   #
635 #        Kurtosis                                    #   -.09  |   1.12   #
636 #====================================================#=========#==========#
637 @end example
638 @end cartouche
639 @caption{Testing for normality using the @cmd{EXAMINE} command and applying
640 a logarithmic transformation.
641 The @var{mtbf} variable has a large positive skew and is therefore
642 unsuitable for linear statistical analysis.
643 However the transformed variable (@var{mtbf_ln}) is close to normal and
644 would appear to be more suitable.}
645 @end float
646
647
648 @node Hypothesis Testing
649 @section Hypothesis Testing
650
651 @cindex Hypothesis testing
652 @cindex p-value
653 @cindex null hypothesis
654
655 One of the most fundamental purposes of statistical analysis
656 is hypothesis testing.
657 Researchers commonly need to test hypotheses about a set of data.
658 For example, she might want to test whether one set of data comes from
659 the same distribution as another,
660 or
661 whether the mean of a dataset significantly differs from a particular
662 value.
663 This section presents just some of the possible tests that @pspp{} offers.
664
665 The researcher starts by making a @dfn{null hypothesis}.
666 Often this is a hypothesis which he suspects to be false.
667 For example, if he suspects that @var{A} is greater than @var{B} he will 
668 state the null hypothesis as @math{ @var{A} = @var{B}}.@c
669 @footnote{This example assumes that it is already proven that @var{B} is
670 not greater than @var{A}.}
671
672 The @dfn{p-value} is a recurring concept in hypothesis testing.
673 It is the highest acceptable probability that the evidence implying a
674 null hypothesis is false, could have been obtained when the null
675 hypothesis is in fact true.
676 Note that this is not the same as ``the probability of making an
677 error'' nor is it the same as ``the probability of rejecting a
678 hypothesis when it is true''.
679
680
681
682 @menu
683 * Testing for differences of means::  
684 * Linear Regression::           
685 @end menu
686
687 @node Testing for differences of means
688 @subsection Testing for differences of means
689
690 @cindex T-test
691 @vindex T-TEST
692
693 A common statistical test involves hypotheses about means.
694 The @cmd{T-TEST} command is used to find out whether or not two separate 
695 subsets have the same mean.
696
697 @ref{t-test} uses the file @file{physiology.sav} previously
698 encountered.
699 A researcher suspected that the heights and core body 
700 temperature of persons might be different depending upon their sex.
701 To investigate this, he posed two null hypotheses: 
702 @itemize @bullet
703 @item The mean heights of males and females in the population are equal.
704 @item The mean body temperature of males and
705       females in the population are equal.
706 @end itemize
707 @noindent
708 For the purposes of the investigation the researcher
709 decided to use a  p-value of 0.05.
710
711 In addition to the T-test, the @cmd{T-TEST} command also performs the 
712 Levene test for equal variances.
713 If the variances are equal, then a more powerful form of the T-test can be used.
714 However if it is unsafe to assume equal variances,
715 then an alternative calculation is necessary.
716 @pspp{} performs both calculations.
717
718 For the @var{height} variable, the output shows the significance of the 
719 Levene test to be 0.33 which means there is a 
720 33% probability that the  
721 Levene test produces this outcome when the variances are equal.
722 Had the significance been less than 0.05, then it would have been unsafe to assume that
723 the variances were equal.
724 However, because the value is higher than 0.05 the homogeneity of variances assumption
725 is safe and the ``Equal Variances'' row (the more powerful test) can be used.
726 Examining this row, the two tailed significance for the @var{height} t-test 
727 is less than 0.05, so it is safe to reject the null hypothesis and conclude
728 that the mean heights of males and females are unequal.
729
730 For the @var{temperature} variable, the significance of the Levene test 
731 is 0.58 so again, it is safe to use the row for equal variances.
732 The equal variances row indicates that the two tailed significance for
733 @var{temperature} is 0.20.  Since this is greater than 0.05 we must reject
734 the null hypothesis and conclude that there is insufficient evidence to 
735 suggest that the body temperature of male and female persons are different.
736
737 @float Example, t-test
738 @cartouche
739 @example
740 @prompt{PSPP>} get file='@value{example-dir}/physiology.sav'.
741 @prompt{PSPP>} recode height (179 = SYSMIS).
742 @prompt{PSPP>} t-test group=sex(0,1) /variables = height temperature.
743 @end example
744 Output:
745 @example
746 1.1 T-TEST.  Group Statistics
747 #==================#==#=======#==============#========#
748 #              sex | N|  Mean |Std. Deviation|SE. Mean#
749 #==================#==#=======#==============#========#
750 #height      Male  |22|1796.49|         49.71|   10.60#
751 #            Female|17|1610.77|         25.43|    6.17#
752 #temperature Male  |22|  36.68|          1.95|     .42#
753 #            Female|18|  37.43|          1.61|     .38#
754 #==================#==#=======#==============#========#
755 1.2 T-TEST.  Independent Samples Test
756 #===========================#=========#===============================   =#
757 #                           # Levene's| t-test for Equality of Means      #
758 #                           #----+----+------+-----+------+---------+-   -#
759 #                           #    |    |      |     |      |         |     #
760 #                           #    |    |      |     |Sig. 2|         |     #
761 #                           #  F |Sig.|   t  |  df |tailed|Mean Diff|     #
762 #===========================#====#====#======#=====#======#=========#=   =#
763 #height      Equal variances# .97| .33| 14.02|37.00|   .00|   185.72| ... #
764 #          Unequal variances#    |    | 15.15|32.71|   .00|   185.72| ... #
765 #temperature Equal variances# .31| .58| -1.31|38.00|   .20|     -.75| ... #
766 #          Unequal variances#    |    | -1.33|37.99|   .19|     -.75| ... #
767 #===========================#====#====#======#=====#======#=========#=   =#
768 @end example                                                          
769 @end cartouche
770 @caption{The @cmd{T-TEST} command tests for differences of means. 
771 Here, the @var{height} variable's two tailed significance is less than
772 0.05, so the null hypothesis can be rejected.
773 Thus, the evidence suggests there is a difference between the heights of
774 male and female persons. 
775 However the significance of the test for the @var{temperature}
776 variable is greater than 0.05 so the null hypothesis cannot be
777 rejected, and there is insufficient evidence to suggest a difference
778 in body temperature.}
779 @end float
780
781 @node Linear Regression
782 @subsection Linear Regression
783 @cindex linear regression
784 @vindex REGRESSION
785
786 Linear regression is a technique used to investigate if and how a variable 
787 is linearly related to others.
788 If a variable is found to be linearly related, then this can be used to 
789 predict future values of that variable.
790
791 In example @ref{regression}, the service department of the company wanted to
792 be able to predict the time to repair equipment, in order to improve
793 the accuracy of their quotations.
794 It was suggested that the time to repair might be related to the time
795 between failures and the duty cycle of the equipment.
796 The p-value of 0.1 was chosen for this investigation.
797 In order to investigate this hypothesis, the @cmd{REGRESSION} command
798 was used.
799 This command not only tests if the variables are related, but also
800 identifies the potential linear relationship. @xref{REGRESSION}.
801
802
803 @float Example, regression 
804 @cartouche
805 @example
806 @prompt{PSPP>} get file='@value{example-dir}/repairs.sav'.
807 @prompt{PSPP>} regression /variables = mtbf duty_cycle /dependent = mttr.
808 @prompt{PSPP>} regression /variables = mtbf /dependent = mttr.
809 @end example
810 Output:
811 @example
812 1.3(1) REGRESSION.  Coefficients
813 #=============================================#====#==========#====#=====#
814 #                                             #  B |Std. Error|Beta|  t  #
815 #========#====================================#====#==========#====#=====#
816 #        |(Constant)                          #9.81|      1.50| .00| 6.54#
817 #        |Mean time between failures (months) #3.10|       .10| .99|32.43#
818 #        |Ratio of working to non-working time#1.09|      1.78| .02|  .61#
819 #        |                                    #    |          |    |     #
820 #========#====================================#====#==========#====#=====#
821
822 1.3(2) REGRESSION.  Coefficients
823 #=============================================#============#
824 #                                             #Significance#
825 #========#====================================#============#
826 #        |(Constant)                          #         .10#
827 #        |Mean time between failures (months) #         .00#
828 #        |Ratio of working to non-working time#         .55#
829 #        |                                    #            #
830 #========#====================================#============#
831 2.3(1) REGRESSION.  Coefficients
832 #============================================#=====#==========#====#=====#
833 #                                            #  B  |Std. Error|Beta|  t  #
834 #========#===================================#=====#==========#====#=====#
835 #        |(Constant)                         #10.50|       .96| .00|10.96#
836 #        |Mean time between failures (months)# 3.11|       .09| .99|33.39#
837 #        |                                   #     |          |    |     #
838 #========#===================================#=====#==========#====#=====#
839
840 2.3(2) REGRESSION.  Coefficients
841 #============================================#============#
842 #                                            #Significance#
843 #========#===================================#============#
844 #        |(Constant)                         #         .06#
845 #        |Mean time between failures (months)#         .00#
846 #        |                                   #            #
847 #========#===================================#============#
848 @end example
849 @end cartouche
850 @caption{Linear regression analysis to find a predictor for
851 @var{mttr}.
852 The first attempt, including @var{duty_cycle}, produces some
853 unacceptable high significance values.
854 However the second attempt, which excludes @var{duty_cycle}, produces
855 significance values no higher than 0.06.
856 This suggests that @var{mtbf} alone may be a suitable predictor
857 for @var{mttr}.}
858 @end float
859
860 The coefficients in the first table suggest that the formula
861 @math{@var{mttr} = 9.81 + 3.1 \times @var{mtbf} + 1.09 \times @var{duty_cycle}}
862 can be used to predict the time to repair.
863 However, the significance value for the @var{duty_cycle} coefficient
864 is very high, which would make this an unsafe predictor.
865 For this reason, the test was repeated, but omitting the
866 @var{duty_cycle} variable.
867 This time, the significance of all coefficients no higher than 0.06,
868 suggesting that at the 0.06 level, the formula
869 @math{@var{mttr} = 10.5 + 3.11 \times @var{mtbf}} is a reliable
870 predictor of the time to repair.
871
872
873 @c  LocalWords:  PSPP dir itemize noindent var cindex dfn cartouche samp xref
874 @c  LocalWords:  pxref ie sav Std Dev kilograms SYSMIS sansserif pre pspp emph
875 @c  LocalWords:  Likert Cronbach's Cronbach mtbf npplot ln myfile cmd NPAR Sig
876 @c  LocalWords:  vindex Levene Levene's df Diff clicksequence mydata dat ascii
877 @c  LocalWords:  mttr outfile