Calculates the maximum-likelihood estimate for a given likelihood function
Source:R/estimate_mle.R
estimate_mle.Rd
This function calculates the maximum-likelihood estimate for a one or two parameter model
Arguments
- log_likelihood
Log-likelihood function in form
function(x, a)
(one parameter model) orfunction(x, a, b)
(two parameter model)- data_in
Vector of observations to be evaluated in log_likelihood, with overall likelihood given by sum(log_likelihood)
- n_param
Number of parameters in
log_likelihood
model- a_initial
Initial guess for parameter
a
- b_initial
Initial guess for parameter
b
(if a two parameter model, otherwise default is NULL)
Examples
# example for a one parameter model
sim_data <- rnorm(100, 5, 2)
log_likelihood <- function(x, a) dnorm(x, a, 2, log = TRUE)
a_initial <- 4
estimate_mle(
log_likelihood = log_likelihood,
data_in = sim_data,
n_param = 1,
a_initial = 1
)
#> $estimate
#> [1] 4.939905
#>
#> $log_likelihood
#> [1] -215.8972
#>
# example for a two parameter model
sim_data <- rnorm(100, 5, 2)
log_likelihood <- function(x, a, b) dnorm(x, a, b, log = TRUE)
a_initial <- 4
b_initial <- 1
estimate_mle(
log_likelihood = log_likelihood,
data_in = sim_data,
n_param = 2,
a_initial = 1,
b_initial = 1
)
#> $estimate
#> a b
#> 5.377671 1.974567
#>
#> $log_likelihood
#> [1] -209.9133
#>