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
______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.