Learn R Programming

VCA (version 1.3.4)

anovaDF: ANOVA Type-I Degrees of Freedom.

Description

Depending on the type of model, e.g. fully-nested, crossed-nested, etc. algorithms are applied which are believed to be reasonably fast for the respective type of model, whenever ANOVA sums of squares are constructed via quadradic forms in y (SSQ.method="qf").

Usage

anovaDF(form, Data, Zmat, Amat, tol = 1e-08)

Arguments

form

(formula) object specifying the model for which ANOVA DFs are requested

Data

(data.frame) with all variables appearing in 'form'

Zmat

(list) of Z-matrices, representing the design matrices of all model-terms, interpreted as fixed effects (number of columns represent number of unique levels)

Amat

(list) of A-matrices, generating ANOVA sums of squares as quadratic forms in \(y\), see anovaVCA for details

tol

(numeric) constant, representing a numeric tolerance used in computing the rank of \(A\)-matrices

Details

This function is not meant to be called directly. It is invoked by functions anovaVCA and anovaMM.

Computing the rank of a corresponding A-matrix, which generates ANOVA sum of squares as quadratic form in \(y\) is a general method applicable to all types of models. This usually envokes a singular value decomposition of \(A\) which makes it rather slow. Here, we try to speed up things by differentiating three classes of models, 1) fully-nested models where DFs are computed as the number of factor-levels minus the sum of higher order terms minus 1, 2) models with only main factors (in this case anova.lm is used), 3) models with main factors and interaction terms. Main factors DFs are computed employing function anova.lm. DFs for interaction terms are computed by determining the rank of \(A\)-matrices. There are certain designs for which anova.lm becomes very fast (see examples section of anovaMM).

Examples

Run this code
# NOT RUN {
# fully-nested design
data(realData)
datP1 <- realData[realData$PID==1,]
system.time(anova.lm.Tab1 <- anova(lm(y~lot/calibration/day/run, datP1)))
system.time(anovaMM.Tab1  <- anovaMM(y~lot/calibration/day/run, datP1))
anova.lm.Tab1
anovaMM.Tab1

# use SSQ.method="qf" (based on quadratic forms)
system.time(anovaMM.Tab1.qf  <- anovaMM(y~lot/calibration/day/run, datP1, SSQ.method="qf"))

# compute degrees of freedom
VCA:::anovaDF( y~lot/calibration/day/run, datP1,
				  Zmat=anovaMM.Tab1.qf$Matrices$Z,
				  Amat=anovaMM.Tab1.qf$Matrices$A)

# design with only main-factors
system.time(anova.lm.Tab2 <- anova(lm(y~lot+calibration+day+run, datP1)))
system.time(anovaMM.Tab2  <- anovaMM(y~lot+calibration+day+run, datP1))
anova.lm.Tab2
anovaMM.Tab2

# use SSQ.method="qf" (based on quadratic forms)
system.time(anovaMM.Tab2.qf  <- anovaMM(y~lot+calibration+day+run, datP1, SSQ.method="qf"))

# compute degrees of freedom
VCA:::anovaDF( y~lot+calibration+day+run, datP1,
				  Zmat=anovaMM.Tab2.qf$Matrices$Z,
				  Amat=anovaMM.Tab2.qf$Matrices$A)

# design with main-factors and interactions
system.time(anova.lm.Tab3 <- anova(lm(y~(lot+calibration)/day/run, datP1)))
system.time(anovaMM.Tab3  <- anovaMM( y~(lot+calibration)/day/run, datP1))
anova.lm.Tab3
anovaMM.Tab3

# use SSQ.method="qf" (based on quadratic forms)
system.time(anovaMM.Tab3.qf  <- anovaMM(y~(lot+calibration)/day/run, datP1, SSQ.method="qf"))

# compute degrees of freedom
VCA:::anovaDF( y~(lot+calibration)/day/run, datP1,
				  Zmat=anovaMM.Tab3.qf$Matrices$Z,
				  Amat=anovaMM.Tab3.qf$Matrices$A)
# }

Run the code above in your browser using DataLab