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.)
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)
}
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) ?
--
Ben Bolker bolker@zoo.ufl.edu
Zoology Department, University of Florida http://www.zoo.ufl.edu/bolker
318 Carr Hall/Box 118525 tel: (352) 392-5697
Gainesville, FL 32611-8525 fax: (352) 392-3704
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Apparently Analagous Threads
- Viewing source code for .Internal functions
- Sometimes having problems finding a minimum using optim(), optimize(), and nlm() (while searching for noncentral F parameters)
- Wierd nlm behaviour in 2.10.1 and 2.12.0 [Sec=Unclassified]
- Understanding nonlinear optimization and Rosenbrock's banana valley function?
- typsize and fscale arguments to nlm