# Bootstrapping confidence intervals for a non-linear combination of logit coefficients using R

I have a GLM with a logit link examining behaviours (success = 1, failure = 0) across several large datasets (n > 30,000). The IVs are standardised and centred.

I would like to produce a metric of 'relative importance' for each coefficient, essentially a normalised scale, calculated as the absolute Beta value of each coefficient divided by the sum of the (absolute) Beta values of all coefficients - e.g. Abs[A] / (Abs[A] + Abs[B] + ...). I am using this as a tentative method to compare the importance of coefficients between groups. Having asked another question around the theory behind this (Are the confidence intervals of logit model coefficients normally distributed?), it appears that I may need to 'brute force' the answer through bootstrapping in R or equivalent. I am trying to find out where and how I can do this within the bootstrap process. I am new to R, and am currently here with my code:

library(multcomp)
library(rms)
library(boot)

GLM_boot <- function(data,indices){
d <-data[indices,]
GLM_model <- glm(formula = cbind(Successes, Failures) ~ A + B + C + D, family = binomial, data=d)
coef (GLM_model)}

boot_results = boot(data = mydata, statistic = GLM_boot, R = 1000)

boot_results


As I understand it, I need to include an evaluation for A / (A + B + C + D) and its associated 95% confidence interval or standard error, and so on for B / (A +...) etc. within the GLM_boot function and then pass this information out as a vector. I have taken some time to look at other questions on StatsExchange before posting, but have not found anything close enough, although happy to be redirected if I am mistaken.

Code derived from examples within: http://www.bio.ic.ac.uk/research/mjcraw/therbook/index.htm and http://people.tamu.edu/~alawing/materials/ESSM689/Btutorial.pdf

You don't need to include that evaluation inside the GLM_boot function, you can do it with a post-bootstrap processing step. This post-processing step modifies the returned bootstrap parameter values according to your desired transform.

I've constructed an example with a simple linear model but the same transform you wish to use:

# Construct data frame
df <- data.frame(A=rnorm(100), B=rnorm(100), C=rnorm(100), D=rnorm(100))
df$y <- df$A + 2*df$B + 3*df$C + 4*df$D + 5*rnorm(100) GLM_boot <- function(data,indices){ d <-data[indices,] GLM_model <- glm(y ~ A + B + C + D, data=d) coef (GLM_model)} boot_results = boot(data = df, statistic = GLM_boot, R = 1000) # Now we'll restate the coefficients as desired inside the boot object postprocess <- function(br) { br$t0 <- br$t0 / sum(br$t0)
br$t <- br$t / rowSums(br$t) br }  ... and the output... > postprocess(boot_results) ORDINARY NONPARAMETRIC BOOTSTRAP Call: boot(data = df, statistic = GLM_boot, R = 1000) Bootstrap Statistics : original bias std. error t1* 0.03483616 0.0008814079 0.04744519 t2* 0.10487991 -0.0032297441 0.05578734 t3* 0.16269011 0.0023995123 0.04332950 t4* 0.29902332 0.0009167799 0.04952932 t5* 0.39857050 -0.0009679560 0.04891230 >  We are not restricted to maintain the dimensionality of the parameters inside the boot object; below I modify the object so that both the original and the ratio versions of the parameters are reported. pp2 <- function(br) { br$t0 <- c(br$t0, br$t0/sum(br$t0)) br$t <- cbind(br$t, br$t/rowSums(br\$t))
br
}

> pp2(boot_results)

ORDINARY NONPARAMETRIC BOOTSTRAP

Call:
boot(data = df, statistic = GLM_boot, R = 1000)

Bootstrap Statistics :
original        bias    std. error
t1*  0.35231765  0.0327456957  0.48938051
t2*  1.06070932  0.0049052064  0.60399757
t3*  1.64537622  0.0453722673  0.51060026
t4*  3.02419044  0.0004190907  0.44728859
t5*  4.03096685 -0.0112095514  0.48327601
t6*  0.03483616  0.0008814079  0.04744519
t7*  0.10487991 -0.0032297441  0.05578734
t8*  0.16269011  0.0023995123  0.04332950
t9*  0.29902332  0.0009167799  0.04952932
t10* 0.39857050 -0.0009679560  0.04891230
>