Hello all, I am running a logit model and when it comes to plot the predictive probability, I found difference between margins & marginsplot and predict. EVENT is the binary outcome var, and PERIOD refers to the age, pr2 is the quadratic version of PERIOD. ELL is a binary var as well. Basically what I want to plot is subject's probability of EVENT at different ages. To give you an example, below is my model.
After getting the model result, I used margins followed by marginsplot.

Then still using the model plot, I instead use predict
But I then get a totally different plot.

Can anyone tell me why is this happening? Is it because margins and predict are calculating different results? If yes, then what are they specifically? Thanks.
Code:
logit EVENT PERIOD pr2 i.ELL if AUT==1
Code:
. logit EVENT PERIOD pr2 i.ELL if AUT==1 Iteration 0: log likelihood = -2000.4498 Iteration 1: log likelihood = -1890.2252 Iteration 2: log likelihood = -1887.0858 Iteration 3: log likelihood = -1887.0743 Iteration 4: log likelihood = -1887.0743 Logistic regression Number of obs = 3222 LR chi2(3) = 226.75 Prob > chi2 = 0.0000 Log likelihood = -1887.0743 Pseudo R2 = 0.0567 ------------------------------------------------------------------------------ EVENT | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- PERIOD | .1542712 .088534 1.74 0.081 -.0192522 .3277947 pr2 | -.0375349 .0080552 -4.66 0.000 -.0533227 -.021747 1.ELL | -.1361254 .128198 -1.06 0.288 -.3873889 .1151381 _cons | -.2112793 .227682 -0.93 0.353 -.6575278 .2349692 ------------------------------------------------------------------------------
Code:
. margins ELL, at(PERIOD=(1(1)10)) Predictive margins Number of obs = 3222 Model VCE : OIM Expression : Pr(EVENT), predict() 1._at : PERIOD = 1 2._at : PERIOD = 2 3._at : PERIOD = 3 4._at : PERIOD = 4 5._at : PERIOD = 5 6._at : PERIOD = 6 7._at : PERIOD = 7 8._at : PERIOD = 8 9._at : PERIOD = 9 10._at : PERIOD = 10 ------------------------------------------------------------------------------ | Delta-method | Margin Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- _at#ELL | 1 0 | .1991791 .0518272 3.84 0.000 .0975996 .3007586 1 1 | .180405 .0495094 3.64 0.000 .0833683 .2774416 2 0 | .2219689 .0431328 5.15 0.000 .1374303 .3065076 2 1 | .2017769 .0423774 4.76 0.000 .1187187 .2848352 3 0 | .2463177 .0328558 7.50 0.000 .1819215 .3107139 3 1 | .2247533 .0342906 6.55 0.000 .157545 .2919616 4 0 | .2721463 .0212896 12.78 0.000 .2304195 .3138732 4 1 | .2492807 .0263204 9.47 0.000 .1976938 .3008677 5 0 | .2993476 .0099511 30.08 0.000 .2798439 .3188513 5 1 | .275277 .02144 12.84 0.000 .2332553 .3172986 6 0 | .3277877 .0114108 28.73 0.000 .3054229 .3501524 6 1 | .3026314 .0243073 12.45 0.000 .2549899 .3502729 7 0 | .3573089 .0253801 14.08 0.000 .3075647 .407053 7 1 | .3312072 .0344955 9.60 0.000 .2635973 .3988171 8 0 | .3877332 .0413639 9.37 0.000 .3066615 .468805 8 1 | .3608442 .0483547 7.46 0.000 .2660707 .4556177 9 0 | .4188664 .0580044 7.22 0.000 .3051799 .532553 9 1 | .3913623 .0639059 6.12 0.000 .2661091 .5166155 10 0 | .4505018 .0748097 6.02 0.000 .3038776 .5971261 10 1 | .4225655 .0802194 5.27 0.000 .2653383 .5797927 ------------------------------------------------------------------------------
Then still using the model plot, I instead use predict
Code:
logit EVENT PERIOD pr2 i.ELL if AUT==1 predict PREDVALS4, pr bysort PERIOD ELL: gen count5 = _n graph twoway connect PREDVALS4 PERIOD if count5 ==1 & ELL == 1 || /// connect PREDVALS4 PERIOD if count5==1 & ELL == 0, /// ytitle(Fitted Hazard Probability) /// xlabel(1 "16" 2 "17" 3 "18" 4 "19" 5 "20" 6 "21" 7 "22" 8 "23" 9 "24" 10 "25") /// legend(position(6) rows(1) ring(0) size(small) region(lstyle(none) lcolor(none) color(none)) label(1 "ELL") label(2 "Non-ELL")) /// graphregion(color(white) fcolor(white) lcolor(white)) xtitle(Year) title("ELL (Autism)", size(small))
Can anyone tell me why is this happening? Is it because margins and predict are calculating different results? If yes, then what are they specifically? Thanks.
Comment