Hello!
Stata's margin commands make it very easy to plot probabilities after, among other things, logistic regression.
Take for example estimating the log-odds of diabetes in females vs males and how the log-odds might differ in black and non-black ethnicities.
This code generates a graph that could naively be taken to plot a negative probability (impossible), when in fact it plots a change in probability.
webuse nhanes2f, clear
keep if !missing(diabetes, black, sex, age)
su age // mean = 47.6
logistic diabetes i.sex i.black age , nolog
// Calculate the probability of diabetes for male and females
// of African origin at mean age
margins i.sex, at(black = 1 age = 47.6 )
// Interpretation 1: after adjusting for age,
// for people of African origin at mean age,
// the Pr(diabetes) for females (.0628306) is higher than for males (.0543217)
di .0628306 - .0543217 // The difference in probability is .0085089
// estimate the uncertainty around this difference
margins , dydx(sex ) at(age = 47.6 black = 1)
// Interpretation 2: The 95% CI for the difference in probability is -.0017589 to .0187767
// so the difference in probability of diabetes for females may be a decrease of .0017589
// compared to males, to an increase of .0187767 compared to males
// Pr(diabetes for females and males of average age for different race):
margins i.black, dydx(sex ) at(age = 47.6 )
marginsplot, xscale(range(-0.5(1)1.5))
Because of this potential for confusion, I don't particularly like the output.
To be honest, I think I'd rather just plot odds ratios for sex by race. Is there a similar tool as margins to do this?
If not, I'd do linear combinations to get the ORs and 95%CIs of interest, manually type the results into Excel (yuck) and plot it up there, which is not at all satisfying.
Comments and personal opinions on the above welcome and thanks in advance for any tips and tricks!
Janine
Stata's margin commands make it very easy to plot probabilities after, among other things, logistic regression.
Take for example estimating the log-odds of diabetes in females vs males and how the log-odds might differ in black and non-black ethnicities.
This code generates a graph that could naively be taken to plot a negative probability (impossible), when in fact it plots a change in probability.
webuse nhanes2f, clear
keep if !missing(diabetes, black, sex, age)
su age // mean = 47.6
logistic diabetes i.sex i.black age , nolog
// Calculate the probability of diabetes for male and females
// of African origin at mean age
margins i.sex, at(black = 1 age = 47.6 )
// Interpretation 1: after adjusting for age,
// for people of African origin at mean age,
// the Pr(diabetes) for females (.0628306) is higher than for males (.0543217)
di .0628306 - .0543217 // The difference in probability is .0085089
// estimate the uncertainty around this difference
margins , dydx(sex ) at(age = 47.6 black = 1)
// Interpretation 2: The 95% CI for the difference in probability is -.0017589 to .0187767
// so the difference in probability of diabetes for females may be a decrease of .0017589
// compared to males, to an increase of .0187767 compared to males
// Pr(diabetes for females and males of average age for different race):
margins i.black, dydx(sex ) at(age = 47.6 )
marginsplot, xscale(range(-0.5(1)1.5))
Because of this potential for confusion, I don't particularly like the output.
To be honest, I think I'd rather just plot odds ratios for sex by race. Is there a similar tool as margins to do this?
If not, I'd do linear combinations to get the ORs and 95%CIs of interest, manually type the results into Excel (yuck) and plot it up there, which is not at all satisfying.
Comments and personal opinions on the above welcome and thanks in advance for any tips and tricks!
Janine
Comment