Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

NR

Newton-Raphson method


Description

Newton-Raphson method

Usage

NR(
  start,
  objective = NULL,
  gradient = NULL,
  hessian = NULL,
  control,
  args = NULL,
  ...
)

Arguments

start

Starting value

objective

Optional objective function (used for selecting step length)

gradient

gradient

hessian

hessian (if NULL a numerical derivative is used)

control

optimization arguments (see details)

args

Optional list of arguments parsed to objective, gradient and hessian

...

additional arguments parsed to lower level functions

Details

control should be a list with one or more of the following components:

  • trace integer for which output is printed each 'trace'th iteration

  • iter.max number of iterations

  • stepsize: Step size (default 1)

  • nstepsize: Increase stepsize every nstepsize iteration (from stepsize to 1)

  • tol: Convergence criterion (gradient)

  • epsilon: threshold used in pseudo-inverse

  • backtrack: In each iteration reduce stepsize unless solution is improved according to criterion (gradient, armijo, curvature, wolfe)

Examples

# Objective function with gradient and hessian as attributes
f <- function(z) {
   x <- z[1]; y <- z[2]
   val <- x^2 + x*y^2 + x + y
   structure(val, gradient=c(2*x+y^2+1, 2*y*x+1),
             hessian=rbind(c(2,2*y),c(2*y,2*x)))
}
NR(c(0,0),f)

# Parsing arguments to the function and
g <- function(x,y) (x*y+1)^2
NR(0, gradient=g, args=list(y=2), control=list(trace=1,tol=1e-20))

lava

Latent Variable Models

v1.6.10
GPL-3
Authors
Klaus K. Holst [aut, cre], Brice Ozenne [ctb], Thomas Gerds [ctb]
Initial release
2021-09-01

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.