Statalist


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

Re: st: logit results not matching with ml


From   Maarten buis <[email protected]>
To   [email protected]
Subject   Re: st: logit results not matching with ml
Date   Thu, 19 Jul 2007 07:53:12 +0100 (BST)

I see the error now: You are giving the likelihood instead of the log
likelihood. Your program should be:

*------------ begin example -----------------
capture program drop mymle1
program define mymle1
       version 8.0
       args lnf  theta1
       quietly replace `lnf' = ln(exp(`theta1')/       /*
                               */(1+exp(`theta1')))    /*
                     */ if $ML_y1 == 1
       quietly replace `lnf' = ln(1/(1+exp(`theta1'))) /*
                     */ if $ML_y1  == 0

end

sysuse auto

ml model lf mymle1 (for  = pr mpg wei)
ml search
ml maximize

logit for pri mpg wei
*------------- end example -------------------

Hope this helps,
Maarten

--- Maarten buis <[email protected]> wrote:

> I don't see any errors in your likelihood. You might want to change
> the
> scale of the variable pol_flow to measure whatever it measures in
> milions, i.e. devide pol_flow by 1000000. The reason is that the
> parameter for that variable is much much smaller than the others but
> the standard error is not dramatically large with respect to that
> estimate (though it is still insignigicant). This might cause
> numerical
> problems.
> 
> Hope this helps,
> Maarten
> 
> --- Tulika Narayan <[email protected]> wrote:
> 
> > Hello,
> > 
> > Stata version 8.0
> > 
> > I am trying to run a non linear logit but before I do that, just to
> > test my
> > work I wrote the logit using stata's ml command but cannot get it
> to
> > replacate the logit results. In fact the likelihood does not even
> > converge.
> > 
> > Here is the logit command I use
> > 
> > logit green_present water_eda mixing_zone i_human temp_avg  sal_avg
> > oxy_avg
> > coll_bottom   oth_crab   shell_present pol_flow
> > 
> > The results
> > 
> > Iteration 0:   log likelihood = -37.362775
> > Iteration 1:   log likelihood =  -21.42294
> > Iteration 2:   log likelihood = -19.458412
> > Iteration 3:   log likelihood = -18.924528
> > Iteration 4:   log likelihood = -18.641708
> > Iteration 5:   log likelihood =  -18.61557
> > Iteration 6:   log likelihood = -18.615379
> > 
> > Logit estimates                                   Number of obs   =
> > 58
> >                                                    LR chi2(10)    
> =
> > 37.49
> >                                                    Prob > chi2    
> =
> > 0.0000
> > Log likelihood = -18.615379                       Pseudo R2       =
> > 0.5018
> > 
> >
>
------------------------------------------------------------------------------
> > green_pres~t |      Coef.   Std. Err.      z    P>|z|     [95%
> Conf.
> > Interval]
> >
>
-------------+----------------------------------------------------------------
> > water_edac~a |   .0093596   .0085614     1.09   0.274    -.0074204
> > 0261396
> >   mixing_zone |  -.0115959   .0109941    -1.05   0.292    -.0331439
> > 009952
> >       i_human |  -.4338438   .4151365    -1.05   0.296    -1.247496
> > 3798089
> >      temp_avg |  -.5166932   .2147708    -2.41   0.016    -.9376362
> > -.0957502
> >       sal_avg |  -.0085234   .0685798    -0.12   0.901    -.1429375
> > 1258906
> >       oxy_avg |  -.4012752   .4969768    -0.81   0.419    -1.375332
> > 5727814
> >   coll_bottom |  -.1368686   .0534403    -2.56   0.010    -.2416096
> > -.0321276
> >      oth_crab |  -.8857099   .5262265    -1.68   0.092    -1.917095
> > 145675
> > shell_pres~t |   .5593585   .4635706     1.21   0.228    -.3492232
> > 1.46794
> >      pol_flow |   4.28e-07   4.20e-07     1.02   0.308    -3.95e-07
>  
> >  1.25
> > e-06
> >         _cons |   16.81088   7.657698     2.20   0.028     1.802072
> > 31.8197
> >
>
------------------------------------------------------------------------------
> > 
> > note: 0 failures and 1 success completely determined.
> > 
> > Here is the equivalent ml command.
> > 
> > capture program drop mymle1
> > program define mymle1
> > 
> >        version 8.0
> >        args lnf  theta1
> >        quietly replace `lnf' = exp(`theta1')/(1+exp(`theta1')) if
> > $ML_y1 ==
> > 1
> >        quietly replace `lnf' = 1/(1+exp(`theta1'))  if $ML_y1  == 0
> > 
> > end
> > 
> > local x1 "water_eda mixing_zone i_human temp_avg  sal_avg oxy_avg
> > coll_bottom   oth_crab   shell_present pol_flow"
> > ml model lf mymle1 (green_present  = `x1')
> > ml search
> > 
> > 
> >   ml maximize, difficult
> > 
> > Results
> > 
> > initial:       log likelihood =         29
> > alternative:   log likelihood =  31.204268
> > rescale:       log likelihood =         38
> > numerical derivatives are approximate
> > flat or discontinuous region encountered
> > Iteration 0:   log likelihood =         38  (not concave)
> > Iteration 1:   log likelihood =  40.018216  (not concave)
> > Iteration 2:   log likelihood =  42.041076  (not concave)
> > Iteration 3:   log likelihood =  43.042035  (not concave)
> > Iteration 4:   log likelihood =  43.042049  (not concave)
> > Iteration 5:   log likelihood =  43.042098  (not concave)
> > Iteration 6:   log likelihood =  43.042103  (not concave)
> > Iteration 7:   log likelihood =  43.042104  (not concave)
> > 
> >                                                    Number of obs  
> =
> > 58
> >                                                    Wald chi2(0)   
> =
> > .
> > Log likelihood =  43.042104                       Prob > chi2     =
> > .
> > 
> >
>
------------------------------------------------------------------------------
> > green_pres~t |      Coef.   Std. Err.      z    P>|z|     [95%
> Conf.
> > Interval]
> >
>
-------------+----------------------------------------------------------------
> > water_edac~a |   .7304996          .        .       .            .
> > .
> >   mixing_zone |  -45.97343          .        .       .            .
> > .
> >       i_human |   .9961338          .        .       .            .
> > .
> >      temp_avg |   3.576235          .        .       .            .
> > .
> >       sal_avg |   10.37114          .        .       .            .
> > .
> >       oxy_avg |   2.229273          .        .       .            .
> > .
> >   coll_bottom |   -.008225          .        .       .            .
> > .
> >      oth_crab |   .0822529          .        .       .            .
> > .
> > shell_pres~t |   .3959996          .        .       .            .
> > .
> >      pol_flow |   .0000723          .        .       .            .
> > .
> >         _cons |   64.28164          .        .       .            .
> > .
> >
>
------------------------------------------------------------------------------
> > 
> > 
> > To help out the program, I gave the initial values from my logit
> > 
> > ml init _cons =16.81 water_ = 0.009 mixing_zone = -0.115 i_human =
> > -0.4338
> > temp_avg =-0.516 sal_avg = -0.008 oxy_avg =-.401 coll_bott =-.136
> > oth_crab
> > =-.885 shell_p = 0.559 pol_flow = 0.00000428
> > ml maximize, difficult
> > 
> > here are the results;
> > 
> > Iteration 548: log likelihood =  50.644631  (backed up)
> > Iteration 549: log likelihood =  50.998166
> > Iteration 550: log likelihood =  50.999718
> > Iteration 551: log likelihood =  50.999727
> > Iteration 552: log likelihood =  50.999729  (backed up)
> > 
> >                                                    Number of obs  
> =
> > 58
> >                                                    Wald chi2(10)  
> =
> > 0.03
> > Log likelihood =  50.999729                       Prob > chi2     =
> > 1.0000
> > 
> >
>
------------------------------------------------------------------------------
> > green_pres~t |      Coef.   Std. Err.      z    P>|z|     [95%
> Conf.
> > Interval]
> >
> 
=== 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/
-----------------------------------------


      ___________________________________________________________ 
Yahoo! Mail is the world's favourite email. Don't settle for less, sign up for
your free account today http://uk.rd.yahoo.com/evt=44106/*http://uk.docs.yahoo.com/mail/winter07.html 
*
*   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