0

I use the code below to get the results of repeated logistic regressions (with bonferroni correction). The problem is that when my variable x has more than two modalities, my results table only takes the Odd ratio for the association with the first modality for each model run. How could I solve this while excluding to extract the intercepts of each model? In addition, I need to obtain a new column so that for each coefficient this column indicates the variable and the modality of the type 'variable:modality'.

var = outcome chosen for the model

data = name of the table

correction = name of the correction to use
y <- data[,var] 
x <- data[, -which(names(data) == var)]

Repeated regression analysis for each variable x

n <- ncol(x) 
odds <- numeric(n) 
pvalues <- numeric(n)

for (i in 1:n) { 
fit <- glm(y ~ x[,i], family = binomial(link = "logit")) 
summary_fit <- summary(fit) 
odds[i] <- exp(summary_fit$coefficients[-c(1),2]) 
ci <- exp(confint(fit, level = 0.95)[2,]) 
pvalues[i] <- summary_fit$coefficients[-c(1),4] }

Bonferroni correction to p-values

pvalues_corrected <- p.adjust(pvalues, method = correction)

Table with results

results <- data.frame(variable = names(x), odd_ratio = odds, ci_low = data.frame(ci)[1,1], ci_high = data.frame(ci)[2,1], p_value = pvalues_corrected)
  • 1
    Could you post a reproducible dataset so as to make it easy for us to help you? – coffeinjunky Mar 11 '23 at 00:54
  • See https://stackoverflow.com/questions/41032858/lm-summary-not-display-all-factor-levels maybe to understand what is going on. Also https://stats.stackexchange.com/questions/285210/what-to-do-in-a-multinomial-logistic-regression-when-all-levels-of-dv-are-of-int/544656#544656 – kjetil b halvorsen Mar 11 '23 at 15:14
  • To reproduce the problem, it is possible to use the "warpbreaks" dataset. The "wool" column is the "y" variable and the two others are the xs variables. The tension column (x) has 3 modalities but the code I wrote will only show the odd ratio of the first association. – GloubiGlouba Mar 11 '23 at 23:43

0 Answers0