基于模拟的推断

R 中的线性回归推断

Jo Hardin

Professor, Pomona College

R 中的线性回归推断

双胞胎 IQ 的散点图。

R 中的线性回归推断

双胞胎数据

双胞胎 IQ 表。每行对应一对双胞胎。第一列为寄养家庭抚养的双胞胎 IQ,第二列为生物学父母抚养的双胞胎 IQ。

R 中的线性回归推断

置换后的双胞胎数据

双胞胎 IQ 表的每列被置换,双胞胎不再同列于同一行。

R 中的线性回归推断

置换数据(1)绘图

原始数据

置换数据(1)

R 中的线性回归推断

置换数据(2)绘图

原始数据

置换数据(2)

R 中的线性回归推断

置换数据(1)与(2)

置换数据(1)

置换数据(2)

R 中的线性回归推断
twins %>%
   specify(Foster ~ Biological) %>%
   hypothesize(null = "independence") %>%
   generate(reps = 10, type = "permute") %>%
   calculate(stat = "slope")
A tibble: 10 x 2
   replicate          stat
       <int>         <dbl>
 1         1  0.0007709302
 2         2 -0.0353592305
 3         3 -0.0278627974
 4         4 -0.0072547982
 5         5 -0.1252761541
 6         6 -0.1669869287
 7         7 -0.2610519170
 8         8 -0.0157695494
 9         9  0.0581361900
10        10  0.1598471947
R 中的线性回归推断

大量置换斜率

perm_slope <- twins %>%
   specify(Foster ~ Biological) %>%
   hypothesize(
     null = "independence"
     ) %>%
   generate(reps = 1000, 
            type = "permute") %>%
   calculate(stat = "slope") 

ggplot(data = perm_slope, aes(x = stat)) + 
   geom_histogram() +
   xlim(-1,1)

R 中的线性回归推断

置换斜率,红线为观测斜率

obs_slope <- lm(Foster ~ Biological,
                data = twins) %>%
   tidy() %>%   
   filter(term == "Biological") %>%
   select(estimate) %>%   
   pull()
obs_slope
0.901436
ggplot(data = perm_slope, aes(x = stat)) + 
   geom_histogram() +
   geom_vline(xintercept = obs_slope, color = "red") 
   + xlim(-1,1)

R 中的线性回归推断

Passons à la pratique !

R 中的线性回归推断

Preparing Video For Download...