Get startedGet started for free

Manually calculating predictions with interactions

In order to understand how predict() works, it's time to calculate the predictions manually again. For this model, there are three separate lines to calculate for, and in each one, the prediction is an intercept plus a slope times the numeric explanatory value. The tricky part is getting the right intercept and the right slope for each case.

mdl_price_vs_both_inter and explanatory_data are available; dplyr and tidyr are available.

This exercise is part of the course

Intermediate Regression in R

View Course

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Get the coefficients from mdl_price_vs_both_inter
coeffs <- ___

# Get the intercept for 0 to 15 year age group
intercept_0_15 <- ___

# Get the intercept for 15 to 30 year age group
intercept_15_30 <- ___

# Get the intercept for 30 to 45 year age group
intercept_30_45 <- ___

# Get the slope for 0 to 15 year age group
slope_0_15 <- ___

# Get the slope for 15 to 30 year age group
slope_15_30 <- ___

# Get the slope for 30 to 45 year age group
slope_30_45 <- ___
Edit and Run Code