Running a likelihood profile on a FIMS model
likelihood_profile.Rmd
library(FIMSdiags)
library(FIMS)
#devtools::load_all()
packageVersion("FIMS")
#> [1] '0.7.1'
clear()Set up FIMS model
Following the minimal demo vignette, we will set up a FIMS model and run it.
# Load sample data
data("data1")
# Prepare data for FIMS model
data_4_model <- FIMSFrame(data1)
# Create parameters
parameters <- data_4_model |>
create_default_configurations() |>
create_default_parameters(data = data_4_model)
# Run the model with optimization
base_model <- parameters |>
initialize_fims(data = data_4_model) |>
fit_fims(optimize = TRUE)
#> ✔ Starting optimization ...
#> ℹ Restarting optimizer 3 times to improve gradient.
#> ℹ Maximum gradient went from 0.02469 to 0.00037 after 3 steps.
#> ✔ Finished optimization
#> ✔ Finished sdreport
#> ℹ FIMS model version: 0.7.1
#> ℹ Total run time was 10.08182 seconds
#> ℹ Number of parameters: fixed_effects=77, random_effects=0, and total=77
#> ℹ Maximum gradient= 0.00037
#> ℹ Negative log likelihood (NLL):
#> • Marginal NLL= 3240.1261
#> • Total NLL= 3240.1261
#> ℹ Terminal SB= 1803.27712
# Clear memory post-run
clear()Run likelihood profile
Once we have a model that is fit, we can run a likelihood analysis to
see the impact of each data type on a given parameter. In this example,
we will test the impact on R0 but any value can be tested by changing
the parameter_name argument. The parameter name must match
what is
like_fit <- run_fims_likelihood(
model = base_model,
parameters = parameters,
parameter_name = "log_rzero",
data = data1,
min = -1,
max = 1,
length = 10
)
plot_likelihood(like_fit)
clear()