# 練習課題の確認コード。sample-dataの親フォルダから実行します。

d <- read.csv("sample-data/sample_pearson_correlation_sleep_fatigue.csv")
t <- cor.test(d$sleep_hours,d$fatigue_score)
answer <- list(correlation=data.frame(n=nrow(d),r=unname(t$estimate),lower=t$conf.int[1],upper=t$conf.int[2]),
 endpoints=d[c(which.min(d$sleep_hours),which.max(d$sleep_hours)),])
plot(d$sleep_hours,d$fatigue_score,xlab="Sleep (hours)",ylab="Fatigue score")
abline(lm(fatigue_score~sleep_hours,data=d))

print(answer)
