[R] predict for mlm does not work properly
Liaw, Andy
andy_liaw at merck.com
Fri Sep 19 14:06:09 CEST 2003
> From: ZABALZA-MEZGHANI Isabelle
>
> Hello,
>
> I've just fitted a model with multi-responses, and I get an
> object of class "lm" "mlm". My problem is that as soon as I
> invoke the predict method for a dataframe "newdata", the
> methods runs and give me back prediction at the fitting
> points but not for newdata.
What version of R and on what platform are you doing this? What were the
commands that you tried?
In R-1.7.1 on WinXPPro, I get:
> df <- data.frame(y1=rnorm(10), y2=rnorm(10), x1=rnorm(10),x2=rnorm(10))
> df2 <- data.frame(y1=rnorm(10), y2=rnorm(10), x1=rnorm(10),x2=rnorm(10))
> try.mlm <- lm(cbind(y1,y2) ~ x1+x2, data=df)
> predict(try.mlm)
y1 y2
1 -0.84974045 -0.19779627
2 -1.08128909 0.17851648
3 0.23572795 0.23167228
4 -0.65118764 0.09273186
5 -0.06741819 0.10396708
6 -0.88852774 -0.05386359
7 -0.21007585 0.07839343
8 -0.07061706 0.01714900
9 -0.67554077 0.07551119
10 -1.36196165 0.33502943
> predict(try.mlm, df2)
y1 y2
1 -0.66079093 2.772385e-02
2 -1.25399169 1.344038e-01
3 -0.64321234 3.044455e-02
4 0.29611924 -9.523683e-02
5 -1.01594522 1.557392e-01
6 -0.04513806 -1.529740e-01
7 -0.38954683 -2.780412e-03
8 -1.21828379 -2.460862e-01
9 -0.38511937 6.092239e-02
10 -0.34979146 -9.909837e-05
Seems fine to me.
Andy
> Does someone has an explanation for this behavior, and some
> ideas to make predict.mlm work efficiently.
>
> Thanks in advance
>
> Isabelle Zabalza-Mezghani
> IFP-Reservoir Engineering Department
> Rueil-Malmaison - France
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo> /r-help
>
More information about the R-help
mailing list