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