Numerical aproximation of the Hessian of a function.
hessian(f, x0, ...)
(type: numeric) name of function that defines log likelihood (or negative of it).
(type: numeric) scalar or vector of parameters that give the point at which you want the hessian estimated (usually will be the mle).
Additional arguments to be passed to the function.
An n×n matrix of 2nd derivatives, where n is the length of
x0
.
Computes the numerical approximation of the Hessian of f
, evaluated at
x0
.
Usually needs to pass additional parameters (e.g. data). N.B. this uses no
numerical sophistication.
# Variance of the maximum likelihood estimator for mu parameter in
# gaussian data
loglik <- function(series, x, sd = 1) {
-sum(log(dnorm(series, mean = x, sd = sd)))
}
sqrt(c(var(malleco) / length(malleco), diag(solve(hessian(
f = loglik, x = mean(malleco), series = malleco,
sd = sd(malleco)
)))))
#> [1] 0.00607085 0.00607085