This is a simple example of using the boot
function in R to produce bootstrapped estimates of the bias and standard error of the parameters.
In [2]:
install.packages('ISLR')
In [3]:
library(ISLR)
library(boot)
attach(Default)
head(Default)
glm.fit <- glm(default~income+balance,family = "binomial",data = Default)
summary(glm.fit)
boot.fn <- function(data ,index) {
return(glm(default~income+balance ,family = "binomial",data = data ,subset = index)$coefficients)
}
boot.fn(Default,1:100)
boot(Default ,boot.fn ,1000)
summary(glm.fit)
As we can see above, the boot function found standard errors that were greater than the standard errors of the summary function. This makes sense, as the bootstrap method does not depend on estimates of the deviations of the error terms -- it simply samples observations repeatedly and creates models with them, and uses the difference between that and the full model to determine the standard error. So, as expected, the true standard error is likely larger than that given by the summary, since the summary is dependent on the type of model itself, while the bootstrap is not.
comments powered by Disqus