[R] small problem with predict
Rolf Turner
rolf at math.unb.ca
Fri Jul 16 13:44:11 CEST 2004
You wrote:
> I have a small problem wit predict() for lm
>
> Let's say I have predictors x1 and x2, response y
>
> I want to predict for a new ds say
> dn<-data.frame(x1= seq(min(x1),max(x1),length=10),x2=rep(median(x2),10))
>
> predict(lm(y~x1+x2),dn,se.fit=T)
>
>
> Error message
> > Error: variables 'x1', 'x2' were specified differently from the fit
I tried your example (with a made-up ``original'' x1 and x2,
and y) and got a perfectly reasonable result, with no error
message.
Explicitly I did:
> x1 <- runif(42)
> x2 <- rnorm(42)
> y <- 4 + 2*x1 + 3*x2 + rnorm(42)
> dn <-data.frame(x1=seq(min(x1),max(x1),length=10),
x2=rep(median(x2),10))
> predict(lm(y~x1+x2),dn,se.fit=T)
No problema.
Are you sure you did what you say you did?
cheers,
Rolf Turner
rolf at math.unb.ca
More information about the R-help
mailing list