if (FALSE) {
library(agridat)
data(kenward.cattle)
dat <- kenward.cattle
# Profile plots
libs(lattice)
foo1 <- xyplot(weight~day|trt, data=dat, type='l', group=animal,
xlab="Day", ylab="Animal weight", main="kenward.cattle")
print(foo1)
# ----------
# lme4. Fixed treatment intercepts, treatment polynomial trend.
# Random deviation for each animal
libs(lme4)
m1a <-lmer(weight ~ trt*poly(day, 4) + (1|animal), data=dat,
REML = FALSE)
# Change separate polynomials into common polynomial
m1b <-lmer(weight ~ trt + poly(day, 4) + (1|animal), data=dat,
REML = FALSE)
# Drop treatment differences
m1c <-lmer(weight ~ poly(day, 4) + (1|animal), data=dat,
REML = FALSE)
anova(m1a, m1b, m1c) # Significant differences between trt polynomials
# Overlay polynomial predictions on plot
libs(latticeExtra)
dat$pred <- predict(m1a, re.form=NA)
foo1 + xyplot(pred ~ day|trt, data=dat,
lwd=2, col="black", type='l')
# A Kenward-Roger Approximation and Parametric Bootstrap
# libs(pbkrtest)
# KRmodcomp(m1b, m1c) # Non-signif
# Model comparison of nested models using parametric bootstrap methods
# PBmodcomp(m1b, m1c, nsim=500)
## Parametric bootstrap test; time: 13.20 sec; samples: 500 extremes: 326;
## large : weight ~ trt + poly(day, 4) + (1 | animal)
## small : weight ~ poly(day, 4) + (1 | animal)
## stat df p.value
## LRT 0.2047 1 0.6509
## PBtest 0.2047 0.6527
# -----------
# ASREML approach to model. Not final by any means.
# Maybe a spline curve for each treatment, plus random deviations for each time
if(require("asreml", quietly=TRUE)){
libs(asreml)
m1 <- asreml(weight ~ 1 + lin(day) + # overall line
trt + trt:lin(day), # different line for each treatment
data=dat,
random = ~ spl(day) + # overall spline
trt:spl(day) + # different spline for each treatment
dev(day) + trt:dev(day) ) # non-spline deviation at each time*trt
p1 <- predict(m1, data=dat, classify="trt:day")
p1 <- p1$pvals
foo2 <- xyplot(predicted.value ~ day|trt, p1, type='l', lwd=2, lty=1, col="black")
libs(latticeExtra)
print(foo1 + foo2)
# Not much evidence for treatment differences
# wald(m1)
## Df Sum of Sq Wald statistic Pr(Chisq)
## (Intercept) 1 37128459 139060 <2e-16 ***
## trt 1 455 2 0.1917
## lin(day) 1 570798 2138 <2e-16 ***
## trt:lin(day) 1 283 1 0.3031
## residual (MS) 267
# lucid::vc(m1)
## effect component std.error z.ratio constr
## spl(day) 25.29 24.09 1 pos
## dev(day) 1.902 4.923 0.39 pos
## trt:spl(day)!trt.var 0.00003 0.000002 18 bnd
## trt:dev(day)!trt.var 0.00003 0.000002 18 bnd
## R!variance 267 14.84 18 pos
}
}
Run the code above in your browser using DataLab