Announcement

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

  • linear regression

    Hello great statisticians,

    I am a bit confused with using lfit vs predicted values. I have the data below and my codes: sbp bmi and women are 3 variables.


    use http://www.stats4life.se/data/fhs, clear

    regress sbp bmi women

    predict predicted_sbp1
    twoway (lfit sbp bmi if women==1, lcolor(red)) (lfit sbp bmi if women==0, lcolor(blue)), ytitle(Predicted SBP) xtitle(BMI kg/m2) legend(on order(1 "Women" 2 "Men")) scheme(s1color)



    twoway (connected predicted_sbp1 bmi if women==1, lcolor(maroon) mcolor(maroon) msize(tiny) msymbol(point)) ///
    (connected predicted_sbp1 bmi if women==0, lcolor(green) mcolor(green) msize(tiny) msymbol(point)), ///
    ytitle(Predicted mean SBP) xtitle(BMI kg/m2) ///
    legend(on order(1 "Women" 2 "Men")) scheme(s1color)



    Why do these two graphs are different in shapes? Shouldn't they be the same.
    May be I have not understood the logic of regression. Can someone help me to clarify this? Please.


  • #2
    Your original command, -regress sbp bmi women- is a model that fits two parallel regression lines for sbp:bmi, one line represents women = 0 and the other represents women = 1. The values of -predict- following that regression will all fall on those two lines.

    However, when you do your -lfit- graphs, you have done two completely separate regressions, one for women and the other for men. In particular, there is no constraint that the two regression lines be parallel. They are estimated entirely independent of each other and can go in different, even perpendicular directions. The analysis that would produce results that resemble your -lfit- graphs would be:
    Code:
    regress sbp bmi if women == 0
    predict predicted_0
    regress sbp bmi if women == 1
    predict predicted_1
    graph twoway connect predicted_0 bmi || connect predicted_1 bmi
    Added: Another way to produce results resembling your -lfit- graphs is:
    Code:
    regress sbp c.bmi##i.women
    predict predicted
    sort bmi
    graph twoway connect predicted bmi if women == 0 || connect predicted bmi if women == 1
    Last edited by Clyde Schechter; 10 Mar 2022, 14:08.

    Comment


    • #3
      Thank you very much for detailed clarification.

      Comment


      • #4
        One more question sir, now I would like to see if there is interaction effect of gender and bmi on sbp. What kind of plot would you suggest to best guess about the possibility of this interaction? It is more of a epi-biostatistics question than stata but if you could suggest something?

        Comment


        • #5
          The second block of code in my response in #2 is a model where sex interacts with bmi in the effect on sbp. To estimate the size of that interaction, you would look at the 1.women#c.bmi coefficient in the regression output and its associated statistics.

          Comment

          Working...
          X