I am suppose to use the predict function to predict when fjbjor
is 5.5 and I always get this warning message and I have tried many ways but it always comes so is there anyone who can see what I am doing wrong here
This is my code
fit.lm <- lm(fjbjor~amagn, data=bjor)
summary(fit.lm)
new.bjor<- data.frame(fjbjor=5.5)
predict(fit.lm,new.bjor)
and this comes out
1 2 3 4 5 6 7 8 9 10 11
5.981287 2.864521 9.988559 5.758661 4.645530 2.419269 4.645530 5.313409 6.871792 3.309773 4.200278
12 13 14 15 16
3.755026 5.981287 5.536035 1.974016 3.755026
Warning message: 'newdata' had 1 row but variables found have 16 rows
If anyone can see what is wrong I would be really thankful for the help.
Your model is
fjbjor ~ amagn
, wherefjbjor
is response andamagn
is covariate. Then yournewdata
isdata.frame(fjbjor=5.5)
.newdata
should be used to provide covariates rather than response.predict
will only retain columns of covariates innewdata
. For your specifiednewdata
, this will beNULL
. As a result,predict
will use the internal model frame for prediction, which returns you fitted values.The warning message is fairly clear.
predict
determines the expected number of predictions fromnrow(newdata)
, which is 1. But then what I described above happened so 16 fitted values are returned. Such mismatch produces the warning.Looks like the model you really want is:
amagn ~ fjbjor
.