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

st: Proposal for a grid search for appropriate -nl- starting values


From   Jonathan Beck <[email protected]>
To   [email protected]
Subject   st: Proposal for a grid search for appropriate -nl- starting values
Date   Tue, 19 Jul 2005 17:51:38 +0200

Dear Listeners,

although my experience with -nl- estimations is only a couple of months old, I noticed a frequent advice in Stata manuals, FAQs and Statalist regarding -nl- problems: "try different starting values".

Papers that present nonlinear least squares results often say they implement a "grid search" for starting values: they evaluate many different sets of starting values before chossing one for estimation. Accordingly, SAS allows you to specifiy a set of values for each parameter in your nonlinear function, calculates the sum of squared residuals (SSR) for each combination of starting values, and proceeds with estimation using that combination with the lowest SSR.

This approach seems reasonable to me, but I could not find a similar program for Stata. Did I miss something? Does it not make sense?

Anyhow, I tried to implement it myself, despite the fact that I am not an experienced Stata programmer. Below is the result.
It seems to work, but still there may be bugs and the code is most probably inefficient.

I would be happy to get your comments on this!

Two rather specific questions are listed below the code.

-----begin Stata code
version 8.2
/* write your -nl- program (here: 3 parameters to be estimated)*/
program nlMyNLmodel
* (skipped)
end

/* define grid of starting values: a vector for each parameter*/
matrix vA=(.05,.15,.25)
matrix vB=(.3,.6,.9)
matrix vC=(1,2,3)

/* get SSR (sum of squared residuals) for all 3^3=27 combinations
and remember those starting values that led to the lowest SSR */
local minssr=.
local bestlp = .
local bestls = .
local bestlth = .
forval i=1/3 {
local sA`i'=vA[1,`i']
forval j=1/3 {
local sB`j'=vB[1,`j']
forval k=1/3 {
local sC`k'=vC[1,`k']
capture nl MyNLmodel indepVariable, /*
*/ init(A=`sA`i'',B=`sB`j'',C=`sC`k'') iterate(1)
if e(rss)<`minssr' {
display "The lowest first-round SSR is currently " e(rss)
local bestA = `sA`i''
local bestB = `sB`j''
local bestC = `sC`k''
local minssr=e(rss)
}
}
}
}

/* estimate nl-program for chosen set of starting values*/
display "Chosen starting values: A=`bestA', B=`bestB', C=`bestC'"
nl MyNLmodel indepVariable, init(A=`bestA',B=`bestB',C=`bestC')
-----end Stata code

1) The above procedure is not completely equivalent to one in SAS, because I obtain SSR values from -nl- results after, not before the first iteration (SSR at iteration 0 is not standard -nl- output, although it is displayed on the screen).
Methodologically, does it make a difference whether you evaluate the starting values before or after iteration 1?

2) Have other criteria than SSR been proposed for evaluating different starting values?

Thank you for reading this far!
Jonathan Beck
http://www.wz-berlin.de/mp/wiw/people/beck.en.htm
*
* 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