상호작용이 있는 경우 예측을 수동으로 계산하기
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 <- ___