I have created a linear model with the R program. And I have predicted a new variable using the model. Running the model, it will print the output of prediction 600 times! (the number of variables we have in the data set). Here is the code:
load(sports)
summary (sports)
ls(sports)
fit = lm(sport_score ~ sport_votes + sport_rating , data = sports)
summary(fit)
newdata = data.frame( sport_vote = 80, sport_rating = 7.7)
predict(fit, newdata, interval="predict")
How can I print the output just once?
It should be :
predict(fit, newdata=newdata, interval="predict")
The first newdata
is a parameter name. The second newdata
is the symbol name of your 'values' to be used.
If you don't give a value to the
newdata
parameter, it will just look for the default value, which as I said are the complete cases in
sports
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.