0

I am using modelr for adding predictions based on a linear regression model with interactions. The question is does add_predictions() work with interactions?

df <- tibble::tibble(
  x1 = sort(runif(100)),
  x2 = sort(runif(100)),
  y = 2*x1 + sqrt(x2) + rnorm(length(x1)))

mod_1 = lm(y~x1*x2, data = df) 
grid_values = expand_grid(x1 = seq(-1,1,0.1),x2 = seq(-1,1,0.1)) 

grid_values %>% add_predictions(mod_1) %>% 
  filter(x1==1 & x2==1)

From this example, it seems that it works. Yet, the question is does it always work? what with 3-way-interactions? What with oter kind of model (logistic)?

Rtist
  • 3,825
  • 2
  • 31
  • 40
  • Why don't you try and see what happens? – Limey Jul 19 '21 at 07:18
  • It worked here. That does not mean it will always work, especially for more complex models (3 way interactions) or with dummy coding and the like. – Rtist Jul 19 '21 at 07:37

0 Answers0