配對自助法(pairs bootstrap)

Statistical Thinking in Python(第 2 部分)

Justin Bois

Lecturer at the California Institute of Technology

非母數推論

  • 不對模型或資料背後的機率分佈做任何假設
Statistical Thinking in Python(第 2 部分)

2008 年美國搖擺州選舉結果

2008 年美國搖擺州選舉結果

1 資料取自 Data.gov(https://www.data.gov/)
Statistical Thinking in Python(第 2 部分)

線性迴歸的配對自助法

  • 以配對方式重抽資料
  • 由重抽樣資料計算斜率與截距
  • 每組斜率與截距是一個自助法重抽複本
  • 以複本的百分位數求信賴區間
Statistical Thinking in Python(第 2 部分)

產生配對自助抽樣

np.arange(7)
array([0, 1, 2, 3, 4, 5, 6])
inds = np.arange(len(total_votes))

bs_inds = np.random.choice(inds, len(inds))
bs_total_votes = total_votes[bs_inds] bs_dem_share = dem_share[bs_inds]
Statistical Thinking in Python(第 2 部分)

計算一次配對自助法複本

bs_slope, bs_intercept = np.polyfit(bs_total_votes, 
                                    bs_dem_share, 1)

bs_slope, bs_intercept
(3.9053605692223672e-05, 40.387910131803025)
np.polyfit(total_votes, dem_share, 1)  # fit of original
array([  4.03707170e-05,   4.01139120e+01])
Statistical Thinking in Python(第 2 部分)

2008 年美國搖擺州選舉結果

2008 年美國搖擺州選舉結果

1 資料取自 Data.gov(https://www.data.gov/)
Statistical Thinking in Python(第 2 部分)

一起來練習吧!

Statistical Thinking in Python(第 2 部分)

Preparing Video For Download...