RLOFE
Computes a lack of fit test based on exact replicates for a fitted regression model.
Required Arguments
XNOBS by NCOL matrix containing the data. (Input)
IREP — Variable option. (Input)
IREP
Meaning
< 0
The first ‑IREP columns of X contain the variables used to determine exact replicates.
> 0
The IREP variables used to determine exact replicates are specified by the column numbers in INDREP.
0
The exact replicates are specified in IGROUP.
INDREP — Index vector of length IREP containing the column numbers of X that are the variables used to determine replication. (Input, if IREP is positive) If IREP is less than or equal to 0, INDREP is not referenced and can be a vector of length one.
IRSP — Column number IRSP of X contains data for the response (dependent) variable. (Input)
DFE — Degrees of freedom for error from the fitted regression. (Input)
SSE — Sum of squares for error from the fitted regression. (Input)
IGROUP — Vector of length NOBS specifying group numbers. (Output, if IREP is nonzero; input, if IREP = 0)
On output, IGROUP(I) = J means row I of X is in the J-th group of replicates (J = 0, 1, 2, NGROUP). Here, J = 0 indicates the group of observations not used in the analysis because NaN (not a number) was input for one of more of the values of the response, replication, frequency, or weight variables. On input, IGROUP(I) = IGROUP(K), K  I, indicates that row I and row K of X are in the same group. IGROUP(I) must equal 0 if row I of X has NaN as one or more of the values of the response, replication, frequency, or weight variables.
NGROUP — Number of groups in the lack of fit test. (Output)
TESTLF — Vector of length 10 containing statistics relating to the test for lack of fit of the model. (Output)
Elem
Description
1
Degrees of freedom for lack of fit
2
Degrees of freedom for pure error
3
Degrees of freedom for error (TESTLF(1)+ TESTLF(2))
4
Sum of squares for lack of fit
5
Sum of squares for pure error
6
Sum of squares for error
7
Mean square for lack of fit
8
Mean square for pure error
9
F statistic
10
p‑value
If there are no replicates in the data set, a test for lack of fit cannot be performed. In this case, elements 8, 9, and 10 of TESTLF are set to NaN (not a number).
Optional Arguments
NOBS — Number of observations. (Input)
Default: NOBS = size (X,1).
NCOL — Number of columns in X. (Input)
Default: NCOL = size (X,2).
LDX — Leading dimension of X exactly as specified in the dimension statement in the calling program. (Input)
Default: LDX = size (X,1).
IFRQ — Frequency option. (Input)
IFRQ = 0 means that all frequencies are 1.0. For positive IFRQ, column number IFRQ of X contains the frequencies.
Default: IFRQ = 0.
IWT — Weighting option. (Input)
IWT = 0 means that all weights are 1.0. For positive IWT, column number IWT of X contains the weights.
Default: IWT = 0.
FORTRAN 90 Interface
Generic: CALL RLOFE (X, IREP, INDREP, IRSP, DFE, SSE, IGROUP, NGROUP, TESTLF [])
Specific: The specific interface names are S_RLOFE and D_RLOFE.
FORTRAN 77 Interface
Single: CALL RLOFE (NOBS, NCOL, X, LDX, IREP, INDREP, IRSP, IFRQ, IWT, DFE, SSE, IGROUP, NGROUP, TESTLF)
Double: The double precision name is DRLOFE.
Description
Routine RLOFE computes a lack of fit test based on exact replicates for a fitted regression model. The data need not be sorted prior to invoking RLOFE. The column indices of X for determining exact replicates can be input in INDREP. If the groups of exact replicates are known prior to invoking RLOFE, the option IREP = 0 allows RLOFE to bypass the computation of the groups. This option is particularly useful for computing a second lack of fit for a different dependent variable that uses the same columns of X for determining exact replicates as the first test.
If IREP is nonzero, routine SROWR (see Chapter 19, “Utilities”) is used to compute a permutation vector that specifies the sorted X along with the ni’s, the number of rows of X in each group. If IREP is zero, the permutation vector and the ni’s are computed from IGROUP.
Let ni be the number of rows of X in the i-th group of replicates (i = 1, 2, k). Let yij be the response for the jth row within the ith group. Let wij and fij be the associated weight and frequency, respectively. The pure error (within group) sum of squares is
The associated degrees of freedom are
The lack of fit sum of squares is SSE SSPE and the lack of fit degrees of freedom are
DFE DFPE.
The F statistic for the test of the null hypothesis of no lack of fit is
Under the hypothesis of no lack of fit, the computed F has an F distribution with numerator and denominator degrees of freedom DFE  DFPE and DFPE, respectively. The p‑value for the test is computed as the probability that a random variable with this distribution is greater than or equal to the computed F statistic.
Comments
1. Workspace may be explicitly provided, if desired, by use of R2OFE/DR2OFE. The reference is:
CALL R2OFE (NOBS, NCOL, X, LDX, IREP, INDREP, IRSP, IFRQ, IWT, DFE, SSE, IGROUP, NGROUP, TESTLF, IWK, WK)
The additional arguments are as follows:
IWK — Work vector. If IREP = 0, the length of IWK is 3 * NOBS; otherwise, the length of IWK is IREP + m + 2.8854 * ln(m) + 3 * NOBS + 5.
WK — Work vector. If IREP= 0, WK is not referenced and can be a vector of length 1; otherwise, WK is of length 2 * m.
2. Informational errors
Type
Code
Description
3
1
DFE is less than the degrees of freedom for pure error. The degrees of freedom for lack of fit is set to zero.
3
2
SSE is less than the sum of squares for pure error. The sum of squares for lack of fit is set to zero.
4
3
An invalid weight or frequency is encountered. Weights and frequencies must be nonnegative.
4
4
An element in X contains NaN (not a number), but the corresponding element in IGROUP is not zero. When IREP = 0, missing values in a row of X are indicated by setting the corresponding row of IGROUP to zero.
Examples
Example 1
This example uses data from Draper and Smith (1981, page 374), which is input in X. A multiple linear regression of column 6 of X on an intercept and columns 1, 3, and 4 has already been computed. The fit gave a residual sum of squares SSE = 163.93 with DFE = 16 degrees of freedom. A test for lack of fit is computed using routine RLOFE.
 
