Description Usage Arguments Details Value Author(s) References See Also Examples

Estimate/Predict random effects employing ANOVA-type estimation and obtain generalized least squares estimates of fixed effects for any linear mixed model including random models and linear models.

1 2 3 |

`form` |
(formula) specifying the linear mixed model (fixed and random part of the model), all random terms need to be enclosed by round brackets. Any variable not being bracketed will be considered as fixed. Interaction terms containing at least one random factor will automatically be random (Piepho et al. 2003). All terms appearing in the model (fixed or random) need to be compliant with the regular expression "^[^[\.]]?[[:alnum:]_\.]*$", i.e. they may not start with a dot and may then only consist of alpha-numeric characters, dot and underscore. Otherwise, an error will be issued. |

`Data` |
(data.frame) containing all variables referenced in 'form', note that variables can only be of type "numeric", "factor" or "character". The latter will be automatically converted to "factor". |

`by` |
(factor, character) variable specifying groups for which the analysis should be performed individually, i.e. by-processing |

`VarVC.method` |
(character) string specifying whether to use the algorithm given in Searle et al. (1992) which corresponds to |

`SSQ.method` |
(character) string specifying the method used for computing ANOVA Type-1 sum of squares and respective degrees of freedom.
In case of "sweep" funtion |

`NegVC` |
(logical) FALSE = negative variance component estimates (VC) will be set to 0 and they will not contribute to the total variance (as done e.g. in SAS PROC NESTED, conservative estimate of total variance). The original ANOVA estimates can be found in element 'VCoriginal'. The degrees of freedom of the total variance are based on adapted mean squares (MS) (see details). TRUE = negative variance component estimates will not be set to 0 and they will contribute to the total variance (original definition of the total variance). |

`quiet` |
(logical) TRUE = will suppress any warning, which will be issued otherwise |

`order.data` |
(logical) TRUE = class-variables will be ordered increasingly, FALSE = ordering of class-variables will remain as is |

A Linear Mixed Model, noted in standard matrix notation, can be written as y = Xb + Zg + e, where
*y* is the column vector of observations, *X* and *Z* are design matrices assigning fixed (*b*),
respectively, random (*g*) effects to observations, and *e* is the column vector of residual errors.
Whenever there is an intercept in the model, i.e. the substring "-1" is not part of the model formula, the same
restriction as in SAS PROC MIXED is introduced setting the last fixed effect equal to zero. Note, that the results
of an linear contrasts are not affected by using an intercept or not, except that constrained fixed effects cannot
be part of such contrasts (one could use the intercept estimated instead).

Here, no further restrictions on the type of model are made. One can fit mixed models as well as random models, which
constitute a sub-set of mixed models (intercept being the only fixed effect). Variables must be either of type "numeric"
or "factor". "character" variables are automatically converted to factors and the response variable has to be numeric, of course.
In case that 'class(Data[,i])' is neither one of these three options, an error is issued.
Even simple linear models can be fitted, i.e. models without a random part (without *Zg*) besides the
residual errors. In this case, an Analysis of Variance (ANOVA) table is computed in the same way as done by function 'anova.lm'.

One drawback of using ANOVA-type estimation of random effects is, that random effects are independent, i.e they have
zero covariance by definition *cov(g_i,g_j) = 0*. Another one is that estimated variance components may become negative
under certain conditions. The latter situation is addressed by setting negative variance estimates equal to zero and adapting
ANOVA mean squares (MS) as *MS = C * VC*, where *C* is a coefficient matrix and a function of the design matrix *[X Z]*
and *VC* is the column-vector of adapted variance components. The Satterthwaite approximation of total degrees of freedom
(DF for total variance) will use adapted *MS*-values.

Note, that setting negative VCs equal to zero results in a conservative estimate of the total variance, i.e. it will be larger than the estimate including the negative VC(s). Use parameter 'NegVC=TRUE' to explicitly allow negative variance estimates.

For further details on ANOVA Type-I estimation methods see `anovaVCA`

.

(VCA) object

Andre Schuetzenmeister [email protected]

Searle, S.R, Casella, G., McCulloch, C.E. (1992), Variance Components, Wiley New York

Goodnight, J.H. (1979), A Tutorial on the SWEEP Operator, The American Statistician, 33:3, 149-158

Giesbrecht, F.G. and Burns, J.C. (1985), Two-Stage Analysis Based on a Mixed Model: Large-Sample Asymptotic Theory and Small-Sample Simulation Results, Biometrics 41, p. 477-486

H.P.Piepho, A.Buechse and K.Emrich (2003), A Hitchhiker's Guide to Mixed Models for Randomized Experiments, J.Agronomy & Crop Science 189, p. 310-322

Gaylor,D.W., Lucas,H.L., Anderson,R.L. (1970), Calculation of Expected Mean Squares by the Abbreviated Doolittle and Square Root Methods., Biometrics 26 (4): 641-655

