Search code examples
rlogistic-regressionstatistics-bootstrap

Bootstrap in logistic model


I have the following 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

And I calculate the "score",X of the model for example X=$null.deviance-$deviance. In this case X=138.63-125.09. Now, I want to use bootstrap to calculate for the mean and confidence interval of the score. How can I implement this in R?


Solution

  • Take a look at package boot. Here follows a simulated example, that suits your case:

    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)
    

    With output:

    ORDINARY NONPARAMETRIC BOOTSTRAP
    
    
    Call:
    boot(data = datasim, statistic = dDeviance, R = 100)
    
    
    Bootstrap Statistics :
        original   bias    std. error
    t1* 41.02692 1.445287    9.712626