quickfit is an R
package to help with simple model fitting tasks in epidemiology.
quickfit is developed at the Centre for the Mathematical Modelling of Infectious Diseases at the London School of Hygiene and Tropical Medicine as part of the Epiverse Initiative.
Installation
You can install the development version of quickfit from GitHub with:
# check whether {pak} is installed
if(!require("pak")) install.packages("pak")
pak::pak("epiverse-trace/quickfit")
Quick start
These examples illustrate some of the current functionalities:
Generate some simulated data, define a likelihood, then estimate MLE, or MLE and 95% confidence interval based on profile likelihood:
sim_data <- rnorm(50, 4, 2)
# Define likelihood function
log_l <- function(x,a,b) dnorm(x, a, b, log = TRUE)
# Estimate MLE
estimate_mle(log_l, sim_data, n_param = 2, a_initial = 3, b_initial = 1)
#> $estimate
#> a b
#> 3.945122 2.223727
#>
#> $log_likelihood
#> [1] -110.9108
# Estimate 95% CI based on profile likelihood
calculate_profile(
log_l,
data_in = sim_data,
n_param = 2,
a_initial = 3,
b_initial = 1,
precision = 0.01
)
#> $estimate
#> a b
#> 3.945122 2.223727
#>
#> $profile_out
#> a1 a2 b1 b2
#> 3.317470 4.577470 1.848473 2.749082
Additionally, multiple distribution models can be compared (for censored and non-censored data).
multi_fitdist(
data = rlnorm(n = 100, meanlog = 1, sdlog = 1),
models = c("lnorm", "gamma", "weibull"),
func = fitdistrplus::fitdist
)
#> models loglik aic bic
#> 1 gamma -237.0588 478.1176 483.3280
#> 2 weibull -237.7660 479.5321 484.7424
#> 3 lnorm -240.0550 484.1099 489.3203
Help
To report a bug please open an issue
Contributions
Contributions are welcome via pull requests.
Code of Conduct
Please note that the quickfit project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.