% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/npests.R
\name{npmle}
\alias{npmle}
\alias{is.npmle}
\alias{print.npmle}
\title{Compute the nonparametric MLE under double truncation}
\usage{
npmle(
  y,
  data = NULL,
  se = TRUE,
  cumhaz = FALSE,
  ainv = TRUE,
  infl = FALSE,
  max_iter = 1000,
  error = 1e-09,
  init = NULL,
  convergence_warning = TRUE,
  check_identifiability = TRUE
)

is.npmle(x)

\method{print}{npmle}(x, ...)
}
\arguments{
\item{y}{A \code{Survdt} object or expression. Observations with missing values
are discarded.
See \code{\link[=Survdt]{Survdt()}}.}

\item{data}{An optional data frame used to evaluate \code{y}.}

\item{se}{Whether to compute standard errors for each estimate
(default \code{TRUE}).}

\item{cumhaz}{Whether to also compute the NPMLE of the event time cumulative
hazard (default \code{FALSE}).}

\item{ainv}{Whether to return the NPMLE of the normalized inverse selection
probabilities at the observed event times (default \code{TRUE}).}

\item{infl}{Whether to return the influence values for each estimate
(default \code{FALSE}).}

\item{max_iter}{The maximum number of iterations for the EM algorithm.}

\item{error}{Tolerance for determining numerical convergence, defined as the
relative change in the log likelihood being less than \code{error} or the absolute
change being less than sqrt(\code{error}) at any iteration.}

\item{init}{Optional event time cdf point masses to initialize the EM
algorithm.}

\item{convergence_warning}{Whether to issue a warning when numerical
convergence is not achieved by \code{max_iter} iterations (default \code{TRUE}).}

\item{check_identifiability}{Whether to check and return an error if the
NPMLE is not identifiable (default \code{TRUE}, see below).}

\item{x}{Any R object.}

\item{...}{Additional arguments passed to or from other methods.}
}
\value{
\code{\link[=npmle]{npmle()}} returns an object of class \code{npmle}, i.e. a list with the following
components:
\item{n}{The complete case sample size.}
\item{n_miss}{The number of discarded observations (with missing values).}
\item{cdf}{A matrix containing the estimated event time cdf evaluated at
ordered unique event times, with columns \code{time}, \code{cdf}, and \code{se}.}
\item{cumhaz}{A matrix containing the estimated event time cumulative hazard
evaluated at ordered unique event times, with columns \code{time}, \code{cumhaz}, and
\code{se}.
Set to \code{NULL} if \code{cumhaz}=\code{FALSE}.}
\item{ainv}{A matrix containing the estimated normalized inverse selection
probabilities for each event time (not sorted and including duplicates),
with columns \code{time}, \code{ainv}, and \code{se}.
Set to \code{NULL} if \code{ainv}=\code{FALSE}.}
\item{infl_cdf}{A matrix containing the estimated influence function for the
cdf, with \verb{[i,j]}th element corresponding to the \code{i}th ordered unique event
time and \code{j}th unsorted individual.
Set to \code{NULL} if \code{infl}=\code{FALSE}.}
\item{infl_cumhaz}{A matrix containing the estimated influence function for
the cumulative hazard, with \verb{[i,j]}th element corresponding to the \code{i}th
ordered unique event time and \code{j}th unsorted individual.
Set to \code{NULL} if \code{cumhaz=FALSE} or \code{infl}=\code{FALSE}.}
\item{infl_ainv}{A matrix containing the estimated influence function for the
normalized inverse selection probabilities, with \verb{[i,j]}th element
corresponding to the \code{i}th event time (including ties) and \code{j}th individual,
both unsorted.
Set to \code{NULL} if \code{ainv=FALSE} or \code{infl}=\code{FALSE}.}
\item{masses}{A data frame containing the point masses for the event time
(\code{f}) and truncation time (\code{g}) cdfs and the estimated selection
probabilities for each event time (\code{pt}) and truncation interval (\code{plr}),
with one row per observation.
Not sorted.}
\item{converged}{Whether the EM algorithm converged before \code{max_iter} was
reached.}
\item{n_iter}{The total number of EM algorithm iterations that ran.}
\item{overall_sampling_prob}{A named vector with the estimated overall
probability of non-truncation in \code{prob} and its standard error in \code{se}.}

\code{\link[=is.npmle]{is.npmle()}} returns \code{TRUE} if \code{x} inherits from the class \code{npmle} and
\code{FALSE} otherwise. The \code{print} method for \code{npmle} objects displays some sample
information and the first few steps of the estimated cdf.
}
\description{
Computes the nonparametric maximum likelihood estimator (NPMLE) of the
pre-truncation event time and truncation time distributions using an EM
algorithm.
}
\details{
Given a doubly truncated sample \eqn{(T_1,L_1,R_1)}, \eqn{(T_2,L_2,R_2)},
\eqn{\ldots}, \eqn{(T_n,L_n,R_n)}, the NPMLE of the (pre-truncation) event
time cdf is a right-continuous step function
\deqn{\widehat{F}(t) = \sum_{i=1}^n 1(T_i\leq t) \widehat{f}_i}
with point masses at the observed event times.
Assuming (quasi-)independent truncation, these point masses maximize the
likelihood function
\deqn{L(f_1, \ldots, f_n) = \prod_{i=1}^n \frac{f_i}{\sum_j 1(L_i<T_j \leq R_i) f_j}.}
Efron and Petrosian (1999) provided a simple EM algorithm to compute the NPMLE.

The point masses of the NPMLE can be expressed as
\eqn{\widehat{f}_i = 1/[\widehat{a}(T_i)n]},
where \eqn{a(t) = P(L<T \leq R|T=t)/P(L<T \leq R)} is the normalized
probability of observing time \eqn{t} within a truncation interval.
These inverse selection probabilities are used to correct for double truncation
bias in \code{\link[=coxph_indtrunc]{coxph_indtrunc()}}.

Once \eqn{\widehat{F}(t)} is obtained, other quantities such as the survival
function, cumulative hazard, and bivariate truncation time cdf point masses
are straightforward to compute.
}
\section{Identifiability}{

Xiao and Hudgens (2019) provided a necessary and sufficient condition for the
likelihood function \eqn{L(f_1, \ldots, f_n)} to have a unique maximizer.
By default, this condition is checked by \code{\link[=npmle]{npmle()}} before estimation.
}

