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

numerical_deriv

Compute numerical derivatives


Description

Compute numerical derivatives using forward/backward difference, central difference, or Richardson extrapolation.

Usage

numerical_deriv(
  f,
  par,
  ...,
  delta = 1e-05,
  gradient = TRUE,
  type = "Richardson"
)

Arguments

f

the objective function being evaluated

par

a vector of parameters

...

additional arguments to be passed to f

delta

the term used to perturb the f function. Default is 1e-5

gradient

logical; compute the gradient terms? If FALSE then the Hessian is computed instead

type

type of difference to compute. Can be either 'forward' for the forward difference, 'central' for the central difference, or 'Richardson' for the Richardson extrapolation (default). Backward difference is achieved by supplying a negative delta value with 'forward'. When type = 'Richardson', the default value of delta is increased to delta * 1000 for the Hessian and delta * 10 for the gradient to provide a reasonable perturbation starting location (each delta is halved at each iteration).

Author(s)

Examples

## Not run: 
f <- function(x) 3*x[1]^3 - 4*x[2]^2
par <- c(3,8)

# grad = 9 * x^2 , -8 * y
(actual <- c(9 * par[1]^2, -8 * par[2]))
numerical_deriv(f, par, type = 'forward')
numerical_deriv(f, par, type = 'central')
numerical_deriv(f, par, type = 'Richardson') # default

# Hessian = h11 -> 18 * x, h22 -> -8, h12 -> h21 -> 0
(actual <- matrix(c(18 * par[1], 0, 0, -8), 2, 2))
numerical_deriv(f, par, type = 'forward', gradient = FALSE)
numerical_deriv(f, par, type = 'central', gradient = FALSE)
numerical_deriv(f, par, type = 'Richardson', gradient = FALSE) # default


## End(Not run)

mirt

Multidimensional Item Response Theory

v1.33.2
GPL (>= 3)
Authors
Phil Chalmers [aut, cre] (<https://orcid.org/0000-0001-5332-2810>), Joshua Pritikin [ctb], Alexander Robitzsch [ctb], Mateusz Zoltak [ctb], KwonHyun Kim [ctb], Carl F. Falk [ctb], Adam Meade [ctb], Lennart Schneider [ctb], David King [ctb], Chen-Wei Liu [ctb], Ogreden Oguzhan [ctb]
Initial release

We don't support your browser anymore

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