Description Usage Arguments Value Author(s) See Also Examples
This function extracts the Hessian of the objective function at optimum. The Hessian information should be supplied by the underlying optimization algorithm, possibly by an approximation.
1 2 3 |
x |
an optimization result of class ‘maxim’ or ‘maxLik’ |
... |
other arguments for methods |
A numeric matrix, the Hessian of the model at the estimated parameter
values. If the maximum is flat, the Hessian
is singular. In that case you may want to invert only the
non-singular part of the matrix. You may also want to fix certain
parameters (see activePar
).
Ott Toomet
maxLik
, activePar
, condiNumber
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | # log-likelihood for normal density
# a[1] - mean
# a[2] - standard deviation
ll <- function(a) sum(-log(a[2]) - (x - a[1])^2/(2*a[2]^2))
x <- rnorm(100) # sample from standard normal
ml <- maxLik(ll, start=c(1,1))
# ignore eventual warnings "NaNs produced in: log(x)"
summary(ml) # result should be close to c(0,1)
hessian(ml) # How the Hessian looks like
sqrt(-solve(hessian(ml))) # Note: standard deviations are on the diagonal
#
# Now run the same example while fixing a[2] = 1
mlf <- maxLik(ll, start=c(1,1), activePar=c(TRUE, FALSE))
summary(mlf) # first parameter close to 0, the second exactly 1.0
hessian(mlf)
# Note that now NA-s are in place of passive
# parameters.
# now invert only the free parameter part of the Hessian
sqrt(-solve(hessian(mlf)[activePar(mlf), activePar(mlf)]))
# gives the standard deviation for the mean
|
Loading required package: miscTools
Please cite the 'maxLik' package as:
Henningsen, Arne and Toomet, Ott (2011). maxLik: A package for maximum likelihood estimation in R. Computational Statistics 26(3), 443-458. DOI 10.1007/s00180-010-0217-1.
If you have questions, suggestions, or comments regarding the 'maxLik' package, please use a forum or 'tracker' at maxLik's R-Forge site:
https://r-forge.r-project.org/projects/maxlik/
--------------------------------------------
Maximum Likelihood estimation
Newton-Raphson maximisation, 6 iterations
Return code 2: successive function values within tolerance limit
Log-Likelihood: -60.20196
2 free parameters
Estimates:
Estimate Std. error t value Pr(> t)
[1,] 0.0393 0.1107 0.355 0.723
[2,] 1.1074 0.0783 14.142 <2e-16 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
--------------------------------------------
[,1] [,2]
[1,] -81.548989783 -7.105427e-03
[2,] -0.007105427 -1.630909e+02
[,1] [,2]
[1,] 0.1107365 NaN
[2,] NaN 0.07830422
Warning message:
In sqrt(-solve(hessian(ml))) : NaNs produced
--------------------------------------------
Maximum Likelihood estimation
Newton-Raphson maximisation, 2 iterations
Return code 1: gradient close to zero
Log-Likelihood: -61.31731
1 free parameters
Estimates:
Estimate Std. error t value Pr(> t)
[1,] 0.0393 0.1000 0.393 0.694
[2,] 1.0000 0.0000 NA NA
--------------------------------------------
[,1] [,2]
[1,] -100.0018 NA
[2,] NA NA
[,1]
[1,] 0.09999911
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.