0
$\begingroup$

I have a logistic regression model with 2 categorical variables and 1 continuous variables using the mtcars package.

I am interested in the interpretation of the cyl categorical variable that has 3 levels 4,6 and 8.

I create a dataframe called "cyl_coefficients" that has the log odds coefficients for the cyl variables:

The intercept of the model is -53. This is the coefficient for cyl4, then -254 for cly6 and -792 for cyl8. I exponentiate those numbers to get the odds ratio column in the cyl_coefficients. Note: the cyl6 and cly8 are OFFSETS from the cyl4 coefficient.

I am interested in the actual coefficients of the cyl variables, NOT THE OFFSETS. So to get the real coefficient for cyl6 and cly8 I add those coefficients to cyl4. See the "log_odds_no_reference_gorup" column.

Then I exponentiate that column to get the "log_odds_no_reference_odds_ratio" column.

My question is: Is the "log_odds_no_reference_odds_ratio" column the actual, not offset, odds ratio for cyl4, cyl6 and cyl8?

I believe it is as when you look at the "check" column which is attempting to tie out to the "odds_ratio" column it does successfully tie out. See the 1.829006e-111 value for cyl6 in the check column and the odds_ratio column.

I want to work with the odds ratios for the variables NOT the offsets because I want to show all variables and rank them by odds ratio (i.e. the "log_odds_no_reference_odds_ratio" column) which would show 6.5e-24 for cyl4, 1.18e-134 for cyl6 and 0 for cyl8.

Of course these are the coefficients when gear =3 because 3 is the reference group for the gear variable.

Can you please comment on the validity of "log_odds_no_reference_odds_ratio" column representing the actual, not offset odds ratios?

data(mtcars)
str(mtcars)
mtcars$gear= factor(mtcars$gear)
mtcars$cyl= factor(mtcars$cyl)
mtcars$vs= factor(mtcars$vs)
g = glm(data=mtcars, formula = vs~cyl+gear+hp, family= "binomial")
summary(g)

cyl_coefficients = data.frame(group= c("cyl4","cyl6","cyl8"),log_odds = as.numeric(c( coef(summary(g))[1,1],coef(summary(g))[2:3,1])), 
                                 odds_ratio= exp(as.numeric(c( coef(summary(g))[1,1],coef(summary(g))[2:3,1]))),
                                 log_odds_no_reference_group = as.numeric(c( coef(summary(g))[1,1],  coef(summary(g))[1,1] + coef(summary(g))[2:3,1])),
                                 odds_ratio_no_reference_group = exp(as.numeric(c( coef(summary(g))[1,1],  coef(summary(g))[1,1] + coef(summary(g))[2:3,1])))
                                 )
cyl_coefficients$check = cyl_coefficients$odds_ratio_no_reference_group/cyl_coefficients$odds_ratio_no_reference_group[1]
cyl_coefficients
> cyl_coefficients
  group   log_odds    odds_ratio log_odds_no_reference_group odds_ratio_no_reference_group         check
1  cyl4  -53.38997  6.501779e-24                   -53.38997                  6.501779e-24  1.000000e+00
2  cyl6 -254.98317 1.829006e-111                  -308.37314                 1.189179e-134 1.829006e-111
3  cyl8 -791.70135  0.000000e+00                  -845.09132                  0.000000e+00  0.000000e+00
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.