[R] question about predictions with linear models
Rajarshi Guha
rxg218 at psu.edu
Wed Oct 1 18:55:03 CEST 2003
Hi,
this question is probably very obvious but I just cant see where I
might be going wrong.
I'm using the lm() function to generate a linear model and then make
predictions using a different set of data.
To generate the model I do (tdata & pdata are matrices of observations
and parameters, tdepv, pdepv are response vectors)
x <- as.data.frame(tdata)
x$tdepv <- tdepv
lnegth(tdepv) = 140
model <- lm(x$tdepv ~ x$V1 + x$V2 + x$V3 + x$V4, x)
pred <- predict(model, x)
length(pred) = 140
y <- as.data.frame(pdata)
y$pdepv <- pdepv
length(pdepv) = 16
pred <- predict(model, y)
length(pred) = 140
But I expect that length(pred) = 16
Why do I get a different length? Furthermore, the original formula
specified the variable tdepv which is not in the dataframe that I send
to predict() - should I also make a variable called tdepv in the
dataframe y?
Thanks,
-------------------------------------------------------------------
Rajarshi Guha <rxg218 at psu.edu> <http://jijo.cjb.net>
GPG Fingerprint: 0CCA 8EE2 2EEB 25E2 AB04 06F7 1BB9 E634 9B87 56EE
-------------------------------------------------------------------
The way to love anything is to realize that it might be lost.
More information about the R-help
mailing list