[R] Help on R Coding
andyer weng
nzandyer at gmail.com
Sun Oct 5 05:33:59 CEST 2008
Hi all,
I am kind of stuck of using Predict function in R to make prediction
for a model with continuous variable and categorial variables. i have
no problem making the model, the model is e.g.
cabbage.lm2<- lm(VitC ~ HeadWt + Date + Cult)
HeadWt is a continuous variable, Date and Culte are factors. Date have
three levels inside (d16,d20,d21), Cult has two levels(c39,c52). I
need to calculate a confidence interval for the mean VitC for each
combination of Date and Cult, fixing the value of HeadWt at the mean
for the corresponding cell. I have already proved that Cult and Date
are not interacted. the mean of HeadWt is also found. e.g.2.59
when i type
> new.df<-data.frame(HeadWt=2.59,Cultc52=1,Dated16=1)
> predict(cabbage.lm2,new.df, interval="confidence")
it has error comes up like this:
Error in model.frame.default(Terms, newdata, na.action = na.action,
xlev = object$xlevels) :
variable lengths differ (found for 'Cult')
In addition: Warning message:
'newdata' had 1 rows but variable(s) found have 60 rows
Is there anything I have done wrong?? Please help with the coding.
Thank you so much!!!
All the best.
Andyer.
More information about the R-help
mailing list