[R] bootstrap glm

Hassan, Nazatulshima Nazatulshima.Hassan at liverpool.ac.uk
Thu Feb 25 16:59:33 CET 2016


Hi

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.


set.seed(111)

yfunction <- function(data,indices)
{
glm.snp1 <- glm(Y~data[indices], family="binomial", data=datasim)
null <- glm.snp1$null.deviance
residual <- glm.snp1$deviance
dDeviance <-(null-residual)
return(dDeviance)
}

mybootstrap <- function(data)
{
boot(data,yfunction, R=100)
}

resulty <- lapply(datasim[,-1],function(x)mybootstrap(x))
bootresult <- sapply(datasim[,-1],function(x)mybootstrap(x)$t)
colMeans(bootresult)



-shima-



More information about the R-help mailing list