r – Problems with the identify function in the lme residuals

r – Problems with the identify function in the lme residuals

Take a reproducible example from the documentation:

library(mgcv)
library(gamm4)
n <- 200;sig <- 2
set.seed(0)
n.g <- 10
n<-n.g*10*4
## simulate smooth part...
dat <- gamSim(1,n=n,scale=2)
f <- dat$f
## simulate nested random effects....
fa <- as.factor(rep(1:10,rep(4*n.g,10)))
ra <- rep(rnorm(10),rep(4*n.g,10))
fb <- as.factor(rep(rep(1:4,rep(n.g,4)),10))
rb <- rep(rnorm(4),rep(n.g,4))
for (i in 1:9) rb <- c(rb,rep(rnorm(4),rep(n.g,4)))
## simulate auto-correlated errors within groups
e<-array(0,0)
for (i in 1:40) {
  eg <- rnorm(n.g, 0, sig)
  for (j in 2:n.g) eg[j] <- eg[j-1]*0.6+ eg[j]
  e<-c(e,eg)
}
dat$y <- f + ra + rb + e
dat$fa <- fa;dat$fb <- fb
## fit model .... 
b <- gamm(y~s(x0,bs=cr)+s(x1,bs=cr)+s(x2,bs=cr)+
            s(x3,bs=cr),data=dat,random=list(fa=~1,fb=~1),
          correlation=corAR1())

What you are trying:

plot(b$lme)      #lattice plot
identify(b$lme)  #doesnt work with lattice plots

Instead, make your own base plot:

plot(fitted(b$lme), resid(b$lme))
identify(fitted(b$lme), resid(b$lme))

This will work.

r – Problems with the identify function in the lme residuals

Leave a Reply

Your email address will not be published.