% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/mcf.R
\name{mcf}
\alias{mcf}
\title{Mean Cumulative Function for Repairable Systems.}
\usage{
mcf(
  id = NULL,
  time = NULL,
  event = NULL,
  end_time = NULL,
  data = NULL,
  conf_level = 0.95
)
}
\arguments{
\item{id}{A vector of system/unit identifiers. Each unique value represents
a distinct system. Ignored if \code{data} is provided.}

\item{time}{A numeric vector of event or censoring times. Must be positive
and finite. Ignored if \code{data} is provided.}

\item{event}{An optional numeric vector of event indicators: 1 for an event,
0 for censoring (end of observation). If \code{NULL} (default), all
observations are treated as events.}

\item{end_time}{An optional named numeric vector of end-of-observation times
per system, where names correspond to system identifiers. This defines
the actual exposure window for each system. When provided, a system
remains in the risk set until its \code{end_time}, even if its last event
occurred earlier. If \code{NULL} (default), the end of observation is
inferred as the maximum time recorded for each system (from both events
and censoring records).}

\item{data}{An optional data frame containing columns named \code{id},
\code{time}, and optionally \code{event} and \code{end_time}.}

\item{conf_level}{Confidence level for bounds (default 0.95).}
}
\value{
An object of class \code{mcf} containing:
\item{time}{Unique event times.}
\item{mcf}{MCF values at each event time.}
\item{variance}{Variance estimates at each event time.}
\item{lower_bounds}{Lower confidence bounds.}
\item{upper_bounds}{Upper confidence bounds.}
\item{conf_level}{Confidence level used.}
\item{n_systems}{Number of distinct systems.}
\item{n_events}{Total number of events.}
\item{end_times}{Named vector of end-of-observation times per system.}
}
\description{
Computes the non-parametric Mean Cumulative Function (MCF) for recurrent
event data from one or more repairable systems, using the Nelson-Aalen
estimator. The MCF estimates the expected cumulative number of events per
system as a function of time, properly accounting for system exposure
(observation windows).
}
\details{
The MCF at time \eqn{t} is estimated as:
\deqn{\hat{M}(t) = \sum_{t_j \le t} \frac{d_j}{n_j}}
where \eqn{d_j} is the number of events at time \eqn{t_j} and \eqn{n_j} is
the number of systems still under observation at \eqn{t_j}. Variance is
estimated as \eqn{\hat{V}(t) = \sum_{t_j \le t} d_j / n_j^2}.

The risk set \eqn{n_j} is determined by each system's \strong{exposure window}.
A system is considered at risk at time \eqn{t_j} if its end-of-observation
time (from \code{end_time}, censoring records, or last event) is
\eqn{\ge t_j}. Specifying \code{end_time} is important when systems were
observed beyond their last event -- without it, the MCF may overestimate
the true recurrence rate because systems with no late events are assumed to
have left observation at their last event time.
}
\examples{
# Basic usage (end of observation inferred from last event)
id <- c(1, 1, 1, 2, 2, 3, 3, 3, 3)
time <- c(100, 300, 500, 150, 400, 50, 200, 350, 600)
result <- mcf(id, time)
print(result)
plot(result, main = "Mean Cumulative Function")

# With explicit end-of-observation times (exposure-adjusted)
end_time <- c("1" = 800, "2" = 800, "3" = 800)
result2 <- mcf(id, time, end_time = end_time)
print(result2)

df <- data.frame(id = id, time = time)
result3 <- mcf(data = df)
print(result3)
}
\seealso{
Other Repairable Systems Analysis: 
\code{\link{exposure}()},
\code{\link{nhpp}()},
\code{\link{overlay_nhpp}()},
\code{\link{plot.exposure}()},
\code{\link{plot.mcf}()},
\code{\link{plot.nhpp}()},
\code{\link{plot.nhpp_predict}()},
\code{\link{predict_nhpp}()},
\code{\link{print.exposure}()},
\code{\link{print.mcf}()},
\code{\link{print.nhpp}()},
\code{\link{print.nhpp_predict}()}
}
\concept{Repairable Systems Analysis}
