Announcement

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

  • Plotting OR/HR's in the y-axis with a continuous variable in the x-variable

    Hello

    I am using Stata 14.1 and am having trouble creating a certain type of figure and have not been able to figure it out in Stata.

    I want to display OR's from a logistic regression model on the y-axis over a continuous variable on the x-axis by a secondary dichotomous variable.

    For example, I want to display all the OR's from logistic regression models of the relationship between the development of tuberculosis and BCG vaccination -- over a third variable that is continuous, which we can say is age here. On the x-axis would be age. On the y-axis would be OR's. The reference would be "No vaccination" and the OR's would show the increased odds of tuberculosis among BCG vaccinated individuals over age. I understand this would need to be done with some sort of smoothed curve.
    __________________________________________________ __________________________________________________ ____

    To give you an example of what I am trying to create see below

    ,
    Click image for larger version

Name:	oddsratios_continuous variable.png
Views:	1
Size:	426.1 KB
ID:	1536085





    From the article "Strength of the Association of Elevated Vitamin B12 and Solid Cancers: An Adjusted Case-Control Study" in the journal J. Clin. Med. 2020, 9, 474.

    Another example is:

    Click image for larger version

Name:	oddsratios_continuous variable1.png
Views:	1
Size:	390.2 KB
ID:	1536086




    From the article "Dietary carbohydrate intake, glycaemic index, glycaemic load and digestive system cancers: an updated dose–response meta-analysis"

    Cai, X., Li, X., Tang, M., Liang, C., Xu, Y., Zhang, M., Yu, W. and Li, X., 2019. Dietary carbohydrate intake, glycaemic index, glycaemic load and digestive system cancers: an updated dose–response meta-analysis. British Journal of Nutrition, 121(10), pp.1081-1096


    __________________________________________________ __________________________________________________ __________________________________________________ ____


    I'm able to show multiple odds ratios for differing age groups using the 'coefplots' command and here is my code and graph for that graph.

    Code:
    #Running a logistic model for each age group and saving the estimates#
    
    melogit death_merg bcg_merg age_merg sex_cont_merg prosp_retro_merg  if all_dis_merg<5 & age_merg<15 & age_merg>=10 ||study_new:, or
    estimates store death_bcg_3
    melogit death_merg bcg_merg age_merg sex_cont_merg prosp_retro_merg  if all_dis_merg<5 & age_merg<10 & age_merg>=5 ||study_new:, or
    estimates store death_bcg_2
    melogit death_merg bcg_merg age_merg sex_cont_merg prosp_retro_merg  if all_dis_merg<5 & age_merg<5  ||study_new:, or
    estimates store death_bcg_1
    melogit death_merg bcg_merg age_merg sex_cont_merg prosp_retro_merg  if all_dis_merg<5 & age_merg<150 & age_merg>=15 ||study_new:, or
    estimates store death_bcg_4
    melogit death_merg bcg_merg age_merg sex_cont_merg prosp_retro_merg  if all_dis_merg<5  ||study_new:, or
    estimates store death_bcg_5
    
    #coefplot based on saved estimates#
    
    coefplot (death_bcg_5 , label("All Participants") mlabels(bcg_merged=1 "N=18175") mlabsize(small) mlabcolor(black) lpatt(solid)lcol(black)msym(d)mcol(black)ciopts(recast(. rcap)lcol(black))  drop(_cons age_merged sex_cont_merged prosp_retro_merged) xlabel(0.2 "0.2" 0.5 "0.5" 1 "1.0"  2 "2.0" 3.0 "3.0")) (death_bcg_1 , label("<5 years old") mlabels(bcg_merged=1 "N=4567") mlabsize(small) mlabcolor(black) lpatt(solid)lcol(brown)msym(d)mcol(brown)ciopts(recast(. rcap)lcol(brown))  drop(_cons age_merged sex_cont_merged prosp_retro_merged) xlabel(0.2 "0.2" 0.5 "0.5" 1 "1.0"  2 "2.0" 3.0 "3.0")) (death_bcg_2, label("5-9 years old") mlabels(bcg_merged=1 "N=6139") mlabsize(small) mlabcolor(black) lpatt(solid)lcol(maroon)msym(d)mcol(maroon)ciopts(recast(. rcap)lcol(maroon)) drop(_cons age_merged sex_cont_merged prosp_retro_merged) xlabel(0.2 "0.2" 0.5 "0.5" 1 "1.0"  2 "2.0" 3.0 "3.0")) (death_bcg_3, label("10-14 years old")  mlabels(bcg_merged=1 "N=4632") mlabsize(small) mlabcolor(black)  xlabel(0.2 "0.2" 0.5 "0.5" 1 "1.0"  2 "2.0" 3.0 "3.0") lpatt(solid)lcol(dkgreen)msym(d)mcol(dkgreen)ciopts(recast(. rcap)lcol(dkgreen)) drop(_cons age_merged sex_cont_merged prosp_retro_merged)) (death_bcg_4, label("≥15 years old") mlabels(bcg_merged=1 "N=2837") mlabsize(small) mlabcolor(black)  xlabel(0.2 "0.2" 0.5 "0.5" 1 "1.0"  2 "2.0" 3.0 "3.0") lpatt(solid)lcol(navy)msym(d)mcol(navy)ciopts(recast(. rcap)lcol(navy)) drop(_cons age_merged sex_cont_merged prosp_retro_merged )), eform  xline(1, lcolor(black) lwidth(thin) lpattern(dash)) xtitle(Odds Ratio) levels(95)   msymbol(d) mfcolor(white) ciopts(recast(. rcap))legend(rows(8)  ring(0) pos(2)  col(1)  size(3.5) region(fcolor(gs15))) graphregion(fcolor(white))

    Figure. Risk of Death Among BCG Vaccinated and Unvaccinated Children, Stratified by Age Groups

    Click image for larger version

Name:	pic_example.png
Views:	1
Size:	120.2 KB
ID:	1536087





    But I would like to create a graph that treats age as a continuous variable and is able to smooth out the relative risk estimates over the continuous variable if possible. I have been unable to find any leads or ways to do this as of yet.

    I'd appreciate any help you can offer.

    Best
    Leo
    Last edited by Leo Martinez; 11 Feb 2020, 11:49.

  • #2
    I wanted to see if anyone knew anything about this question?

    Comment


    • #3
      marginsplot might do what you want.

      Here is quick example lifted from
      help marginsplot:

      Code:
      webuse nhanes2
      
      // Plots at specified values of continuous covariates
      logistic highbp sex##agegrp##c.bmi
      margins, at(bmi=(10(5)65))
      marginsplot


      Of course you'll replace the model from the example and at(age_merg=(5(5)100)) or some such.
      Options and extensions of marginsplot will let you modify the output until you have something close to the "goal plots" you started with.

      Comment


      • #4
        Hi Leo,
        I have the same question regarding the calculation of odds ratio per continuous variable and plotting each point. Were you able to create the graph that you wanted, and if so, how did you do it?
        Best wishes,
        Karla

        Comment

        Working...
        X