data("wafers")
## Gamma GLMM with log link
m1 <- HLfit(y ~X1+X2+X1*X3+X2*X3+I(X2^2)+(1|batch),family=Gamma(log),
resid.model = ~ X3+I(X3^2) ,data=wafers,method="ML")
m2 <- update(m1,formula.= ~ . -I(X2^2))
#
anova(m1,m2) # LRT
## 'anova' (Wald chi-squared tests...) for GLMM or model with a 'resid.model'
anova(m1)
## ANOVA table for GLM
# Gamma example, from McCullagh & Nelder (1989, pp. 300-2), as in 'glm' doc:
clotting <- data.frame(
u = c(5,10,15,20,30,40,60,80,100),
lot1 = c(118,58,42,35,27,25,21,19,18),
lot2 = c(69,35,26,21,18,16,13,12,12))
spglm <- fitme(lot1 ~ log(u), data = clotting, family = Gamma, method="REML")
anova(spglm, test = "F")
anova(spglm, test = "Cp")
anova(spglm, test = "Chisq")
anova(spglm, test = "Rao")
## ANOVA table for LMM
if(requireNamespace("lmerTest", quietly=TRUE)) {
lmmfit <- fitme(y ~X1+X2+X1*X3+X2*X3+I(X2^2)+(1|batch),data=wafers)
print(anova(lmmfit)) # => Satterthwaite method, here giving p-values
# quite close to traditional t-tests given by:
summary(lmmfit, details=list(p_value=TRUE))
}
## Using resp_testfn argument for bootstrap LRT:
if (FALSE) {
set.seed(1L)
d <- data.frame(success = rbinom(10, size = 1, prob = 0.9), x = 1:10)
xx <- cbind(1,d$x)
table(d$success)
m_x <- fitme(success ~ x, data = d, family = binomial())
m_0 <- fitme(success ~ 1, data = d, family = binomial())
#
# Bootstrap LRTs:
anova(m_x, m_0, boot.repl = 100,
resp_testfn=function(y) {! is_separated(xx,as.numeric(y),verbose=FALSE)})
}
#### Various cases were asymptotic tests may be unreliable:
set.seed(123)
dat <- data.frame(g = rep(1:10, e = 10), x = (x<-rnorm(100)),
y = 0.1 * x + rnorm(100))
m0 <- fitme(y ~ 1, data=dat)
## (1) Models differing both by fixed and random effects:
#
# (note the warning for variance at boundary):
#
if (spaMM.getOption("example_maxtime")>11) {
m <- fitme(y ~ x + (1|g), data=dat)
LRT(m,m0, boot.repl = 199L)
}
## See help("get_RLRsim_args") for a fast and accurate test procedure
## (2) Models differing also by residual-dispersion models:
#
if (spaMM.getOption("example_maxtime")>25) {
m <- fitme(y ~ x + (1|g), data=dat, resid.model= ~x)
LRT(m,m0, boot.repl = 99L)
}
## (3) Models differing (also) by their random-effects in resid.model:
#
m <- fitme(y ~ x, data=dat, resid.model= ~1+(1|g))
LRT(m,m0) # no test performed
Run the code above in your browser using DataLab