I did a multiple linear regression in R using the function lm and I want to use it to predict several values. So I\'m trying to use the function predict()
.
Here is
The problem is you defined v
as a new, distinct variable from t
when you fit your model. R doesn't remember how a variable was created so it doesn't know that v
is a function of t
when you fit the model. So when you go to predict values, it uses the existing values of v
which would have a different length than the new values of t
you are specifying.
Instead you want to fit
new <- data.frame(t=c(10, 20, 30))
LinReg <- lm(p ~ log(t) + I(1/t))
Pred <- predict(LinReg, new, interval="confidence")
If you did want v
to be a completely independent variable, then you would need to supply values for v
as well in your new
data.frame in order to predict p
.