Statalist The Stata Listserver


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

RE: st: nonlinear constraints


From   Maarten buis <[email protected]>
To   [email protected]
Subject   RE: st: nonlinear constraints
Date   Wed, 14 Feb 2007 12:57:33 +0000 (GMT)

--- Nick Cox <[email protected]> wrote:
> Just looking at this, I see scope for some simplifications: 
> In the line 
> 
>           quietly replace `lnf' = ln(exp(`theta')/(1+exp(`theta')))
> if $ML_y1==1
> 
> the log of a ratio is the difference of the logs 
> 
> 	= ln(exp(`theta')) - ln(1 + exp(`theta')) if $ML_y1 == 1
> 
> but then the first term simplifies too:
> 
> 	= `theta' - ln(1 + exp(`theta')) if $ML_y1 == 1
> 
> A similar story below:
> 
>           quietly replace `lnf' = ln(1/(1+exp(`theta'))) if $ML_y1==0
> 
> 	= ln(1) - ln(1+exp(`theta')) if $ML_y1==0	
> 	= - ln(1+exp(`theta')) if $ML_y1==0	
> 

In my tweak of this program I replaced the lines:
quietly replace `lnf' = ln(exp(`theta')/(1+exp(`theta'))) if $ML_y1==1
quietly replace `lnf' = ln(1/(1+exp(`theta'))) if $ML_y1==0

with:
quietly replace `lnf' = ln(invlogit( `theta')) if $ML_y1==1
quietly replace `lnf' = ln(invlogit(-`theta')) if $ML_y1==0

I've done this for two reasons:
1) It is less typing so less chance of a typo
2) I tend to trust the numerical properties of Stata functions more
then my own renderings of those functions. 

However my experience mirrors that of Richard's in that replacing  
gen `theta' = ...
by
gen double `theta' = ...
has a much bigger effect on the speed of convergence. 


-----------------------------------------
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/
-----------------------------------------


		
___________________________________________________________ 
Inbox full of unwanted email? Get leading protection and 1GB storage with All New Yahoo! Mail. http://uk.docs.yahoo.com/nowyoucan.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