SAS Help and Documentation PROC MIXED, SAS Institute Inc., Cary, NC, USA

`anovaVCA`

, `VCAinference`

, `remlVCA`

, `remlMM`

`ranef`

, `fixef`

, `vcov`

, `vcovVC`

,
`test.fixef`

, `test.lsmeans`

, `plotRandVar`

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 | ```
## Not run:
data(dataEP05A2_2)
# assuming 'day' as fixed, 'run' as random
anovaMM(y~day/(run), dataEP05A2_2)
# assuming both as random leads to same results as
# calling anovaVCA
anovaMM(y~(day)/(run), dataEP05A2_2)
anovaVCA(y~day/run, dataEP05A2_2)
# use different approaches to estimating the covariance of
# variance components (covariance parameters)
dat.ub <- dataEP05A2_2[-c(11,12,23,32,40,41,42),] # get unbalanced data
m1.ub <- anovaMM(y~day/(run), dat.ub, SSQ.method="qf", VarVC.method="scm")
m2.ub <- anovaMM(y~day/(run), dat.ub, SSQ.method="qf", VarVC.method="gb") # is faster
V1.ub <- round(vcovVC(m1.ub), 12)
V2.ub <- round(vcovVC(m2.ub), 12)
all(V1.ub == V2.ub)
# make it explicit that "gb" is faster than "scm"
# compute variance-covariance matrix of VCs 10-times
system.time(for(i in 1:500) vcovVC(m1.ub)) # "scm"
system.time(for(i in 1:500) vcovVC(m2.ub)) # "gb"
# fit a larger random model
data(VCAdata1)
fitMM1 <- anovaMM(y~((lot)+(device))/(day)/(run), VCAdata1[VCAdata1$sample==1,])
fitMM1
# now use function tailored for random models
fitRM1 <- anovaVCA(y~(lot+device)/day/run, VCAdata1[VCAdata1$sample==1,])
fitRM1
# there are only 3 lots, take 'lot' as fixed
fitMM2 <- anovaMM(y~(lot+(device))/(day)/(run), VCAdata1[VCAdata1$sample==2,])
# the following model definition is equivalent to the one above,
# since a single random term in an interaction makes the interaction
# random (see the 3rd reference for details on this topic)
fitMM3 <- anovaMM(y~(lot+(device))/day/run, VCAdata1[VCAdata1$sample==2,])
# fit same model for each sample using by-processing
lst <- anovaMM(y~(lot+(device))/day/run, VCAdata1, by="sample")
lst
# fit mixed model originally from 'nlme' package
library(nlme)
data(Orthodont)
fit.lme <- lme(distance~Sex*I(age-11), random=~I(age-11)|Subject, Orthodont)
# re-organize data for using 'anovaMM'
Ortho <- Orthodont
Ortho$age2 <- Ortho$age - 11
Ortho$Subject <- factor(as.character(Ortho$Subject))
fit.anovaMM1 <- anovaMM(distance~Sex*age2+(Subject)*age2, Ortho)
# use simplified formula avoiding unnecessary terms
fit.anovaMM2 <- anovaMM(distance~Sex+Sex:age2+(Subject)+(Subject):age2, Ortho)
# and exclude intercept
fit.anovaMM3 <- anovaMM(distance~Sex+Sex:age2+(Subject)+(Subject):age2-1, Ortho)
# compare results
fit.lme
fit.anovaMM1
fit.anovaMM2
fit.anovaMM3
# are there a sex-specific differences?
cmat <- getL(fit.anovaMM3, c("SexMale-SexFemale", "SexMale:age2-SexFemale:age2"))
cmat
test.fixef(fit.anovaMM3, L=cmat)
# former versions of the package used R-function 'lm' and 'anova',
# which is significantly slower for sufficiently large/complex models
data(realData)
datP1 <- realData[realData$PID==1,]
system.time(anova.lm.Tab <- anova(lm(y~lot/calibration/day/run, datP1)))
# using the quadratic forms approach for estimating ANOVA Type-1 sums of squares
system.time(anovaMM.Tab1 <- anovaMM(y~lot/calibration/day/run, datP1, SSQ.method="qf"))
# using the sweeping approach for estimating ANOVA Type-1 sums of squares
# this is now the default setting (Note: only "gb" method works as VarVC.method)
# Also see ?anovaVCA for a comparison of the computational efficiency of "qf" and "sweep".
system.time(anovaMM.Tab2 <- anovaMM(y~lot/calibration/day/run, datP1, SSQ.method="sweep"))
# compare results, note that the latter corresponds to a linear model,
# i.e. without random effects. Various matrices have already been computed,
# e.g. "R", "V" (which are identical in this case).
anova.lm.Tab
anovaMM.Tab1
anovaMM.Tab2
## End(Not run)
``` |

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.