Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Plot margins for odds ratio

    Dear stata users,

    I recently got some difficulties switching from the command "gam" to "margins"

    What I want is to plot the odds ratio and 95% CIs from a general additive model, starting at OR=1 for the smallest X value (X is continuous). Here is some of my old codes:

    The arbitrary value "0.06043" is the fitted GAM_mu value for the smallest serd value.
    First of all, is my GAM code correct? I assume the fitted GAM_mu is the odds, right?

    gam stroke X, family(binomial) df(6)
    gen strokeor= GAM_mu/0.06043
    gen strokeorhigh=strokeor+strokeor* e_X*1.96
    gen strokeorlow=strokeor-strokeor* e_X*1.96

    scatter strokeorhigh X if X<=10, graphregion(fcolor(white) lcolor(white)) connect(l) clpattern(dash) msymbol(i) ///
    || scatter strokeor X if X<=10, graphregion(fcolor(white) lcolor(white))connect(l) msymbol(i) ///
    || scatter strokeorlow Xif X<=10, graphregion(fcolor(white) lcolor(white))connect(l) clpattern(dash) msymbol(i) ///
    ytitle("OR for Stroke") xtitle("X (umol/L)") legend(off) scheme(s2mono)




    Now I'd like to control some additional variables and use the "margin" command, but I have some difficulties to translate the code above.
    The marginsplot or marginscontplot always plot the probability, not the odds ratio. How can I get do that?

    First just assumes a linear relationship:

    logit stroke X age sex married college income job sbp smoking bmi pinact epa dha

    What should I do to get a plot for Odds ratio for stroke, start from 1

    Later on, I would like to add test the nonlinear trend with the "rc_spline" command, What should I do? I tried something like this, but it does not work.

    rc_spline X
    logit stroke _SX* age sex married college income job sbp smoking bmi pinact epa dha

    predict logodds, xb
    predict stderr, stdp
    gen odds=exp(logodds)
    gen odds_lb=odds-1.98*exp(stderr)
    gen odds_ub=odds+1.98*exp(stderr)



    Thanks a lot
    Last edited by David HU; 18 Feb 2016, 19:11.

  • #2
    I revised my codes as follows:

    logit mi c.X##c.X##c.X age sex married college income job sbp smoking bmi pinact epa dha, or
    margins, at ((means) age sex married college income job sbp smoking bmi pinact epa dha X=(-0.5(0.1)10)) expression(exp(predict(xb))/0.09156)
    marginsplot, recast(line) recastci(rarea) scheme(s2mono) xdim(X)

    The Arbitrary value 0.09156 is the margin when X==-0.5

    Does that make sense?

    Comment

    Working...
    X