% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/Survdt.R
\name{Survdt}
\alias{Survdt}
\alias{[.Survdt}
\alias{is.na.Survdt}
\alias{is.Survdt}
\alias{length.Survdt}
\alias{as.data.frame.Survdt}
\alias{plot.Survdt}
\title{Create a basic survival object for doubly truncated data.}
\usage{
Survdt(time, ltrunc, rtrunc)

\method{[}{Survdt}(x, i, j, ...)

\method{is.na}{Survdt}(x)

is.Survdt(x)

\method{length}{Survdt}(x)

\method{as.data.frame}{Survdt}(x, ...)

\method{plot}{Survdt}(x, colorvar = NULL, sort = TRUE, ...)
}
\arguments{
\item{time}{A vector of follow up times.}

\item{ltrunc}{A vector of left truncation times.}

\item{rtrunc}{A vector of right truncation times.}

\item{x}{Any R object.}

\item{i, j}{Row and columns index vectors. The result is a \code{Survdt} object if
\code{j} is missing, otherwise \code{x} is treated as a matrix.}

\item{...}{Additional arguments passed to other methods.}

\item{colorvar}{An optional vector used to color the dots in the plot. Will
be coerced to factor before using.}

\item{sort}{Whether to sort the data rows by follow up time (and \code{colorvar},
if provided) before plotting (default \code{TRUE}).}
}
\value{
\itemize{
\item \code{\link[=Survdt]{Survdt()}} returns an object of class \code{Survdt}, with columns \code{time},
\code{ltrunc}, and \code{rtrunc}.
Indexing a \code{Survdt} object by rows will return another \code{Survdt} object,
otherwise it is treated as a matrix.
The length of a \code{Survdt} object is its sample size, and \code{is.na()} returns
a logical index vector for the non-complete cases.
Calling \code{as.data.frame()} on a \code{Survdt} object will return a data frame
stripped of the \code{Survdt} class attribute.
\item \code{\link[=is.Survdt]{is.Survdt()}} returns \code{TRUE} if \code{x} inherits from the class \code{Survdt} and
\code{FALSE} otherwise.
\item The plot method for \code{Survdt} objects returns a simple visualization from
\code{\link[ggplot2:ggplot]{ggplot2::ggplot()}} with x-axis time, y-axis subject, rectangles for the
truncation intervals, and dots for the event times.
The dots can optionally be colored by a factor variable supplied in
\code{colorvar}.
Incomplete cases are dropped from the plot (with a warning).
}
}
\description{
Creates a survival object to contain the event times, left truncation times,
and right truncation times from a doubly truncated sample, with one observation
per subject.

Typically used as the input for nonparametric analysis methods or as the
response variable in a regression model formula.
}
\details{
For a given event time of interest \eqn{T}, a sample is doubly truncated when
it only includes subjects with \eqn{L_i<T_i \leq R_i} for some random
truncation times \eqn{L_i} and \eqn{R_i}.
Analyzing this type of data requires information on the \eqn{i}th subject's
event time \eqn{T_i}, left truncation time \eqn{L_i}, and right truncation
time \eqn{R_i}.

\code{\link[=Survdt]{Survdt()}} provides the basic data structure for organizing such data and
checking its validity in the \code{survdt} package.
Attempting to run \code{\link[=Survdt]{Survdt()}} with inputs that do not satisfy \eqn{L<T \leq R}
will result in an error.
}
\examples{
y <- with(aids, Survdt(incu, ltrunc, rtrunc))
plot(y)
plot(y, colorvar = aids$age_gp)
npmle(y)

}
\seealso{
\itemize{
\item \code{\link[=npmle]{npmle()}}, \code{\link[=test_samplediff_indtrunc]{test_samplediff_indtrunc()}}: nonparametric estimation and
analysis for doubly truncated data.
\item \code{\link[=coxph_indtrunc]{coxph_indtrunc()}}: inverse probability weighted Cox regression.
\item \code{\link[=Survdt2]{Survdt2()}}: to encode time-varying covariates; also \code{\link[=time_split]{time_split()}} for
converting data from \code{Survdt} structure to \code{Survdt2}.
}
}
