Bootstrap 在逻辑模型中

Bootstrap in logistic model

我有以下逻辑模型

 Call:
 glm(formula = Y ~ ., family = binomial, data = datasim)

 Deviance Residuals: 
 Min        1Q    Median        3Q       Max  
-1.79670  -1.06758   0.00754   1.08200   1.69251  

Coefficients:
             Estimate Std. Error z value Pr(>|z|)   
(Intercept) -0.11504    1.02968  -0.112  0.91104   
X1           0.17173    0.31899   0.538  0.59034   
X2          -0.01573    0.28294  -0.056  0.95567   
X3          -0.36905    0.29577  -1.248  0.21212   
X4          -0.34710    0.29518  -1.176  0.23965   
X5           0.01733    0.36088   0.048  0.96170   
X6          -0.33492    0.38217  -0.876  0.38083   
X7           0.20179    0.31615   0.638  0.52328   
X8          -0.42734    0.26011  -1.643  0.10040   
X9          -0.02750    0.29571  -0.093  0.92590   
X10          0.76991    0.26840   2.868  0.00412 **
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

(Dispersion parameter for binomial family taken to be 1)

Null deviance: 138.63  on 99  degrees of freedom
Residual deviance: 125.09  on 89  degrees of freedom
AIC: 147.09

Number of Fisher Scoring iterations: 4

然后我计算模型的 "score",X,例如 X=$null.deviance-$deviance。在这种情况下,X=138.63-125.09。 现在,我想使用 bootstrap 来计算分数的均值和置信区间。我如何在 R 中实现它?

看看包 boot。下面是一个适合您情况的模拟示例:

library(boot)
x <- rnorm(100)
Y <- exp(x + rnorm(100)) > 1
datasim <- data.frame(Y, x)

dDeviance <- function(data, indices){
  fit <- glm(formula = Y ~ ., family = binomial, data = data[indices, ])
  with(fit, null.deviance - deviance)
}
boot(data = datasim, statistic = dDeviance, R = 100)

输出:

ORDINARY NONPARAMETRIC BOOTSTRAP


Call:
boot(data = datasim, statistic = dDeviance, R = 100)


Bootstrap Statistics :
    original   bias    std. error
t1* 41.02692 1.445287    9.712626