信賴區間

R 的抽樣

Richie Cotton

Data Evangelist at DataCamp

信賴區間

  • 「平均數一個標準差內的值」在每個分配中都包含大量數值。
  • 我們將定義一個相關概念,稱為「信賴區間」。
R 的抽樣

天氣預測

  • 美國南達科他州的 Rapid City 天氣最難預測。
  • 你的任務是預測該地明天的最高溫。

一張天氣地圖,以顏色表示各地可預測性。

R 的抽樣

你的天氣預測

  • 點估計 = 47 °F(8.3 °C)
  • 合理最高溫範圍 = 40 至 54 °F(4.4 至 12.8 °C)
R 的抽樣

你剛剛回報了一個信賴區間

  • 40 至 54 °F 是一個「信賴區間」
  • 有時寫成 47 °F(40 °F, 54 °F)或 47 °F [40 °F, 54 °F]
  • …或 47 ± 7 °F
  • 7 °F 是「誤差範圍」
R 的抽樣

平均風味的自助抽樣分配

ggplot(coffee_boot_distn, aes(resample_mean)) +
  geom_histogram(binwidth = 0.002)

咖啡風味平均值的直方圖。

R 的抽樣

重抽樣平均的平均值

coffee_boot_distn %>% 
  summarize(
    mean_resample_mean = mean(resample_mean)
  )
# A tibble: 1 x 1
  mean_resample_mean
               <dbl>
1             7.5263

以藍色垂直線標示平均值的咖啡風味平均直方圖。

R 的抽樣

平均值加減一個標準差

coffee_boot_distn %>% 
  summarize(
    mean_resample_mean = mean(resample_mean),
    mean_minus_1sd = mean_resample_mean - sd(resample_mean),
    mean_plus_1sd = mean_resample_mean + sd(resample_mean)
  )
# A tibble: 1 x 3
  mean_resample_mean mean_plus_1sd mean_minus_1sd
               <dbl>         <dbl>          <dbl>
1             7.5263        7.5355         7.5171

以垂直線標示平均與一個標準差的咖啡風味平均直方圖。

R 的抽樣

以分位數求信賴區間的方法

coffee_boot_distn %>% 
  summarize(
    lower = quantile(resample_mean, 0.025),
    upper = quantile(resample_mean, 0.975)
  )
# A tibble: 1 x 2
   lower  upper
   <dbl>  <dbl>
1 7.5087 7.5447

95% 信賴區間的線段。

R 的抽樣

反累積分配函式

  • PDF:鐘形曲線
  • CDF:積分得到曲線下面積
  • 反 CDF:交換 x 與 y 軸
normal_inv_cdf <- tibble(
  p = seq(-0.001, 0.999, 0.001),
  inv_cdf = qnorm(p)
)
ggplot(normal_inv_cdf, aes(p, inv_cdf)) +
  geom_line()

反累積分配函式。

1 參見「Introduction to Statistics in R」,第 3 章,「The Normal Distribution」
R 的抽樣

以標準誤求信賴區間的方法

coffee_boot_distn %>% 
  summarize(
    point_estimate = mean(resample_mean),
    std_error = sd(resample_mean),

lower = qnorm(0.025, point_estimate, std_error), upper = qnorm(0.975, point_estimate, std_error)
)
# A tibble: 1 x 4
  point_estimate std_error  lower  upper
           <dbl>     <dbl>  <dbl>  <dbl>
1         7.5263 0.0091815 7.5083 7.5443
R 的抽樣

一起來練習吧!

R 的抽樣

Preparing Video For Download...