Problems with the identify function in the lme residuals

207 views Asked by At

I'm having problems with the identify function. I am trying to identify the points on the residuals graph of the adjusted model, however the identify function is giving an error.

library(mgcv)
require(gamm4)

fit4.gamm <- gamm(log(massaseca)~factor(Trat)+s(Tempo,k=10,bs="ps",m=2,
                                           by=factor(Trat)),
                  random=list(id=pdSymm(~Tempo)),data=dados)
comp_lme = fit4.gamm$lme

x11()
plot(comp_lme)

Error:

identify(comp_lme)
Error in xy.coords(x, y, setLab = FALSE) : 
  'x' is a list, but does not have components 'x' and 'y'
1

There are 1 answers

0
Axeman On BEST ANSWER

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)  #doesn't 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.