Fits INAD models by maximum likelihood.
Usage
fit_inad(
y,
order = 1,
thinning = c("binom", "pois", "nbinom"),
innovation = c("pois", "bell", "nbinom"),
blocks = NULL,
max_iter = 50,
tol = 1e-06,
verbose = FALSE,
init_alpha = NULL,
init_theta = NULL,
init_tau = 0.4,
init_nb_inno_size = 1,
nb_inno_size_ub = 50,
na_action = c("fail", "complete", "marginalize")
)Arguments
- y
Integer matrix n_sub by n_time.
- order
Integer in {0, 1, 2}.
- thinning
One of "binom", "pois", "nbinom".
- innovation
One of "pois", "bell", "nbinom".
- blocks
Optional integer vector length n_sub. Default NULL.
- max_iter
Max iterations for FE coordinate descent.
- tol
Tolerance for FE log likelihood stopping.
- verbose
Logical.
- init_alpha
Optional initial alpha. For order 1 numeric length 1 or n_time. For order 2 matrix n_time by 2 or list(alpha1, alpha2).
- init_theta
Optional initial theta numeric length 1 or n_time.
- init_tau
Optional initial tau. Scalar expands to c(0, x, ..., x). Vector forces first to 0.
- init_nb_inno_size
Optional initial size for innovation nbinom, length 1 or n_time.
- nb_inno_size_ub
Upper bound for innovation negative binomial size parameter when
innovation = "nbinom". Default is 50.- na_action
How to handle missing values:
"fail": stop if any NA is present."complete": fit using complete-case subjects only."marginalize": maximize observed-data likelihood under MAR.
Value
A list of class "inad_fit" containing:
- alpha
Estimated antedependence parameter(s)
- theta
Estimated innovation parameter(s)
- tau
Estimated block effects (if applicable)
- nb_inno_size
Estimated innovation NB size parameter(s), when
innovation = "nbinom"- log_l
Maximized log-likelihood
- aic
Akaike information criterion
- bic
Bayesian information criterion
- n_params
Number of free parameters
- convergence
Convergence code
- settings
Model and fitting settings
Details
No fixed effect: time separable optimization using logL_inad_i with theta eliminated by moment equations for order 1 and 2.
Fixed effect: block coordinate descent using nloptr BOBYQA, updating tau, alpha, theta, and nb_inno_size if needed.
Examples
set.seed(1)
y <- simulate_inad(
n_subjects = 60,
n_time = 5,
order = 1,
thinning = "binom",
innovation = "pois",
alpha = 0.3,
theta = 2
)
fit <- fit_inad(y, order = 1, thinning = "binom", innovation = "pois", max_iter = 20)
fit$log_l
#> [1] -522.7922