This function estimate the profile likelihood and 95% CI for a one or two parameter model
Usage
calculate_profile(
log_likelihood,
data_in,
n_param,
a_initial,
b_initial = NULL,
precision = 0.01
)
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)- precision
Parameter defining how fine-scale the grid search is for the profile likelihood
Examples
# example of a one parameter model
data_in <- rnorm(n = 100, mean = 1, sd = 2)
log_likelihood <- function(x,a) dnorm(x, a, 2, log = TRUE)
n_param <- 1
a_initial <- 0.5
calculate_profile(
log_likelihood = log_likelihood,
data_in = data_in,
n_param = 1,
a_initial = 4,
precision = 0.1
)
#> $estimate
#> [1] 1.141578
#>
#> $profile_out
#> a1 a2
#> 0.7495856 1.5335712
#>
# examle of a two parameter model
data_in <- rnorm(n = 100, mean = 1, sd = 1)
log_likelihood <- function(x,a,b) dnorm(x, a, b, log = TRUE)
n_param <- 2
a_initial <- 0.5
b_initial <- 1
calculate_profile(
log_likelihood = log_likelihood,
data_in = data_in,
n_param = 2,
a_initial = 4,
b_initial = 2,
precision = 0.1
)
#> $estimate
#> a b
#> 1.115020 1.009153
#>
#> $profile_out
#> a1 a2 b1 b2
#> 0.9641402 1.3641402 0.8729176 1.1453889
#>