手动计算含交互项的预测值
为了理解 predict() 的工作方式,现在再次手动计算预测值。对于这个模型,需要分别计算三条直线。在每种情况下,预测值都等于截距加上斜率乘以数值型自变量。关键在于为每种情形选对截距和斜率。
mdl_price_vs_both_inter 和 explanatory_data 已提供;已加载 dplyr 和 tidyr。
本练习是课程的一部分
R 中级回归
交互式实操练习
通过完成这段示例代码来试试这个练习。
# 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 <- ___