nlm
Non-Linear Minimization

Description

Minimizes multivariate function with no contraints using Dennis and Schnabel optif9 code.

Usage

nlm(f, p, ..., hessian = FALSE, typsize = rep(1, length(p)), fscale = 1, 
     print.level = 0, ndigit = 12, gradtol = 1e-06, stepmax = max(1000 * sqrt(sum((p/typsize)^2)), 1000), 
     steptol = 1e-06, iterlim = 100, check.analyticals = TRUE)

Arguments

f the function to minimize. It must take a numeric vector argument, which is varied by nlm as it searches for a minimum, and it must return a numeric scalar value. f can also take other arguments, which are passed from the ... arguments to nlm.
p a numeric vector. An initial parameter value for minimization. Missing and non-finite values are not allowed.
... additional arguments to pass to f.
hessian a logical value. If TRUE, computes and returns the matrix of second partial derivatives at the final estimate. The default is FALSE.
typsize a numeric vector the same length as p. Specifies the typical size of parameter elements. This might be needed if the parameters differ in size by orders of magnitude.
fscale a numeric object. Specifies the typical size of f near its minimum.
print.level an integer value. This argument is not used.
ndigit The number of good digits in function f.
gradtol the tolerance at which the scaled gradient is considered close enough to zero to terminate the algorithm.
stepmax the maximum allowable step size for f.
steptol the relative step size at which successive iterations are considered close enough to terminate the algorithm.
iterlim the maximum number of allowable iterations to perform before termination. The default is 100. Each iteration usually involves many function evaluations as it chooses a direction and executes a line search in that direction.
check.analyticals a logical value. This argument is not used.

Details

nlm is an interface to a modification of the CMLIB/UNCMIN subroutine optif9, based on Dennis and Schnabel (1983) and described in detail in http://www1.fpl.fs.fed.us/uncmin_userguide.pdf. The major modification was to allow the objective function to have a second argument pointing to data that is constant over the course of the minimization. Also, optif9 itself does not compute the Hessian at the minimum. (It returns the Hessian at the penultimate point considered.) Our version does so, if hessian=TRUE is specified.
With nlm, you cannot supply analytical gradient or hessian functions, even though optif9 supports such usage. The 'iexp' parameter to optif9 is fixed at 1, meaning that the function should be considered expensive to compute.
Value
returns a list with the following components:
minimumthe minimum value of the function that could be found.
estimatethe numeric vector of length length(p) such that f(estimate,...) == minimum.
gradientthe numeric vector of length length(p); the approximate partial derivatives of f at p=estimate.
hessiana length(p) by length(p) numeric matrix; the approximate second partial derivatives of f at p=estimate. This is omitted unless you specify hessian=TRUE when calling nlm.
codea termination code. In 1..5, 1, 2, and 3 mean that a plausable minimum was found. No warning is given when the search is abandoned.
1 indicates a relative gradient close to zero. The current iteration is probably the solution.
2 indicates successive iterates within tolerance. The current iteration is probably the solution.
3 indicates that the last global step failed to locate a point lower than the estimate. Either the estimate is an approximate local minimum of the function, and the function is too non-linear for this algorithm, or steptol is too large.
4 indicates that the iteration limit is exceeded, and the algorithm failed.
5 indicates that the maximum step size exceeded 5 consecutive times. Either the function is unbounded below and becomes asymptotic to a finite value from above in some direction, or stepmax is too small.
iterationsthe iteration count of algorithm process.
References
Dennis, J. E. and Schnabel, R. B. 1983. Numerical Methods for Unconstrained Optimization and Nonlinear Equations. Englewood Cliffs, NJ: Prentice-Hall.
Schnabel, R. B., Koontz, J. E. and Weiss, B. E. 1985. A modular system of algorithms for unconstrained minimization. ACM Transactions on Mathematical Software. Volume 11. 419-440.
An Unconstrained Nonlinear Optimization Solver: A User's Guide. http://www1.fpl.fs.fed.us/uncmin_userguide.pdf. Last modified 08 Aug 2005 14:55:36 GMT.
See Also
nlminb, optim, optimize, nls.
Examples
nlm(function(x,offset,scale) sum((x-offset)^2),
    offset = c(10,5), p = c(0,0))
x0 <- c(11,12,19,23,22)
nlm(function(x,offset,lambda) sum( (x-offset)^2 ) + lambda * sum( diff(diff(x))^2 ),
    offset = x0, lambda = 2, p = x0, hessian = TRUE)
Package stats version 6.1.4-13
Package Index