[R] Predicting a single observatio using LME

Rebecca Sela rsela at stern.nyu.edu
Sat Jun 7 07:39:51 CEST 2008


When I use a model fit with LME, I get an error if I try to use "predict" with a dataset consisting of a single line.

For example, using this data:
> simpledata
              Y t D ID
1  -1.464740870 1 0  1
2   1.222911373 2 0  1
3  -0.605996798 3 0  1
4   0.155692707 4 0  1
5   3.849619772 1 0  2
6   4.289213902 2 0  2
7   2.369407737 3 0  2
8   2.249052533 4 0  2
9   0.920044316 1 0  3
10  2.003262622 2 0  3
11  0.003833438 3 0  3
12  1.578300927 4 0  3
13 -0.842322442 1 1  4
14 -0.657256158 2 1  4
15  1.504491575 3 1  4
16  2.896007045 4 1  4
17  0.990505440 1 1  5
18  2.722942793 2 1  5
19  4.395861278 3 1  5
20  4.849296475 4 1  5
21  3.049616421 1 1  6
22  2.874405962 2 1  6
23  4.359511097 3 1  6
24  6.165419699 4 1  6

This happened:
> testLME <- lme(Y~t+D,data=simpledata,random=~1|ID)
> predict(testLME, simpledata[1,])
Error in val[revOrder, level + 1] : incorrect number of dimensions

This has occurred with other datasets as well.  Is this a bug in the code, or am I doing something wrong?

(Also, is there a way to parse a formula of a type given to "random"?  For example, given ~1+t|ID, I'd like to be able to extract all the variable names to the left of | and to the right of |, the way one can with a normal formula.)

Thanks in advance!

Rebecca



More information about the R-help mailing list