USE RLOFE_INT
USE UMACH_INT
USE WRIRN_INT
 
IMPLICIT NONE
INTEGER LDX, NCOL, NOBS, NREP, J
PARAMETER (NCOL=6, NOBS=20, NREP=3, LDX=NOBS)
!
INTEGER IGROUP(NOBS), INDREP(NREP), IREP, IRSP, &
NGROUP, NOUT
REAL DFE, SSE, TESTLF(10), X(LDX,NCOL)
!
DATA (X(1,J),J=1,6)/1.0, 1.0, 1.0, 0.0, 1.0, 246.0/
DATA (X(2,J),J=1,6)/1.0, 0.0, 1.0, 0.0, 1.0, 252.0/
DATA (X(3,J),J=1,6)/1.0, 1.0, 1.0, 0.0, 1.0, 253.0/
DATA (X(4,J),J=1,6)/0.0, 1.0, 1.0, 1.0, 0.0, 164.0/
DATA (X(5,J),J=1,6)/1.0, 1.0, 0.0, 0.0, 1.0, 203.0/
DATA (X(6,J),J=1,6)/0.0, 1.0, 1.0, 1.0, 0.0, 173.0/
DATA (X(7,J),J=1,6)/1.0, 1.0, 0.0, 0.0, 1.0, 210.0/
DATA (X(8,J),J=1,6)/1.0, 0.0, 1.0, 0.0, 1.0, 247.0/
DATA (X(9,J),J=1,6)/0.0, 1.0, 0.0, 1.0, 0.0, 120.0/
DATA (X(10,J),J=1,6)/0.0, 1.0, 1.0, 1.0, 0.0, 171.0/
DATA (X(11,J),J=1,6)/0.0, 1.0, 1.0, 1.0, 0.0, 167.0/
DATA (X(12,J),J=1,6)/0.0, 0.0, 1.0, 1.0, 0.0, 172.0/
DATA (X(13,J),J=1,6)/1.0, 1.0, 1.0, 0.0, 1.0, 247.0/
DATA (X(14,J),J=1,6)/1.0, 1.0, 1.0, 0.0, 1.0, 252.0/
DATA (X(15,J),J=1,6)/1.0, 0.0, 1.0, 0.0, 1.0, 248.0/
DATA (X(16,J),J=1,6)/0.0, 1.0, 1.0, 1.0, 0.0, 169.0/
DATA (X(17,J),J=1,6)/0.0, 1.0, 0.0, 0.0, 0.0, 104.0/
DATA (X(18,J),J=1,6)/0.0, 1.0, 1.0, 1.0, 0.0, 166.0/
DATA (X(19,J),J=1,6)/0.0, 1.0, 1.0, 1.0, 0.0, 168.0/
DATA (X(20,J),J=1,6)/0.0, 1.0, 1.0, 0.0, 0.0, 148.0/
DATA INDREP/1, 3, 4/
!
IREP = NREP
IRSP = 6
DFE = 16.0
SSE = 163.93
CALL RLOFE (X, IREP, INDREP, IRSP, DFE, SSE, IGROUP, NGROUP, TESTLF)
CALL UMACH (2, NOUT)
WRITE (NOUT,*) ' NGROUP = ', NGROUP
CALL WRIRN ('IGROUP', IGROUP, 1, NOBS, 1)
WRITE (NOUT,*) ' '
WRITE (NOUT,99999) ' Test for Lack of '// &
'Fit'
WRITE (NOUT,99999) ' Sum of Mean '// &
' Prob. of'
WRITE (NOUT,99999) ' Source of Error DF Squares Square '// &
' F Larger F'
WRITE (NOUT,99999) ' Lack of Fit ', TESTLF(1), TESTLF(4), &
TESTLF(7), TESTLF(9), TESTLF(10)
WRITE (NOUT,99999) ' Expanded model ', TESTLF(2), TESTLF(5), &
TESTLF(8)
WRITE (NOUT,99999) ' Original model ', TESTLF(3), TESTLF(6)
99999 FORMAT (A, F5.1, F9.1, F8.2, F7.3, F10.3)
END
Output
 
