Fit monomolecular, logistic, and Gompertz epidemic models using nonlinear regression while also estimating the maximum disease intensity parameter `K`.
Arguments
- time
Numeric vector of assessment times.
- y
Numeric vector of disease intensity values.
- starting_par
Named list with starting values for `y0`, `r`, and `K`. When omitted or partially specified, `epifitter` supplies data-driven fallback values.
- maxiter
Maximum number of iterations. Must be a positive number.
- weights
Optional numeric vector of positive weights, or a function that receives a data frame with columns `time`, `y`, `predicted`, and `model` and returns positive weights. When supplied, these weights are used directly and `weight_method` must be `"none"`.
- weight_method
Weighting strategy for nonlinear least squares. Use `"none"` for ordinary nonlinear least squares, `"binomial"` for \(1 / (\hat{p}(1 - \hat{p}) + \epsilon)\), `"mean"` for \(1 / (\hat{p} + \epsilon)\), `"cv"` for \(1 / (\hat{p}^2 + \epsilon)\), or `"power"` for \(1 / (|\hat{p}|^{2\theta} + \epsilon)\).
- weight_eps
Small positive constant added to fitted-value variance approximations to keep weights finite near 0 and 1.
- weight_power
Non-negative power \(\theta\) used only when `weight_method = "power"`.
Details
Weighted fits use weighted nonlinear least squares, not a binomial or beta likelihood. `weight_method` options other than `"none"` use a two-step working approximation: first fit the model without weights, derive weights from the fitted values, and then refit the model. Report the selected weighting rule as an assumption.
Examples
set.seed(1)
epi <- sim_logistic(N = 30, y0 = 0.01, dt = 5, r = 0.3, alpha = 0.5, n = 4)
fit_nlin2(
time = epi$time,
y = epi$random_y * 0.8,
starting_par = list(y0 = 0.01, r = 0.1, K = 0.8),
maxiter = 1024
)
#> Warning: no non-missing arguments to max; returning -Inf
#> Warning: no non-missing arguments to max; returning -Inf
#> Warning: no non-missing arguments to max; returning -Inf
#> Warning: The following nonlinear model(s) with estimated K did not converge and will be returned as NA: Monomolecular.
#> Results of fitting population models
#>
#> Stats:
#> CCC r_squared RSE
#> Gompertz 0.9954 0.9915 0.0333
#> Logistic 0.9646 0.9370 0.0907
#> Monomolecular NA NA NA
#>
#> Infection rate:
#> Estimate Std.error Lower Upper
#> Gompertz 0.2870933 0.02151228 0.2427880 0.3313987
#> Logistic 0.1820370 0.03123483 0.1177076 0.2463663
#> Monomolecular NA NA NA NA
#>
#> Initial inoculum:
#> Estimate Std.error Lower Upper
#> Gompertz 2.220446e-16 2.149695e-15 -4.205336e-15 4.649425e-15
#> Logistic 3.923556e-02 1.668975e-02 4.862385e-03 7.360874e-02
#> Monomolecular NA NA NA NA
#>
#> Maximum disease intensity:
#> Estimate Std.error Lower Upper
#> Gompertz 0.7766917 0.01357448 0.7487345 0.8046489
#> Logistic 1.0000000 0.09237762 0.8097447 1.1902553
#> Monomolecular NA NA NA NA
