Rtist
Rtist

Reputation: 4205

Add predictions using models with interactions in R

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)?

Upvotes: 0

Views: 65

Answers (0)

Related Questions