[Rd] Editing the "..." argument
J. R. M. Hosking
jh910 at juno.com
Sun Jul 6 20:59:03 CEST 2008
Mathieu Ribatet wrote:
> Dear all,
>
> I'd like tweaking the ... arguments that one user can pass in my
> function for fitting a model. More precisely, my objective function is
> (really) problematic to optimize using the "optim" function.
> Consequently, I'd like to add in the "control" argument of the latter
> function a "ndeps = rep(something, #par)" and/or "parscale = something"
> if the user has not specified it already.
>
> Do you know a way to deal with this point?
> In advance, thanks.
>
> Mathieu
Package lmom, recently added to CRAN, contains a function 'pelp' that
does exactly what you describe. Relevant parts of its code:
# Get the user-supplied arguments for the optimization functions
dotargs <- list(...)
# If user didn't supply a "control" argument, create one
if (is.null(dotargs$control)) dotargs<-c(dotargs,list(control=list()))
# If user didn't provide "ndeps" or "abstol" elements of the "control"
# argument, set them to our own defaults
if (is.null(dotargs$control$ndeps))
dotargs$control <- c(dotargs$control,list(ndeps=rep(acc,nshape)))
if (method!="L-BFGS-B" && is.null(dotargs$control$abstol))
dotargs$control <- c(dotargs$control,abstol=acc^2)
# Call the optimization function, optim()
opt <- do.call(optim,c(list(par=start[shape.pos]),fn=critfn,
method=method,dotargs))
J. R. M. Hosking
More information about the R-devel
mailing list