[Rd] nlm and optional arguments
Prof Brian D Ripley
ripley@stats.ox.ac.uk
Tue, 7 Mar 2000 07:06:28 +0000 (GMT)
On Mon, 6 Mar 2000, Ben Bolker wrote:
>
> It would be really nice if nlm took a set of "..." optional arguments
> that were passed through to the objective function. This level of hacking
> is probably slightly beyond me: is there a reason it would be technically
> difficult/inefficient? (I have a vague memory that it used to work this
> way either in S-PLUS or in some previous version of R, but I could easily
> be wrong.)
Well, ms and nlminb work that way in S-PLUS, and optimize and optim do in
R, so there is no real problem.
> Here's a hack in R code that works for me (basically copying the R code
> of nlm() but defining a temporary function that passes the optional
> arguments to the objective function), but I presume this would be cleaner
> and faster if implemented at a lower level ...
>
> nlm2 <- function(f, p, hessian=FALSE, typsize=rep(1,length(p)),
> fscale=1, print.level=0, ndigit=12, gradtol=1e-6,
> stepmax=max(1000 * sqrt(sum((p/typsize)^2)), 1000),
> steptol=1e-6, iterlim=100, check.analyticals=TRUE, ...) {
> tmpf <- function(x) {
> f(x,...)
> }
> nlm(tmpf,p,hessian=hessian,typsize=typsize,fscale=fscale,print.level=print.level,
> ndigit=ndigit,gradtol=gradtol,stepmax=stepmax,steptol=steptol,iterlim=iterlim,
> check.analyticals=check.analyticals)
> }
One can just put function(x) f(x, ...) as the first argumnet of the
.Internal call. It can also fairly easily be done internally (but
why bother?) I'll take a look at this, but why not try optim instead?
> As a matter of general principle, would the R-core folks prefer that
> "wishlist" items like this get sent to R-bugs (so they can be kept better
> track of) or not (so they don't clutter up the bugs database) ?
I'll leave that for the R-bugs-master.
--
Brian D. Ripley, ripley@stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272860 (secr)
Oxford OX1 3TG, UK Fax: +44 1865 272595
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._