[R] pdIdent and lme

TR Fanshawe t.fanshawe at lancaster.ac.uk
Fri Aug 14 10:43:23 CEST 2009


Dear all,
Can anyone please explain this apparent problem with using pdIdent in 
lme within a new function?

library(nlme)

y<-rnorm(30)
K<-matrix(rnorm(900),30,30)
df1<-data.frame(y=y,K=K,g=1)
df1$g<-as.factor(df1$g)
lme(fixed=y~1,random=list(g=pdIdent(~K-1)),data=df1,na.action=na.omit) 
#Works
rm(y,K,df1)

#Repeat the above within a single function f
f<-function(){
y<-rnorm(30)
K<-matrix(rnorm(900),30,30)
df1<-data.frame(y=y,K=K,g=1)
df1$g<-as.factor(df1$g)
lme(fixed=y~1,random=list(g=pdIdent(~K-1)),data=df1,na.action=na.omit)}
f() #Error in eval(expr, envir, enclos) : object "K" not found


Thanks for any help.
Tom.

------------------------------------
T.R. Fanshawe
Lancaster University




More information about the R-help mailing list