## anova mixed models resting 
#
# specify terms sequentially used "terms" in lm or glm
# 
# anova.mixed gives table of F-tests based on sequntial tests 
# and specified errror terms
#
# example:
# 

time <- gl(4,30,120)
grp <- gl(3,10,120)
ind <- gl(15,2,120)
y <- as.numeric(grp) * as.numeric(time)/10 + as.numeric(ind)/5 + rnorm(120)
y <- exp(y)
df <- data.frame(y,time,grp,ind)
summary(df)

fit <- lm(terms(y ~ grp + grp/ind + time + grp:time + ind:time, data=df, keep.order=T))
anova(fit)
anova.mixed(fit)
anova.mixed(fit,c(2,5))

fit <- glm(terms(y ~ grp + grp/ind + time + grp:time + ind:time, data=df, keep.order=T),family=quasipoisson)
anova(fit,test="F")
anova.mixed(fit)
anova.mixed(fit,c(2,5))



