% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/ipw_ests.R
\name{plot_coxsurv}
\alias{plot_coxsurv}
\title{Plot survival or hazard estimates from a Cox model fit}
\usage{
plot_coxsurv(
  object,
  newdata,
  ci = TRUE,
  level = 0.95,
  ctype = c("log-log", "log", "plain"),
  target = c("survival", "cumhaz")
)
}
\arguments{
\item{object}{A \code{coxph_indtrunc} object. See \code{\link[=coxph_indtrunc]{coxph_indtrunc()}}.}

\item{newdata}{A data frame with the covariate values for the plot.
The original model formula is applied to extract predictors.
Rows that are duplicated or have missing values are discarded.}

\item{ci}{Whether to plot pointwise confidence intervals (default \code{TRUE}).
Will re-fit the model if \code{basehaz} or its standard errors were not computed.}

\item{level}{Confidence level for the pointwise confidence intervals
(default 0.95).}

\item{ctype}{Type of confidence interval.
\itemize{
\item \code{"plain"}: linear confidence from a normal approximation.
\item \code{"log"}: back-transformed confidence intervals from the natural log scale.
Guaranteed to be non-negative.
\item \code{"log-log"} (the default): for the survival function, back-transformed
confidence intervals from the (natural) log minus log scale, which are
guaranteed to be between zero and one.
For the cumulative hazard, the same confidence intervals as \code{"log"} are
used.
}}

\item{target}{Which quantity to plot.
\itemize{
\item \code{"survival"} (the default): the conditional survival function.
\item \code{"cumhaz"}: the conditional cumulative hazard.
}}
}
\value{
After displaying the plot, a list with two elements is returned invisibly.
The first element \code{ests} is a data frame with the columns \code{time}, \code{est},
\code{lower}, and \code{upper}, containing the point estimates and their computed
confidence intervals.
The second element \code{plot} is the plotted object returned by \code{\link[ggplot2:ggplot]{ggplot2::ggplot()}}.
Lines are colored based on the covariate value.
}
\description{
Given a fitted Cox model from \code{\link[=coxph_indtrunc]{coxph_indtrunc()}}, plot the conditional survival
or cumulative hazard estimates along with pointwise confidence intervals.
The baseline hazard and its standard errors are computed by \code{\link[=plot_coxsurv]{plot_coxsurv()}}
if they were not included in the \code{coxph_indtrunc} fit.
}
\details{
In order to construct the linear predictors at the requested covariate values,
the design matrix obtained from evaluating the original model formula on
\code{newdata} should have the same column names as the design matrix for the
fitted model.
Issues can occur for categorical variables that were converted to factors by
\code{\link[=coxph_indtrunc]{coxph_indtrunc()}} for estimation.
If an error occurs, check that each categorical variable in \code{newdata} is a
factor variable that is not missing any levels used to fit the model.
}
\examples{
fit <- coxph_indtrunc(Survdt(incu, ltrunc, rtrunc) ~ age_gp,
                      data = aids,
                      basehaz = TRUE)
plot_coxsurv(fit, newdata = aids[c(1,40), ])

plot_coxsurv(fit, newdata = aids[c(1,40), ],
             target = "cumhaz")
}
\seealso{
\code{\link[=coxph_indtrunc]{coxph_indtrunc()}}
}