\section{Standard errors}{

By default, \code{\link[=npmle]{npmle()}} computes variance estimates for the NPMLE
using the closed-form standard errors derived by Vazquez and Xie (2025).
This is generally more computationally efficient than the resampling methods
used by other packages.
If fit with \code{infl}=\code{TRUE}, the \code{npmle} object may be supplied as an input to
other \link{survdt} functions, which will then not need to re-compute the influence
values.
}

\examples{
npmle(Survdt(incu, ltrunc, rtrunc),
      data = aids)


}
\references{
Efron, B., & Petrosian, V. (1999). Nonparametric methods for doubly truncated
data. \emph{Journal of the American Statistical Association}, \strong{94}(447), 824--834.

de Uña-Álvarez, J., & Van Keilegom, I. (2021). Efron–Petrosian integrals for
doubly truncated data with covariates: An asymptotic analysis. \emph{Bernoulli},
\strong{27}(1), 249--273.

Vazquez, O., & Xie, S. X. (2025). Robust inverse probability weighted
estimators for doubly truncated Cox regression with closed-form standard
errors. \emph{Lifetime Data Analysis}, \strong{31}(2), 364–-393.

Xiao, J., & Hudgens, M. G. (2019). On nonparametric maximum likelihood
estimation with double truncation. \emph{Biometrika}, \strong{106}(4), 989--996.
}
\seealso{
\itemize{
\item \code{\link[=plot.npmle]{plot.npmle()}}: compute/plot estimates and pointwise confidence
intervals for the event time survival function and cumulative hazard,
normalized inverse selection probability weights, and selection probability
as a function of time.
\item \code{\link[=test_ignorability_indtrunc]{test_ignorability_indtrunc()}}: test for ignorable sampling bias using the
NPMLE.
\item \code{\link[=test_samplediff_indtrunc]{test_samplediff_indtrunc()}}: test for differences in the event time
distributions across groups using the NPMLE.
\item \code{\link[=test_quasiindep_ctau]{test_quasiindep_ctau()}}: test for violations of the quasi-independent
truncation assumption.
\item \code{vignette("nonparametric-analysis", package = "survdt")}: an example of
various nonparametric analyses applied to the \link{aids} data, if vignettes
were built when installing \link{survdt}.
}
}
