# nlm

0th

Percentile

##### Non-Linear Minimization

This function carries out a minimization of the function f using a Newton-type algorithm. See the references for details.

Keywords
nonlinear, optimize
##### 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, returning a single numeric value. This should be a function with first argument a vector of the length of p followed by any other arguments specified by the … argument.

If the function value has an attribute called gradient or both gradient and hessian attributes, these will be used in the calculation of updated parameter values. Otherwise, numerical derivatives are used. deriv returns a function with suitable gradient attribute and optionally a hessian attribute.

p

starting parameter values for the minimization.

additional arguments to be passed to f.

hessian

if TRUE, the hessian of f at the minimum is returned.

typsize

an estimate of the size of each parameter at the minimum.

fscale

an estimate of the size of f at the minimum.

print.level

this argument determines the level of printing which is done during the minimization process. The default value of 0 means that no printing occurs, a value of 1 means that initial and final details are printed and a value of 2 means that full tracing information is printed.

ndigit

the number of significant digits in the function f.

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 f in each direction p[i] divided by the relative change in p[i].

stepmax

a positive scalar which gives the maximum allowable scaled step length. stepmax is used to prevent steps which would cause the optimization function to overflow, to prevent the algorithm from leaving the area of interest in parameter space, or to detect divergence in the algorithm. stepmax would be chosen small enough to prevent the first two of these occurrences, but should be larger than any anticipated reasonable step.

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.

##### Details

Note that arguments after … must be matched exactly.

If a gradient or hessian is supplied but evaluates to the wrong mode or length, it will be ignored if check.analyticals = TRUE (the default) with a warning. The hessian is not even checked unless the gradient is present and passes the sanity checks.

The C code for the “perturbed” cholesky, choldc() has had a bug in all R versions before 3.4.1.

From the three methods available in the original source, we always use method “1” which is line search.

The functions supplied should always return finite (including not NA and not NaN) values: for the function value itself non-finite values are replaced by the maximum positive value with a warning.

##### Value

A list containing the following components:

minimum

the value of the estimated minimum of f.

estimate

the point at which the minimum value of f is obtained.

the gradient at the estimated minimum of f.

hessian

the hessian at the estimated minimum of f (if requested).

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 estimate. Either estimate is an approximate local minimum of the function or steptol is too small.

4:

iteration limit exceeded.

5:

maximum step size stepmax exceeded five consecutive times. Either the function is unbounded below, becomes asymptotic to a finite value from above in some direction or stepmax is too small.

iterations

the number of iterations performed.

##### 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 Transactions on Mathematical Software, 11, 419--440. 10.1145/6187.6192.

optim and nlminb.

constrOptim for constrained optimization, optimize for one-dimensional minimization and uniroot for root finding. deriv to calculate analytical derivatives.

For nonlinear regression, nls may be better.

• nlm
##### Examples
library(stats) # NOT RUN { f <- function(x) sum((x-1:length(x))^2) nlm(f, c(10,10)) nlm(f, c(10,10), print.level = 2) utils::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) # } 
Documentation reproduced from package stats, version 3.6.2, License: Part of R 3.6.2

### Community examples

Looks like there are no examples yet.
{"ft_lang_label":"__label__en","ft_lang_prob":0.72683203,"math_prob":0.97309303,"size":5269,"snap":"2020-34-2020-40","text_gpt3_token_len":1288,"char_repetition_ratio":0.11547958,"word_repetition_ratio":0.02291918,"special_character_ratio":0.2347694,"punctuation_ratio":0.14514515,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9928722,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2020-08-04T00:08:26Z\",\"WARC-Record-ID\":\"<urn:uuid:b82671a9-2d1c-4ae3-a7e5-8c1c9aa3f930>\",\"Content-Length\":\"21784\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:dd602eef-f5df-4b1b-87fb-922f3ddb6e8c>\",\"WARC-Concurrent-To\":\"<urn:uuid:dbd0b34a-e05d-46c0-9e93-a95802a1f89b>\",\"WARC-IP-Address\":\"35.153.91.168\",\"WARC-Target-URI\":\"https://www.rdocumentation.org/packages/stats/versions/3.6.2/topics/nlm\",\"WARC-Payload-Digest\":\"sha1:FBJTDKCDGN6QDKOJYKTULNRCW4AWZV6S\",\"WARC-Block-Digest\":\"sha1:LB46J24J2LXP7KXAM3HFMB7LKG5TVOZ3\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2020/CC-MAIN-2020-34/CC-MAIN-2020-34_segments_1596439735836.89_warc_CC-MAIN-20200803224907-20200804014907-00248.warc.gz\"}"}