0

I'm trying to calculate the adjusted odds ratios of lots of different outcomes with a set number of factors in a data frame in R. I'm using a loop to output these to a list.

Outcomes <- c("Q1", "Q2", "Q3", ....)

List <- lapply(Outcomes , function(x) {
    z = glm(substitute(i ~ ., list(i = as.name(x))), data = select(df, x, 100:102, Year, Country), family = "binomial") 
    exp(cbind(OR = coef(z), confint(z)))
})

I have 3 categorical factors: age range (3 levels), year (8 levels: 2015, 2016...), and country (3 levels)

When outputting the odds ratio the first two levels of year are missing - I know the first level should be missing because that's the comparison, but the second...The other two categorical factors are fine.

(sidenote does exp(cbind(OR = coef(z), confint(z))) calculate the odds ratio or the adjusted odds ratio?)

If I complete the the glm outside the loop

glm(substitute(i ~ ., list(i = as.name("Q1"))), data = select(ASHDATA, B2, Year), family = "binomial")

The second level 2016 is included in the output!

Why is it not included when I use the lapply function and is there a way to make it work?

Thank you in advance!

Harry
  • 1
  • Can you make your post [reproducible](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) and provide the dataset that you want to use this function with? – jrcalabrese Jan 06 '23 at 15:18

0 Answers0