% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/test-recurrent-ipcw.R
\name{test_marginalMean}
\alias{test_marginalMean}
\title{Pepe-Mori Test for Marginal Mean Comparison}
\usage{
test_marginalMean(
  formula,
  data,
  cause = 1,
  cens.code = 0,
  ...,
  death.code = 2,
  death.code.prop = NULL,
  time = NULL,
  beta = NULL
)
}
\arguments{
\item{formula}{Formula with an \code{Event} object on the left-hand side and 
covariates (typically with \code{strata()} for group comparison) on the right.
Can include \code{cluster(id)} for correlated data.}

\item{data}{Data frame containing all variables referenced in the formula.}

\item{cause}{Cause of interest (default 1).}

\item{cens.code}{Censoring code (default 0).}

\item{...}{Additional arguments passed to lower-level functions.}

\item{death.code}{Code for death (terminating event, default 2).}

\item{death.code.prop}{Code for other causes of death for Fine-Gray regression model.}

\item{time}{Upper limit for Pepe-Mori and AUC integrals. If NULL, defaults to 
the maximum event time for the cause of interest.}

\item{beta}{Starting values for the score test (default NULL, uses zeros).}
}
\value{
An object of class \code{"marginalTest"} containing:
  \item{pepe.mori}{Pepe-Mori test results with compare p-value.}
  \item{RatioAUC}{Ratio of AUC test results with compare p-value.}
  \item{difAUC}{Difference of AUC test results with compare p-value.}
  \item{prop.test}{Proportionality test results.}
  \item{score.test}{Score test results (equivalent to Gray's test).}
  \item{score.iid}{Influence function for the score test.}
  \item{time}{Upper time limit used.}
  \item{RAUCl, RAUCe}{Raw and transformed AUC estimates.}
}
\description{
Performs score-test type tests for proportionality of marginal means in competing 
risks data and recurrent events, as presented in Ghosh and Lin (2000). The test 
is based on an IPCW (Inverse Probability of Censoring Weighting) formulation.
}
\details{
The function computes several tests:
\enumerate{
  \item \strong{Pepe-Mori Test}: Tests for equality of marginal mean functions between groups.
  \item \strong{Ratio of AUC}: Compares the area under the curve of marginal means.
  \item \strong{Difference of AUC}: Tests for difference in areas under the curve.
  \item \strong{Score Test}: Tests for proportionality (equivalent to Gray's test for CIF).
  \item \strong{Proportionality Test}: Tests the proportional hazards assumption.
}

The Pepe-Mori test uses weights based on the number at risk in each group to 
construct a weighted integral of the difference in marginal means.
}
\examples{
data(bmt,package="mets")
bmt$time <- bmt$time+runif(nrow(bmt))*0.01
bmt$id <- 1:nrow(bmt)
dcut(bmt) <- age.f~age
     
fg=cifregFG(Event(time,cause)~tcell,data=bmt,cause=1)
 
## computing tests for difference  for CIF
pmt <- test_marginalMean(Event(time,cause)~strata(tcell)+cluster(id),data=bmt,cause=1,
			 death.code=1:2,death.code.prop=2,cens.code=0,time=40)
summary(pmt) 
 
pmt$pepe.mori
pmt$RatioAUC
pmt$prop.test
## score test equialent to Gray's test but variance estimated differently 
pmt$score.test
 
### age-groups  
pmt <- test_marginalMean(Event(time,cause)~strata(age.f)+cluster(id),data=bmt,cause=1,
			 death.code=1:2,death.code.prop=2,cens.code=0)
summary(pmt) 
 
## having a look at the cumulative incidences 
cifs <- cif(Event(time,cause)~strata(age.f)+cluster(id),data=bmt,cause=1)
plot(cifs) 
 
## recurrent events   
data(hfactioncpx12)
hf <- hfactioncpx12
pmt <- test_marginalMean(Event(entry,time,status)~strata(treatment)+cluster(id),data=hf,
			 cause=1,death.code=2,cens.code=0)
summary(pmt) 
 
}
\references{
Ghosh, D. and Lin, D. Y. (2000). Nonparametric Analysis of Recurrent Events and Death. Biometrics, 56, 554--562.
}
\seealso{
\code{\link{test_logrankRecurrent}}, \code{\link{test_conc}}
}
\author{
Thomas Scheike
}
