null_dist_x %>%
visualize() +
shade_p_value(obs_stat = x_bar,
direction = "less") + # 섭취 후의 몸무게가 줄어들었는지를 보기 때문에 less
shade_confidence_interval(endpoints = null_dist_ci)
빨간 선이 p-value, 초록영역이 신뢰구간. 신뢰구간 안에 관측치가 들어와야 귀무가설 채택, 아래를 보면 아닌 것을 알 수 있음
-> 대체가설 채택(다이어트 약 복용 전후 몸무게 차이가 있다!)
2번 방법: t값 활용
1. 통계치 계산 및 분포 생성
t_cal <- pst_tb %>%
specify(response = 차이) %>%
hypothesize(null = "point",
mu = 0) %>%
calculate(stat = "t") %>%
print()
null_dist_t <- pst_tb %>% # 귀무가설 가정
specify(response = 차이) %>%
hypothesize(null = "point",
mu = 0) %>% # 검증값을 0으로 설정(복용 전후 몸무게 차이=0)
generate(reps = 1000, # 1000개 샘플링
type = "bootstrap") %>%
calculate(stat = "t")%>%
print() # 저장과 동시에 프린트
2. 신뢰구간 계산 및 시각화
ull_dist_ci <- null_dist_t %>%
get_ci(level = 0.95,
type = "percentile") %>%
print()
null_dist_t %>%
visualize(method = "both") + #both를 넣으면 이론적 분포(라인그래프)와 샘플의 값(히스토그램)을 비교
shade_p_value(obs_stat = t_cal, # obs_stat 관측치
direction = "less") + # 값이 너무 많이 떨어져 있어, 귀무가설 기각
shade_confidence_interval(endpoints = null_dist_ci)