Hi Hugo,

In this example,  the problem is due to cluster="One Transition, Middle
Income" all the time.

I don't undertand why this is a problem. If I want to get predict() to work
I have to include all variables from the model, right? Obviously, the input
data in the model's call will not include factor set to the same values for
all cases. Yet, if I want to get predictions just for subset of the data,
or for new observations, I may be interested in only in cases where some
factor is always set to be the same.  Does it make sense? How can I get
predictions in that case?



On Sat, May 26, 2012 at 9:08 AM, <Hugo.Mildenberger@web.de> wrote:

> Antonio,
>
> > Error in `contrasts<-`(`*tmp*`, value = contr.funs[1 + isOF[nn]]) :
> >   contrasts can be applied only to factors with 2 or more levels
>
> this is probably a consequence of the variable 'ttd' being
> constantly zero.
>
> Best
>
>
> On Fri, 25 May 2012 17:29:35 -0700
> "Antonio P. Ramos" <ramos.grad.student@gmail.com> wrote:
>
> > ---------- Forwarded message ----------
> > From: Antonio P. Ramos <ramos.grad.student@gmail.com>
> > Date: Fri, May 25, 2012 at 5:29 PM
> > Subject: error while trying to get predictions from a lme object
> > To: Antonio Pedro Ramos <ramos.grad.student@gmail.com>
> >
> >
> > Another example of the error I am taking about:
> >
> > > # the variables from this models dependens
> > > model <- lme(log(child_mortality) ~ as.factor(cluster)*time +
> > +              my.new.time.one.transition.low.and.middle + ttd +
> > +              maternal_educ+ log(IHME_id_gdppc) + hiv_prev-1,
> > +
>  merged0,na.action=na.omit,method="ML",weights=varPower(form
> > = ~ time),
> > +              random= ~ time| country.x,
> > +              correlation=corAR1(form = ~ time),
> > +              control=lmeControl(msMaxIter = 200, msVerbose = TRUE))
> > >
> >
> >
> > > # create a toy data set
> > > test.pred0 <-
> >  expand.grid(time=20:29,country.x=c("Poland","Brazil","Argentina"))
> > > z0 <-
> >
> as.data.frame(cbind(my.new.time.one.transition.low.and.middle=c(0,0,0,0,0,0,1,2,3,4),
> > +       ttd=c(0,0,0,0,0,0,1,0,0,0),
> > +       maternal_educ=seq(from=10.0, to=12.0, length.out=10),
> > +       IHME_id_gdppc=log(seq(from=5000, to=8000, length.out=10)),
> > +       hiv_prev=rep(.005,10),cluster=rep("One Transition, Middle
> > Income",10)))
> > >
> > > z <- rbind(z0,z0,z0)
> > > test.pred <- cbind(test.pred0,z)
> > > # check
> > > head(test.pred)
> >   time country.x my.new.time.one.transition.low.and.middle ttd
> >  maternal_educ    IHME_id_gdppc hiv_prev
> > 1   20    Poland                                         0   0
> >   10 8.51719319141624    0.005
> > 2   21    Poland                                         0   0
> > 10.2222222222222 8.58173171255381    0.005
> > 3   22    Poland                                         0   0
> > 10.4444444444444 8.64235633437024    0.005
> > 4   23    Poland                                         0   0
> > 10.6666666666667 8.69951474821019    0.005
> > 5   24    Poland                                         0   0
> > 10.8888888888889 8.75358196948047    0.005
> > 6   25    Poland                                         0   0
> > 11.1111111111111 8.80487526386802    0.005
> >                         cluster
> > 1 One Transition, Middle Income
> > 2 One Transition, Middle Income
> > 3 One Transition, Middle Income
> > 4 One Transition, Middle Income
> > 5 One Transition, Middle Income
> > 6 One Transition, Middle Income
> > >
> > # run the predictions
> > > predict(model,test.pred,level=0)
> > Error in `contrasts<-`(`*tmp*`, value = contr.funs[1 + isOF[nn]]) :
> >   contrasts can be applied only to factors with 2 or more levels
> >
> > Thank you!
> >
> > Antonio Pedro.
> >
> >       [[alternative HTML version deleted]]
> >
> > _______________________________________________
> > R-sig-mixed-models@r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models
>
>
> --
> Hugo Mildenberger <hm@zotac.lan>
>

	[[alternative HTML version deleted]]

