Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: Predict and adjust


From   "Tim Wade" <[email protected]>
To   [email protected]
Subject   Re: st: Predict and adjust
Date   Thu, 28 Dec 2006 10:15:36 -0500

Maarten, thanks for this article it is very helpful.  I also just
wanted to point out that if you use adjust to generate predicted
probabilities based on each individual covariate pattern in the
example  Fred provided where no variables or by variables are
specified in the adjust command, the results are the same as those
obtained from predict. There appear to be some very slight
differences, but I would imagine these are just artificats resulting
from the calculations (rounding or precision). To my understanding,
they should be the same.  Apologies if you make this point in your
paper, I have not yet read it completely. Tim



. use http://www.stata-press.com/data/r9/lbw,clear
(Hosmer & Lemeshow data)

.
. xi: logistic low age lwt i.race smoke,nolog
i.race            _Irace_1-3          (naturally coded; _Irace_1 omitted)

Logistic regression                               Number of obs   =        189
                                                 LR chi2(5)      =      20.08
                                                 Prob > chi2     =     0.0012
Log likelihood = -107.29639                       Pseudo R2       =     0.0856

------------------------------------------------------------------------------
        low | Odds Ratio   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
        age |   .9777443   .0334083    -0.66   0.510     .9144097    1.045466
        lwt |   .9875761    .006305    -1.96   0.050     .9752956    1.000011
   _Irace_2 |   3.425372   1.771281     2.38   0.017     1.243215    9.437768
   _Irace_3 |     2.5692   1.069301     2.27   0.023     1.136391    5.808555
      smoke |   2.870346    1.09067     2.77   0.006        1.363    6.044672
------------------------------------------------------------------------------

.
. predict p
(option p assumed; Pr(low))

.
. adjust,pr gen(p2)

--------------------------------------------------------------------------------------------------------
    Dependent variable: low     Command: logistic
      Created variable: p2
  Variables left as is: age, lwt, smoke, _Irace_2, _Irace_3
--------------------------------------------------------------------------------------------------------

----------------------
     All |         pr
----------+-----------
         |    .289227
----------------------
    Key:  pr  =  Probability


/*probabilities from adjust and predict are equal to 6 decimal places*/
. assert round(p, 0.000001)==round(p2, 0.000001)

. assert round(p, 0.0000001)==round(p2, 0.0000001)
1 contradiction in 189 observations
assertion is false


/*list differences*/
. list p p2 if p~=p2

    +---------------------+
    |        p         p2 |
    |---------------------|
 9. | .3087749   .3087749 |
13. | .3991293   .3991293 |
22. | .1655139   .1655139 |
26. | .0841037   .0841037 |
34. | .1024484   .1024484 |
    |---------------------|
39. | .1190956   .1190956 |
44. | .1050068   .1050068 |
49. | .1614151   .1614151 |
53. | .3239199   .3239199 |
75. | .3400029   .3400029 |
    |---------------------|
83. | .3150367   .3150367 |
84. | .3177494   .3177494 |
89. | .0648929   .0648929 |
92. | .2943909   .2943909 |
93. | .1212154   .1212154 |
    |---------------------|
95. | .3400029   .3400029 |
97. | .0955361   .0955361 |
100. |  .113265    .113265 |
114. | .1329292   .1329292 |
121. | .1095563   .1095563 |
    |---------------------|
122. | .2121971   .2121971 |
127. | .0702466   .0702466 |
147. | .1959741   .1959741 |
148. | .2509839   .2509839 |
158. | .3239199   .3239199 |
    |---------------------|
159. | .3381446   .3381447 |
170. | .2005814   .2005814 |
172. | .6548489   .6548489 |
177. | .3239199   .3239199 |
181. | .2250071   .2250071 |
    +---------------------+




