% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/recreg.R
\name{twostageREC}
\alias{twostageREC}
\title{Fitting of Two-Stage Recurrent Events Random Effects Model}
\usage{
twostageREC(
  margsurv,
  recurrent,
  data = parent.frame(),
  theta = NULL,
  model = c("full", "shared", "non-shared"),
  ghosh.lin = NULL,
  theta.des = NULL,
  var.link = 0,
  method = "NR",
  no.opt = FALSE,
  weights = NULL,
  se.cluster = NULL,
  fnu = NULL,
  nufix = 0,
  nu = NULL,
  numderiv = 1,
  derivmethod = c("simple", "Richardson"),
  ...
)
}
\arguments{
\item{margsurv}{Marginal model for the terminal event (object of class \code{"phreg"}).}

\item{recurrent}{Marginal model for recurrent events (object of class \code{"phreg"} or \code{"recreg"}).}

\item{data}{Data frame used for fitting.}

\item{theta}{Starting value for total variance of gamma frailty.}

\item{model}{Model type: \code{"full"} (fully shared), \code{"shared"} (partly shared), or \code{"non-shared"}.}

\item{ghosh.lin}{Logical; if \code{TRUE}, forces use of Ghosh-Lin marginals based on the recurrent model.}

\item{theta.des}{Regression design for variance parameters.}

\item{var.link}{Link function for variance (1 for exponential).}

\item{method}{Optimization method (default "NR").}

\item{no.opt}{Logical; if \code{TRUE}, skips optimization.}

\item{weights}{Weights.}

\item{se.cluster}{Clusters for SE calculation (GEE style).}

\item{fnu}{Function to transform \eqn{\nu} (amount shared).}

\item{nufix}{Logical; if \code{TRUE}, fixes the amount shared.}

\item{nu}{Starting value for the amount shared.}

\item{numderiv}{Logical; if \code{TRUE}, uses numerical derivatives.}

\item{derivmethod}{Method for numerical derivative.}

\item{...}{Arguments for the optimizer.}
}
\value{
An object of class \code{"twostageREC"} containing:
\item{coef}{Estimated coefficients.}
\item{var}{Variance-covariance matrix.}
\item{theta}{Dependence parameters.}
\item{model}{Model type.}
}
\description{
Fits a two-stage random effects model for recurrent events with a terminal event.
Marginal models (Cox or Ghosh-Lin) are fitted first and passed to this function.
}
\details{
Supports:
\itemize{
\item Cox/Cox marginals.
\item Cox/Ghosh-Lin marginals.
\item Fully shared, partly shared, or non-shared random effects.
}
}
\references{
Scheike (2026), Two-stage recurrent events random effects models, LIDA, to appear.
}
\author{
Thomas Scheike
}