NGROUP = 6
 
IGROUP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
6 6 6 4 5 4 5 6 2 4 4 4 6 6 6 4 1 4 4 3
 
Test for Lack of Fit
Sum of Mean Prob. of
Source of Error DF Squares Square F Larger F
Lack of Fit 2.0 20.5 10.25 1.001 0.393
Expanded model 14.0 143.4 10.24
Original model 16.0 163.9
Example 2
This example uses the same data as in Example 1. Here, the option IREP = 0 is used because IGROUP is known before invoking routine RLOFE. Routine SROWR (see Chapter 19, “Utilities”) is used to compute the group numbers contained in IGROUP.
 
USE RLOFE_INT
USE SROWR_INT
USE UMACH_INT
USE WRIRN_INT
 
IMPLICIT NONE
INTEGER LDX, NCOL, NKEY, NOBS, J
PARAMETER (NCOL=6, NKEY=3, NOBS=20, LDX=NOBS)
!
INTEGER I, IGROUP(NOBS), INDKEY(NKEY), &
INDREP(1), IPERM(NOBS), IREP, IRET, IRSP, &
K, NGROUP, NI(NOBS), NOUT, NRMISS
REAL DFE, SSE, TESTLF(10), X(LDX,NCOL)
!
DATA (X(1,J),J=1,6)/1.0, 1.0, 1.0, 0.0, 1.0, 246.0/
DATA (X(2,J),J=1,6)/1.0, 0.0, 1.0, 0.0, 1.0, 252.0/
DATA (X(3,J),J=1,6)/1.0, 1.0, 1.0, 0.0, 1.0, 253.0/
DATA (X(4,J),J=1,6)/0.0, 1.0, 1.0, 1.0, 0.0, 164.0/
DATA (X(5,J),J=1,6)/1.0, 1.0, 0.0, 0.0, 1.0, 203.0/
DATA (X(6,J),J=1,6)/0.0, 1.0, 1.0, 1.0, 0.0, 173.0/
DATA (X(7,J),J=1,6)/1.0, 1.0, 0.0, 0.0, 1.0, 210.0/
DATA (X(8,J),J=1,6)/1.0, 0.0, 1.0, 0.0, 1.0, 247.0/
DATA (X(9,J),J=1,6)/0.0, 1.0, 0.0, 1.0, 0.0, 120.0/
DATA (X(10,J),J=1,6)/0.0, 1.0, 1.0, 1.0, 0.0, 171.0/
DATA (X(11,J),J=1,6)/0.0, 1.0, 1.0, 1.0, 0.0, 167.0/
DATA (X(12,J),J=1,6)/0.0, 0.0, 1.0, 1.0, 0.0, 172.0/
DATA (X(13,J),J=1,6)/1.0, 1.0, 1.0, 0.0, 1.0, 247.0/
DATA (X(14,J),J=1,6)/1.0, 1.0, 1.0, 0.0, 1.0, 252.0/
DATA (X(15,J),J=1,6)/1.0, 0.0, 1.0, 0.0, 1.0, 248.0/
DATA (X(16,J),J=1,6)/0.0, 1.0, 1.0, 1.0, 0.0, 169.0/
DATA (X(17,J),J=1,6)/0.0, 1.0, 0.0, 0.0, 0.0, 104.0/
DATA (X(18,J),J=1,6)/0.0, 1.0, 1.0, 1.0, 0.0, 166.0/
DATA (X(19,J),J=1,6)/0.0, 1.0, 1.0, 1.0, 0.0, 168.0/
DATA (X(20,J),J=1,6)/0.0, 1.0, 1.0, 0.0, 0.0, 148.0/
DATA INDKEY/1, 3, 4/
!
IRET = 1
CALL SROWR (X, INDKEY, IPERM, NGROUP, NI, IRET=IRET)
K = 1
DO 20 I=1, NGROUP
DO 10 J=1, NI(I)
IGROUP(IPERM(K)) = I
K = K + 1
10 CONTINUE
20 CONTINUE
IREP = 0
IRSP = 6
DFE = 16.0
SSE = 163.93
CALL RLOFE (X, IREP, INDREP, IRSP, DFE, SSE, IGROUP, NGROUP, TESTLF)
CALL UMACH (2, NOUT)
WRITE (NOUT,*) ' NGROUP = ', NGROUP
CALL WRIRN ('IGROUP', IGROUP, 1, NOBS, 1)
WRITE (NOUT,*) ' '
WRITE (NOUT,99999) ' Test for Lack of '// &
'Fit'
WRITE (NOUT,99999) ' Sum of Mean '// &
' Prob. of'
WRITE (NOUT,99999) ' Source of Error DF Squares Square '// &
' F Larger F'
WRITE (NOUT,99999) ' Lack of Fit ', TESTLF(1), TESTLF(4), &
TESTLF(7), TESTLF(9), TESTLF(10)
WRITE (NOUT,99999) ' Expanded model ', TESTLF(2), TESTLF(5), &
TESTLF(8)
WRITE (NOUT,99999) ' Original model ', TESTLF(3), TESTLF(6)
99999 FORMAT (A, F5.1, F9.1, F8.2, F7.3, F10.3)
END
Output
 
NGROUP = 6
 
IGROUP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
6 6 6 4 5 4 5 6 2 4 4 4 6 6 6 4 1 4 4 3
 
Test for Lack of Fit
Sum of Mean Prob. of
Source of Error DF Squares Square F Larger F
Lack of Fit 2.0 20.5 10.25 1.001 0.393
Expanded model 14.0 143.4 10.24
Original model 16.0 163.9
Published date: 03/19/2020
Last modified date: 03/19/2020