On 12/27/06, Maarten buis <[email protected]> wrote:
As you can see on page 5 of my `extended answer' available on my
website (http://home.fsw.vu.nl/m.buis), adjust will give the predicted
probability of someone with average values on the predictor within its
group, if you have only one group (i.e. don't specify the by option)
than that will be the overall mean.

hope this helps,
Maarten

--- Tim Wade <[email protected]> wrote:

> Fred, I haven't thought through this completely (and Michael and
> Marteen have already provided great explanations), but as I was
> thinking about your example I calculated the adjusted probabilities
> holding each variable constant at its mean and it seems to produces
> the same marginal results as the adjust command.  I never have used
> adjust without specifying any variables, so I'm not sure about this
> exactly. Tim
>
> . xi: logistic low age lwt i.race smoke,nolog
> i.race            _Irace_1-3          (naturally coded; _Irace_1
> omitted)
>
> Logistic regression                               Number of obs   =
>      189
>                                                   LR chi2(5)      =
>    20.08
>                                                   Prob > chi2     =
>   0.0012
> Log likelihood = -107.29639                       Pseudo R2       =
>   0.0856
>
>
------------------------------------------------------------------------------
>          low | Odds Ratio   Std. Err.      z    P>|z|     [95% Conf.
> Interval]
>
-------------+----------------------------------------------------------------
>          age |   .9777443   .0334083    -0.66   0.510     .9144097
> 1.045466
>          lwt |   .9875761    .006305    -1.96   0.050     .9752956
> 1.000011
>     _Irace_2 |   3.425372   1.771281     2.38   0.017     1.243215
> 9.437768
>     _Irace_3 |     2.5692   1.069301     2.27   0.023     1.136391
> 5.808555
>        smoke |   2.870346    1.09067     2.77   0.006        1.363
> 6.044672
>
------------------------------------------------------------------------------
>
> . predict p
> (option p assumed; Pr(low))
>
> . adjust,pr
>
>
--------------------------------------------------------------------------------------------------------
>      Dependent variable: low     Command: logistic
>    Variables left as is: age, lwt, smoke, _Irace_2, _Irace_3
>
--------------------------------------------------------------------------------------------------------
>
> ----------------------
>       All |         pr
> ----------+-----------
>           |    .289227
> ----------------------
>      Key:  pr  =  Probability
>
> . /*generate linear predictor, holding predictors constant at mean*/
> .
> .
> . foreach var of varlist low age lwt _Irace* smoke {
>   2. qui sum `var'
>   3. local mean`var'=r(mean)
>   4. }
>
> . gen
>
x1=_b[_cons]+(`meanage'*_b[age])+(`mean_Irace_2'*_b[_Irace_2])+(`mean_Irace_3'*_b[_Irace_3])+(`mea
> > nlwt'*_b[lwt])+(`meansmoke'*_b[smoke])
>
> .
> . /*generate odds*/
> .
> . gen odds3=exp(x1)
>
> . /*generate probability*/
> .
> . gen p3=odds3/(odds3+1)
>
> . list p3 in 1
>
>      +----------+
>      |       p3 |
>      |----------|
>   1. | .2892265 |
>      +----------+
>
> . sum p3
>
>     Variable |       Obs        Mean    Std. Dev.       Min
> Max
>
-------------+--------------------------------------------------------
>           p3 |       189    .2892265           0   .2892265
> .2892265
>
>
>
>
>
>
>
> On 12/23/06, Fred Wolfe <[email protected]> wrote:
> > I know this has come up on the Stata list before, but in somewhat
> > different form. I wonder if someone could explain the following to
> me.
> >
> > The manual and the FAQ state that the results after predict and
> > adjust are the same for the following circumstances, and they site
> > this analysis that I have rerun.
> >
> > . sysuse auto, clear
> > (1978 Automobile Data)
> >
> > . regress mpg weight length foreign
> >
> >        Source |       SS       df       MS              Number of
> obs =      74
> > -------------+------------------------------           F(  3,
> 70) =   48.10
> >         Model |   1645.2889     3  548.429632           Prob > F
>   =  0.0000
> >      Residual |  798.170563    70  11.4024366           R-squared
>   =  0.6733
> > -------------+------------------------------           Adj
> R-squared =  0.6593
> >         Total |  2443.45946    73  33.4720474           Root MSE
>   =  3.3767
> >
> >
>
------------------------------------------------------------------------------
> >           mpg |      Coef.   Std. Err.      t    P>|t|     [95%
> Conf. Interval]
> >
>
-------------+----------------------------------------------------------------
> >        weight |  -.0043656   .0016014    -2.73   0.008    -.0075595
>   -.0011718
> >        length |  -.0827432   .0547942    -1.51   0.136    -.1920267
>    .0265403
> >       foreign |  -1.707904    1.06711    -1.60   0.114    -3.836188
>    .4203806
> >         _cons |   50.53701   6.245835     8.09   0.000     38.08009
>    62.99394
> >
>
------------------------------------------------------------------------------
> >
> > . predict p, xb
> >
> > . su p
> >
> >      Variable |       Obs        Mean    Std. Dev.       Min
> Max
> >
>
-------------+--------------------------------------------------------
> >             p |        74     21.2973    4.747442   10.12822
> 30.51564
> >
> > . su mpg
> >
> >      Variable |       Obs        Mean    Std. Dev.       Min
> Max
> >
>
-------------+--------------------------------------------------------
> >           mpg |        74     21.2973    5.785503         12
>  41
> >
> > . adjust
> >
> >
>
---------------------------------------------------------------------------
> >       Dependent variable: mpg     Command: regress
> >     Variables left as is: weight, length, foreign
> >
>
---------------------------------------------------------------------------
> >
> > ----------------------
> >        All |         xb
> > ----------+-----------
> >            |    21.2973
> > ----------------------
> >       Key:  xb  =  Linear Prediction
> >
> >
> > The above shows that adjust and predict produce the same results.
> >
> > However, when I use the logistic regression example from page 20
> > (Reference A-J) for the adjust command, predict and adjust give
> > different results, as shown below. Can someone help me to
> understand
> > why this is so and what I might do to obtain the same results using
> adjust.
> >
> > Thanks,
> >
> > Fred
> >
> >
> >
> > . use http://www.stata-press.com/data/r9/lbw,clear
> > (Hosmer & Lemeshow data)
> >
> > . xi: logistic low age lwt i.race smoke,nolog
> > i.race            _Irace_1-3          (naturally coded; _Irace_1
> omitted)
> >
> > Logistic regression                               Number of obs   =
>
=== message truncated ===


-----------------------------------------
Maarten L. Buis
Department of Social Research Methodology
Vrije Universiteit Amsterdam
Boelelaan 1081
1081 HV Amsterdam
The Netherlands

visiting address:
Buitenveldertselaan 3 (Metropolitan), room Z434

+31 20 5986715

http://home.fsw.vu.nl/m.buis/
-----------------------------------------

Send instant messages to your online friends http://uk.messenger.yahoo.com
*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index