% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/Reml_CompRisk_frailty.R
\name{Reml_CompRisk_frailty}
\alias{Reml_CompRisk_frailty}
\title{REML Estimation for Cause 1 in a Competing Risks Model with Shared Frailty}
\usage{
Reml_CompRisk_frailty(
  data,
  cluster_censoring = FALSE,
  max_iter = 300,
  tol = 1e-06,
  threshold = 1e-05
)
}
\arguments{
\item{data}{A data frame with at least the following columns:
\describe{
\item{times}{Observed times to event or censoring.}
\item{status}{Event type: 0 = censored, 1 = cause of interest, >1 = other competing risks.}
\item{clusters}{Cluster membership (e.g., centers or subjects).}
\item{covariates}{(Optional) Columns from the 4th onward are used as covariates.}
}}

\item{cluster_censoring}{Logical. If \code{TRUE}, accounts for center-specific censoring using a frailty model on censoring times. Default is \code{FALSE}.}

\item{max_iter}{Maximum number of iterations for the Newton-Raphson algorithm (default = 300).}

\item{tol}{Convergence tolerance for the likelihood and frailty variance (default = 1e-6).}

\item{threshold}{Lower bound for the frailty variance parameter \eqn{\theta}. If the estimated value falls below this threshold, frailty is considered negligible (default = 1e-5).}
}
\value{
A list with:
\describe{
\item{beta}{Estimated regression coefficients for the cause 1 hazard.}
\item{u}{Estimated cluster-specific random effects (frailties).}
\item{theta}{Estimated frailty variance.}
\item{p_value}{P-value testing the null hypothesis \eqn{H_0: \theta = 0}.}
}
}
\description{
Fits a cause-specific hazard model for cause 1 in a competing risks framework using restricted maximum likelihood (REML) with a shared frailty term for clusters.
}
\details{
The function fits a proportional hazards model for cause 1, accounting for unobserved heterogeneity via a shared frailty term on clusters. When \code{cluster_censoring = TRUE}, a frailty-adjusted survival curve is used to correct for informative censoring using either a Kaplan-Meier or Nelson-Aalen-based estimator.

If the estimated frailty variance \eqn{\theta} becomes smaller than the provided \code{threshold}, the model reverts to a standard Cox model for cause 1 using \code{\link{Ml_CompRisk}}.
}
\examples{
\donttest{
data <- data.frame(
  times = c(4, 6, 10, 12, 3),
  status = c(1, 0, 2, 1, 0),
  clusters = c(1, 1, 2, 2, 3),
  x1 = rnorm(5),
  x2 = sample(0:1, 5, replace = TRUE)
)
result <- Reml_CompRisk_frailty(data)
result$beta
result$p_value
}

}
\seealso{
\code{\link{Ml_CompRisk}}, \code{\link{Reml_Cox_frailty}}, \code{\link{logLikelihood_1}}, \code{\link{compute_M_optimized}}
}
