nlm {base} | R Documentation |
Non-Linear Minimization
Description
This function carries out a minimization of the function f
using a Newton-type algorithm. See the references for details.
This is a preliminary version of this function and it will probably change.
Usage
nlm(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, ...)
Arguments
f |
the function to be minimized. If the function value has
an attribute called |
p |
starting parameter values for the minimization. |
hessian |
if |
typsize |
an estimate of the size of each parameter at the minimum. |
fscale |
an estimate of the size of |
print.level |
this argument determines the level of printing
which is done during the minimization process. The default
value of |
ndigit |
the number of significant digits in the function |
gradtol |
a positive scalar giving the tolerance at which the
scaled gradient is considered close enough to zero to
terminate the algorithm. The scaled gradient is a
measure of the relative change in |
stepmax |
a positive scalar which gives the maximum allowable
scaled step length. |
steptol |
A positive scalar providing the minimum allowable relative step length. |
iterlim |
a positive integer specifying the maximum number of iterations to be performed before the program is terminated. |
check.analyticals |
a logical scalar specifying whether the analytic gradients and Hessians, if they are supplied, should be checked against numerical derivatives at the initial parameter values. This can help detect incorrectly formulated gradients or Hessians. |
... |
additional arguments to |
Value
A list containing the following components:
minimum |
the value of the estimated minimum of |
estimate |
the point at which the mininum value of
|
gradient |
the gradient at the estimated minimum of |
hessian |
the hessian at the estimated minimum of |
code |
an integer indicating why the optimization process terminated. 1: relative gradient is close to zero, current iterate is probably solution. 2: successive iterates within tolerance, current iterate is probably solution. 3: last global step failed to locate a point lower than
4: iteration limit exceeded. 5: maximum step size |
References
Dennis, J. E. and Schnabel, R. B. (1983) Numerical Methods for Unconstrained Optimization and Nonlinear Equations. Prentice-Hall, Englewood Cliffs, NJ.
Schnabel, R. B., Koontz, J. E. and Weiss, B. E. (1985) A modular system of algorithms for unconstrained minimization. ACM Trans. Math. Software, 11, 419–440.
See Also
optimize
for one-dimensional
minimization and uniroot
for root finding.
deriv
to calculate analytical derivatives.
Examples
f <- function(x) sum((x-1:length(x))^2)
nlm(f, c(10,10))
nlm(f, c(10,10), print.level = 2)
str(nlm(f, c(5), hessian = TRUE))
f <- function(x, a) sum((x-a)^2)
nlm(f, c(10,10), a=c(3,5))
f <- function(x, a)
{
res <- sum((x-a)^2)
attr(res, "gradient") <- 2*(x-a)
res
}
nlm(f, c(10,10), a=c(3,5))
## more examples, including the use of derivatives.
## Not run: demo(nlm)