The following link is my raw dataset.
I have created a linear regression model for it. And now, I would like to create a 95% confidence interval for the prediction that if "Weight=26".
My code was like the following:
MileWeight.lm <-lm(Mydata$Mileage~Mydata$Weight,
data = Mydata)
attach(Mydata)
newdata1 <-(Weight=26)
predict(MileWeight.lm, weight= 26 , interval = "confidence")
The output was 7 rows with "fit lwr upr", with a warning
'newdata' had 1 row but variables found have 7 rows
Have I missed anything? Any assistance would be highly appreciated! Thanks!
Data in dput
format.
Mydata <-
structure(list(Weight = c(8, 24.5, 27, 14.5, 28.5, 12.75, 21.25
), Mileage = c(7.69, 4.97, 4.56, 6.49, 4.34, 6.24, 4.45)), class = "data.frame", row.names = c(NA,
-7L))
Weight
notweight
, R is case sensitive. And please don'tattach
data. – Rui Barradasnewdata1 <-(Weight=26)
does not do what you seem to think it does. It could be with double==
but that would create a logical vector. The right way isnewdata1 <- data.frame(Weight = 26)
. As for books usingattach
they can (and generally do) have other good things, that is not one of them. – Rui Barradas