Performs regression across variates (M.W. Patefield & D. Tandy).
||Pointers each containing a set of y-variates for each of whose units a regression is to be done|
||Pointer containing x-variates for each set of y-variates|
||Variate to save the estimated slopes from each set of regressions|
||Variate to save the estimated intercepts from each set of regressions|
Given a pointer containing a set of y-variates and another containing a set of x-variates,
VREGRESS performs a separate regression for the data in each unit of the variates. The pointers are specified using the
X parameters. There must be an equal number of x- and y-variates, and the variates must all be of the same length. The
SLOPE parameter must supply a variate to receive the regression coefficients, and the
INTERCEPT parameter can give a variate to save the intercepts. These variates will have the same length as the x- and y-variates.
The procedure propagates missing values in any of the x-variates into the appropriate unit of the corresponding y-variate, and vice-versa. The regressions are calculated using matrix operations and variate functions in
CALCULATE. The vectors of means across the x- and y-variates are subtracted, and then the sums of squares of
X and the sums of products of
X are calculated across the variates, to obtain the estimated slope coefficients. The estimated intercepts are calculated directly from the slope coefficients and the vectors of means.
The action taken with missing values is the same as would be given by the
FIT directive. Units with all values of
X missing after propagation will have missing values in both
INTERCEPT. Units with a single non-missing value will have a missing value in
SLOPE and the corresponding element of
INTERCEPT equal to the non-missing value of
It is considerably faster to use
VREGRESS than to use
FIT on each unit after re-arrangement of the data. However, there may be a slight loss of accuracy resulting from single-precision calculations on machines where double-precision is used for the calculations within
All the data variates in
X must be subject to the same restriction (if any). If this is not so a fault (
VA 1 - incompatible restrictions) will occur during the calculations. If
INTERCEPT is restricted prior to use of
VREGRESS, the restriction must be the same as that on the data variates. On exit from
VREGRESS, the computed
INTERCEPT variates will be restricted in the same way as the data variates.
Commands for Regression analysis.
CAPTION 'VREGRESS example',\ !t('The data (from John Laws, IGAP, North Wyke, Devon)',\ 'consists of weights of seven lambs each taken at',\ 'four different ages.'); STYLE=meta,plain VARIATE Age[1...4],Lambwt[1...4] READ [PRINT=errors;SETNVALUES=yes] Age[1...4],Lambwt[1...4] 0 36 49 63 4.5 17 20 25 0 30 43 57 5.9 13 17 20 0 25 38 52 5.4 11 14 20 0 35 48 62 4.5 16 20 25 0 19 32 46 7.3 15 20 27 0 9 22 36 5.2 * 12 16 0 1 14 28 4.5 * 9 13 : PRINT Age[1...4],Lambwt[1...4]; FIELDWIDTH=4(7),4(10); DECIMALS=4(0),3(1) VREGRESS Y=Lambwt; X=Age; SLOPE=Rate; INTERCEPT=Constant PRINT Rate,Constant; DECIMALS=3,2 CAPTION\ !t('For each lamb, a regression is calculated of the four values in',\ 'Lambwt[1...4] on the four values in Age[1...4]. Thus, for the first',\ 'lamb, the regression is of ( 4.5, 17, 20, 25 ) on ( 0, 36, 49, 63 ) ', \ 'giving a fitted line:-'),'Lambwt = 4.69 + 0.323 Age',\ !t('For the last lamb the missing value is excluded, so the regression',\ 'is of the three values ( 4.5, 9, 13 ) on ( 0, 14, 28 ) ',\ 'giving a fitted line:-'),'Lambwt = 4.58 + 0.304 Age'