% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/fit_inad.R
\name{fit_inad}
\alias{fit_inad}
\title{Fit INAD antedependence model 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{
\item{y}{Integer matrix n_sub by n_time.}

\item{order}{Integer in \{0, 1, 2\}.}

\item{thinning}{One of "binom", "pois", "nbinom".}

\item{innovation}{One of "pois", "bell", "nbinom".}

\item{blocks}{Optional integer vector length n_sub. Default NULL.}

\item{max_iter}{Max iterations for FE coordinate descent.}

\item{tol}{Tolerance for FE log likelihood stopping.}

\item{verbose}{Logical.}

\item{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).}

\item{init_theta}{Optional initial theta numeric length 1 or n_time.}

\item{init_tau}{Optional initial tau. Scalar expands to c(0, x, ..., x). Vector forces first to 0.}

\item{init_nb_inno_size}{Optional initial size for innovation nbinom, length 1 or n_time.}

\item{nb_inno_size_ub}{Upper bound for innovation negative binomial size
parameter when \code{innovation = "nbinom"}. Default is 50.}

\item{na_action}{How to handle missing values:
\itemize{
\item \code{"fail"}: stop if any NA is present.
\item \code{"complete"}: fit using complete-case subjects only.
\item \code{"marginalize"}: maximize observed-data likelihood under MAR.
}}
}
\value{
A list of class \code{"inad_fit"} containing:
\describe{
\item{alpha}{Estimated antedependence parameter(s)}
\item{theta}{Estimated innovation parameter(s)}
\item{tau}{Estimated block effects (if applicable)}
\item{nb_inno_size}{Estimated innovation NB size parameter(s), when
\code{innovation = "nbinom"}}
\item{log_l}{Maximized log-likelihood}
\item{aic}{Akaike information criterion}
\item{bic}{Bayesian information criterion}
\item{n_params}{Number of free parameters}
\item{convergence}{Convergence code}
\item{settings}{Model and fitting settings}
}
}
\description{
Fits INAD models by maximum likelihood.
}
\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
}
