0

I am trying the following:

model_lr <- lm(metrics$Rev_Per_Player~metrics$Promo + metrics$DoW)

DoW <- wday(c(2,3,4,5,6,7,1), label = TRUE)
Promo <- c("","A","","B", "A","B", "")
Players <- c(3000,4000,4000,5000,6000,6000,7000)

new_ds <- data.frame(Promo,DoW,Players)

predict(model_lr,newdata = new_ds[,1:2])

I end up getting this warning:

Warning message:
'newdata' had 7 rows but variables found have 182 rows

All the explanations I found for this problem have to do with inapropriately naming the new datasets' input features, which is something that I am accounting for already.

Spacedman
  • 92,590
  • 12
  • 140
  • 224
YouthPrank
  • 23
  • 2
  • 6

1 Answers1

1

May I suggest you try: lm(Rev_Per_Player ~ Promo + DoW, data = metrics)

Example:

mod1 <- lm(mpg ~ hp, data = mtcars)
mod2 <- lm(mtcars$mpg ~ mtcars$hp)
newdata <- data.frame(mpg = 5, hp = 200)

## Works
predict(mod1, newdata)

## Doesn't Work
predict(mod2, newdata)

Why?

I believe it has to do with the fact that the model.frames are different depending on how you specify the variables used in the analysis. lm() uses the model.frame to actually run the regression algorithm.

Try the following. The naming conventions are different.

model.frame(mpg ~ hp, data = mtcars)
model.frame(mtcars$mpg ~ mtcars$hp)
jacobsg
  • 121
  • 6
  • I had tried it already but unfortunately it didn't work. I just decided to clean all the environment and run it again, which did the trick for me. – YouthPrank Nov 04 '17 at 16:02