0

I am attempting to follow thisn step-by-step guide in order to create a prediction from my dataset. https://www.statology.org/predict-in-r-multiple-regression/. However, when i print these following lines of code I get thousands of output when I only want one.

model <- lm(Regresjon$Days~Regresjon$Age+Regresjon$Month)
summary(model)
new <- data.frame(Age=c(50), Month=c(250))
predict(model, newdata=new)

All data is numerical. Any tips?

Thomasiko
  • 39
  • 4
  • I would be surprised if you were getting thousands. `summary(model)` should print the fitted model while `predict(model, newdata=new)` should print 1 line. – Oliver Nov 03 '22 at 08:15
  • You need to use the `data` parameter of `lm`: `model <- lm(Days ~ Age + Month, data = Regresjon)` You shouldn't use `$` within a formula. If you fix that, `predict` will use `new` instead of just giving you the fitted values. – Roland Nov 03 '22 at 08:24

0 Answers0