Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: nonlinearleastsquare


From   May Boggess <[email protected]>
To   [email protected]
Subject   Re: st: nonlinearleastsquare
Date   13 Nov 2003 09:14:05 -0600

On Thursday morning, Andreas Aschbacher wrote that he was getting an
error message when trying to run a nonlinear least squares.
 
Perhaps it is possible that the invalid name error is coming from what
we see as `1'. His code had the line:

> if "`1'" == "?"{      //     alt+0145 1 alt+0146    <=>     for  `1'  

I think the comment Andreas has to the right, is saying that he is using
different characters (alt+0145 and alt+0146) instead of ` and '. Someone
who is more familar with a European keyboard may be able to say if this
could be the cause of the problem.

> my ambition is to make nonlinear-fit for z(d) = a1*exp(-((d-a2)/a3)^2) +
> a4*exp(-((d-a5)/a6)^2)
> with LevenbergMarquardt therefore I need this example above.
> Thank you for any help.  andreas

Below is an example using the function Andreas is interested in. It's
convergence seems very sensitive to changes in domain and parameters.

yours,
-- May

[email protected]


clear
set obs 100
gen d=uniform()                    
gen y= 0.3*exp(-((d-0.2)/0.3)^2) + 0.4*exp(-((d-0.5)/0.6)^2)         
sort d
twoway line y d
                                                                               
capture program drop nlexample
program nlexample
version 8
if "`1'" == "?"{
 global S_1 "a1 a2 a3 a4 a5 a6"
 global a1 = 0.5
 global a2 = 0.5
 global a3 = 0.5
 global a4 = 0.5
 global a5 = 0.5
 global a6 = 0.5
 exit
}
replace `1'=$a1*exp(-((d-$a2)/$a3)^2) +
$a4*exp(-((d-$a5)/$a6)^2)          
end
                                                                               
nl example y


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