Skip to content
Prev 10806 / 20628 Next

GLMM doesn't do what it is supposed to (wrong results).

Jake Westfall <jake987722 at ...> writes:
of a herring*age interaction. Are
[snip]
 
 Jake Westfall is exactly right.
  It would be worth reading Schielzeth 2010 _Methods Ecol. Evol._ ...

database <- read.table("vandewalle.txt", header=TRUE)
## pups captured twise or more, before age 30, pos growth
data1 <- subset(database, numberofcaptures>=2 &
               age<30 & 
               growthrate>0)
data1$fliptag <- droplevels(data1$fliptag)
length(levels(data$fliptag)) ## 317

library(nlme)

## scale data
sdata <- data.frame(lapply(data1,
                function(x) if (is.numeric(x)) c(scale(x)) else x))
plyr::numcolwise(mean)(sdata,na.rm=TRUE)  ## double-check

## model 1 (unscaled)
mod1 <- lme(weight ~ age*herring,
            random=~1+age|fliptag,
            data=data1, method="REML")

anova(mod1, type="marginal")

## model 2 (scaled)
mod2 <- update(mod1,data=sdata)
pr <- function(x) {
    printCoefmat(summary(x)$tTable,digits=3,cs.ind=1:2,has.Pvalue=TRUE)
}
pr(mod1)
pr(mod2)
anova(mod2, type="marginal")
library(plyr)
hsum <- unlist(daply(data1,"fliptag",summarise,length(unique(herring))))
table(hsum)

library(ggplot2)
theme_set(theme_bw())
ggplot(data,aes(age,weight,colour=herring))+
    stat_sum(aes(size=factor(..n..)),alpha=0.5)

ggplot(data,aes(age,herring,colour=weight))+
    stat_sum(aes(size=factor(..n..)),alpha=0.5)+
    geom_smooth()