Implemented the RANK command.
[pspp-builds.git] / doc / regression.texi
1 @node REGRESSION, ,RANK, Statistics
2 @comment  node-name,  next,  previous,  up
3 @section REGRESSION
4
5 The REGRESSION procedure fits linear models to data via least-squares
6 estimation. The procedure is appropriate for data which satisfy those
7 assumptions typical in linear regression:
8
9 @itemize @bullet
10 @item The data set contains n observations of a dependent variable, say
11 Y_1,...,Y_n, and n observations of one or more explanatory
12 variables. Let X_11, X_12, ..., X_1n denote the n observations of the
13 first explanatory variable; X_21,...,X_2n denote the n observations of the
14 second explanatory variable; X_k1,...,X_kn denote the n observations of the kth
15 explanatory variable.
16
17 @item The dependent variable Y has the following relationship to the 
18 explanatory variables:
19 @math{Y_i = b_0 + b_1 X_1i + ... + b_k X_ki + Z_i} 
20 where @math{b_0, b_1, ..., b_k} are unknown
21 coefficients, and @math{Z_1,...,Z_n} are independent, normally
22 distributed ``noise'' terms with common variance. The noise, or
23 ``error'' terms are unobserved. This relationship is called the
24 ``linear model.''
25 @end itemize
26
27 The REGRESSION procedure estimates the coefficients
28 @math{b_0,...,b_k} and produces output relevant to inferences for the
29 linear model. 
30
31 @c If you add any new commands, then don't forget to remove the entry in 
32 @c not-implemented.texi
33
34 @menu
35 * Syntax::                      Syntax definition.
36 * Examples::                    Using the REGRESSION procedure.
37 @end menu
38
39 @node Syntax, Examples, , REGRESSION
40 @subsection Syntax
41
42 @vindex REGRESSION
43 @display
44 REGRESSION
45         /VARIABLES=var_list
46         /DEPENDENT=var_list
47         /STATISTICS=@{ALL, DEFAULTS, R, COEFF, ANOVA, BCOV@}
48         /EXPORT ('file-name')
49         /SAVE=@{PRED, RESID@}
50 @end display
51
52 The @cmd{REGRESSION} procedure reads the active file and outputs
53 statistics relevant to the linear model specified by the user.
54
55 The VARIABLES subcommand, which is required, specifies the list of
56 variables to be analyzed.  Keyword VARIABLES is required. The
57 DEPENDENT subcommand specifies the dependent variable of the linear
58 model. The DEPENDENT subcommand is required. All variables listed in
59 the VARIABLES subcommand, but not listed in the DEPENDENT subcommand,
60 are treated as explanatory variables in the linear model.
61
62 All other subcommands are optional:
63
64 The STATISTICS subcommand specifies the statistics to be displayed:
65
66 @table @code
67 @item ALL
68 All of the statistics below.
69 @item R
70 The ratio of the sums of squares due to the model to the total sums of
71 squares for the dependent variable.
72 @item COEFF
73 A table containing the estimated model coefficients and their standard errors.
74 @item ANOVA
75 Analysis of variance table for the model.
76 @item BCOV
77 The covariance matrix for the estimated model coefficients.
78 @end table
79
80 The SAVE subcommand causes PSPP to save the residuals or predicted
81 values from the fitted
82 model to the active file. PSPP will store the residuals in a variable
83 called RES1 if no such variable exists, RES2 if RES1 already exists,
84 RES3 if RES1 and RES2 already exist, etc. It will choose the name of
85 the variable for the predicted values similarly, but with PRED as a
86 prefix.
87
88 The EXPORT subcommand causes PSPP to write a C program containing
89 functions related to the model. One such function accepts values of
90 explanatory variables as arguments, and returns an estimate of the
91 corresponding new
92 value of the dependent variable. The generated program will also contain
93 functions that return prediction and confidence intervals related to
94 those new estimates. PSPP will write the program to the
95 'file-name' given by the user, and write declarations of functions
96 to a file called pspp_model_reg.h. The user can then compile the C
97 program and use it as part of another program. This subcommand is a
98 PSPP extension.
99
100 @node Examples, , Syntax, REGRESSION
101 @subsection Examples
102 The following PSPP syntax will generate the default output, save the
103 predicted values and residuals to the active file, and save the
104 linear model in a program called ``model.c.''
105
106 @example
107 title 'Demonstrate REGRESSION procedure'.
108 data list / v0 1-2 (A) v1 v2 3-22 (10).
109 begin data.
110 b  7.735648 -23.97588
111 b  6.142625 -19.63854
112 a  7.651430 -25.26557
113 c  6.125125 -16.57090
114 a  8.245789 -25.80001
115 c  6.031540 -17.56743
116 a  9.832291 -28.35977
117 c  5.343832 -16.79548
118 a  8.838262 -29.25689
119 b  6.200189 -18.58219
120 end data.
121 list.
122 regression /variables=v0 v1 v2 /statistics defaults /dependent=v2 
123            /export (model.c) /save pred resid /method=enter.
124 @end example
125
126 The file pspp_model_reg.h contains these declarations:
127
128 @example
129 double pspp_reg_estimate (const double *, const char *[]);
130 double pspp_reg_variance (const double *var_vals, const char *[]);
131 double pspp_reg_confidence_interval_U (const double *var_vals, const char *var_names[], double p);
132 double pspp_reg_confidence_interval_L (const double *var_vals, const char *var_names[], double p);
133 double pspp_reg_prediction_interval_U (const double *var_vals, const char *var_names[], double p);
134 double pspp_reg_prediction_interval_L (const double *var_vals, const char *var_names[], double p);
135 @end example
136
137 The file model.c contains the definitions of the functions. 
138 @setfilename ignored