This function takes the output of `optim`, `newton_raphson`, or `sim_anneal` and turns it into an `mle_numerical` (subclass of `mle`) object.
Source:R/mle_numerical.R
mle_numerical.RdThis function takes the output of `optim`, `newton_raphson`, or `sim_anneal` and turns it into an `mle_numerical` (subclass of `mle`) object.
Usage
mle_numerical(sol, options = list(), superclasses = NULL)Examples
# Fit exponential distribution using optim
set.seed(123)
x <- rexp(100, rate = 2)
# Log-likelihood for exponential distribution
loglik <- function(rate) {
if (rate <= 0) return(-Inf)
sum(dexp(x, rate = rate, log = TRUE))
}
# Optimize (maximize by setting fnscale = -1)
result <- optim(
par = 1,
fn = loglik,
method = "Brent",
lower = 0.01, upper = 10,
hessian = TRUE,
control = list(fnscale = -1)
)
# Wrap in mle_numerical
fit <- mle_numerical(result, options = list(nobs = length(x)))
params(fit)
#> [1] 1.91256
se(fit)
#> [1] 0.191256