處理 R 輸出(1)
lm 輸出的 p 值預設為雙尾 p 值。在雙胞胎研究中,沿用單尾的科學假設可能更合理:雙胞胎的 IQ 分數彼此呈現「正向」關聯。由於 p 值表示觀察到的資料或更極端結果的機率,雙尾檢定的 p 值會是單尾結果的兩倍。也就是說,若要從 R 的雙尾輸出得到單尾 p 值,將 p 值除以 2 即可。
腳本中已提供 Foster 對 Biological 的線性迴歸模型 model。
本練習屬於課程
R 中的線性迴歸推論
練習說明
- 從模型中取得 Biological 的迴歸係數。
- 將模型整理為整齊格式(tidy)。
- 針對
term為"Biological"進行篩選。
- 新增一個欄位
one_sided_p_value,內容為單尾 p 值。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
model <- lm(Foster ~ Biological, data = twins)
# Get the Biological model coefficient
biological_term <- model %>%
# Tidy the model
___ %>%
# Filter for term equal to "Biological"
___
biological_term %>%
# Add a column of one-sided p-values
___(one_sided_p_value = ___)