베이지안 모델 시각화하기
이전 연습 문제에서 곡의 나이(song_age)로 인기도(popularity)를 예측하는 베이지안 모델을 추정했어요. 이제 이 모델을 시각화해 봅시다. 이미 로드된 songs 데이터셋과 stan_model 객체를 사용해서, ggplot2로 데이터와 추정된 회귀선을 함께 보여 주는 시각화를 만들어 보세요.
이 연습은 강의의 일부입니다
rstanarm으로 배우는 Bayesian 회귀 모델링
연습 안내
- 모델 모수의 깔끔한 요약을
tidy_coef에 저장하세요 tidy_coef에서 추정된 절편과 기울기를 추출하세요- x축은
song_age, y축은popularity로 두고 데이터와 추정된 회귀선을 함께 보여 주는 플롯을 만드세요
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
# Save the model parameters
tidy_coef <- ___(stan_model)
# Extract intercept and slope
model_intercept <- tidy_coef$___[1]
model_slope <- tidy_coef$___[2]
# Create the plot
ggplot(songs, aes(x = ___, y = ___)) +
geom_point() +
geom_abline(intercept = ___, slope = ___)