1

Based on this question:

Predict() - Maybe I'm not understanding it

Does anyone understand on what criteria I choose my values I want to predict for my newdataframe?

model <- lm(Coupon ~ Total, data=df)
new.df <- data.frame(Total=c(79037022, 83100656, 104299800))
predict(model, new.df)

They are using this code and I just cannot get behind it where the 3 values: "79037022, 83100656, 104299800" come from that eventually are put in

predict(model, new.df)

Thank you! :)

bli12blu12
  • 357
  • 2
  • 11

1 Answers1

3

predict works when you have some new data without response and you want to get the result from our model. Sometimes you may put the origin data into the predict function because you want to get something like confidence interval or prediction interval. These 3 values: "79037022, 83100656, 104299800" appears just because you are interested in the response when the input is these three values. You can use other values of course and R will give you the result. But remember, the model usually works only when the new data is not far from the original data.

VicaYang
  • 544
  • 3
  • 17
  • 1
    predict functions just provide a method to calculate the mean, variance, CI, PI of response base on the model and the input. You can get the same result by manually compute y=ax+b. So it will not tell you whether your model is good. To check whether your model is proper, you can do lots of diagnostics the test. Then you need to read some book about that. – VicaYang Jun 12 '18 at 09:11
  • 1
    You don't have to use your whole dataset to build the model. Keep some data (randomly) in order to test it. You can find more info if you search for train / test sets for model building and valitation. – AntoniosK Jun 12 '18 at 09:21
  • @AntoniosK Thank you! Yes just as AntoniosK said, use cross-validation is also a useful way to detect whether our model works fine, especially if you have lots of data. You can visit [Cross-validation (statistics)](https://en.wikipedia.org/wiki/Cross-validation_(statistics)) for further learning – VicaYang Jun 12 '18 at 09:28