[R] bootstrap glm
Nazatulshima.Hassan at liverpool.ac.uk
Thu Feb 25 16:59:33 CET 2016
I have a data with an outcome,Y and 10 predictors (X1-X10).
My aim is to fit a logistic model to each of the predictors and calculate the deviance difference (dDeviance).
And later on bootstrapping the dDeviance for 100 times (R=100).
I tried the following function. It is calculating the original dDeviance correctly. But, when I checked the mean bootstrap values, it differs greatly from the original.
I suspect I made a mistake with the bootstrapping function, which I need help with.
I attached the script if you need to look at it.
Thank you in advance.
yfunction <- function(data,indices)
glm.snp1 <- glm(Y~data[indices], family="binomial", data=datasim)
null <- glm.snp1$null.deviance
residual <- glm.snp1$deviance
mybootstrap <- function(data)
resulty <- lapply(datasim[,-1],function(x)mybootstrap(x))
bootresult <- sapply(datasim[,-1],function(x)mybootstrap(x)$t)
More information about the R-help