## 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)
Run the code above in your browser using DataLab