2 comments below. On 07/07/2011 06:00 AM, r-help-requ...@r-project.org wrote: > Date: Wed, 6 Jul 2011 20:39:19 -0700 (PDT) > From: EdBo <n.bow...@gmail.com> > To: r-help@r-project.org > Subject: Re: [R] loop in optim > Message-ID: <1310009959045-3650592.p...@n4.nabble.com> > Content-Type: text/plain; charset=us-ascii > > I have one last theoretical question, I did not adjust my code prior so that > it maximise the likehood function. I googled that to make optim maximise you > multiply fn by -1. > > In my code, would that be the same as saying "-sum" on the "sum" part of my > code (see below)? > > llik = function(x) > { > al_j=x[1]; au_j=x[2]; sigma_j=x[3]; b_j=x[4] > sum(na.rm=T, > > ifelse(a$R_j< 0, log(1 / ( sqrt(2*pi) * sigma_j) )- >
The optimx package has a "maximize" control because we felt that the fnscale approach, while perfectly correct, is not comfortable for users and is not standard across other optimization tools. Note that this package is undergoing a fairly extensive overhaul at the moment (the development version is on R-forge in the project 'optimizer') to include some safeguards on functions that return NaN etc. as well as a number of other changes -- hopefully improvements. A second comment on this looping: Why do you not use the parameters from the last estimation as the starting parameters for the next? Unless you are expecting very extreme changes over the moving window of data, this should appreciably speed up the optimization. John Nash ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.