對資料做 Bootstrapping
使用 infer 套件並設定 type = "bootstrap",你可以從資料集反覆抽樣,以估計斜率係數的抽樣分配與標準誤。運用抽樣分配可以直接找出母體斜率的信賴區間。
本練習屬於課程
R 中的線性迴歸推論
練習說明
使用 infer 的步驟,對 twins 資料做 1000 次 bootstrap。你不需要呼叫 hypothesize(),因為現在要建立的是信賴區間,而不是做假設檢定!
- 指定
Foster相對於Biological。 - 透過 bootstrapping 產生
1000個重複樣本。 - 計算斜率統計量。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Set the seed for reproducibility
set.seed(4747)
# Calculate 1000 bootstrapped slopes
boot_slope <- twins %>%
# Specify Foster vs. Biological
___ %>%
# Generate 1000 bootstrap replicates
___ %>%
# Calculate the slope statistic
___
# See the result
boot_slope