[R-sig-ME] lme predict function
HARSHANA KIRIELLA
harshana.kiriella at students.mq.edu.au
Sat Jul 30 17:06:10 CEST 2011
Dear R users,
I apologies in advance if this is really obvious question.
My problem can be best described by the following example. I believe
fm1 and fm2 are equivalent model and the data frame newOrth2 which
mirrors the data frame newOrth contains all the variables in model
fm2. When I try to use the predict function on fm2 I get an error
message:
“Error in model.frame.default(formula = ~QQ + age, data = list(Sex = c(2L, :
variable lengths differ (found for 'age')”
Could someone please help and explain to me what I am doing wrong.
#Method 1
fm1 <- lme(distance ~ age, Orthodont, random = ~ age | Subject)
newOrth <- data.frame(Sex = c("Male","Male","Female","Female","Male","Male"),
age = c(15, 20, 10, 12, 2, 4),
Subject = c("M01","M01","F30","F30","M04","M04"))
predict(fm1, newOrth, level = 0:1)
#Method 2
QQ<-cbind(1,Orthodont$age)
attr(QQ,"dimnames")<-list(NULL,c("a","W"))
fm2 <- lme( distance ~ age, Orthodont, random = list(Subject=pdSymm(~0+QQ)) )
newOrth2<- data.frame(Sex = c("Male","Male","Female","Female","Male","Male"),
age = c(15, 20, 10, 12, 2, 4),
QQa = c(1, 1, 1, 1, 1, 1),
QQW = c(15, 20, 10, 12, 2, 4),
Subject =
c("M01","M01","F30","F30","M04","M04"))
predict(fm2, newOrth2, level = 0:1)
Thanking you all in advance for your help,
Harshana Kiriella
More information about the R-sig-mixed-models
mailing list