Description Usage Arguments Details Value Methods (by class) References See Also Examples
An S4 class generic function that returns the mean cumulative function (MCF) estimates from a fitted model or returns the nonparametric MCF estimates (also called the NelsonAalen estimator) from the sample data.
1 2 3 4 5 6 7 8 9 10  mcf(object, ...)
## S4 method for signature 'formula'
mcf(object, data, subset, na.action,
variance = c("LawlessNadeau", "Poisson", "bootstrap"), logConfInt = FALSE,
level = 0.95, control = list(), ...)
## S4 method for signature 'rateReg'
mcf(object, newdata, groupName, groupLevels, level = 0.95,
na.action, control = list(), ...)

object 
An object used to dispatch a method. 
... 
Other arguments for future usage. 
data 
A data frame, list or environment containing the variables in
the model. If not found in data, the variables are taken from

subset 
An optional vector specifying a subset of observations to be used in the fitting process. 
na.action 
A function that indicates what should the procedure do if
the data contains 
variance 
A character specifying the method for variance estimates.
The available options are 
logConfInt 
A logical value. If 
level 
An optional numeric value indicating the confidence level required. The default value is 0.95. 
control 
An optional named list specifying other options. For
The option For formula method, the available named elements are given as follows:

newdata 
An optional data frame. If specified, the data frame should have the same column names as the covariate names appearing in the formula of original fitting. 
groupName 
An optional lengthone charactor vector to specify the name
for grouping each unique row in 
groupLevels 
An optional charactor vector to specify the levels for
each unique row in 
For formula
object with Survr
object as response, the
covariate specified at the right hand side of the formula should be either
1
or any "linear" conbination of categorical variable in the data.
The former computes the overall sample MCF. The latter computes the sample
MCF for each level of the combination of the categorical variable(s)
specified, respectively. The sample MCF is also called NelsonAalen
nonparametric estimator (Nelson 2003) and computed on each time point from
sample data. The point estimate of sample MCF at each time point does not
assume any particular underlying model. The variance estimates at each time
point is computed following the Lawless and Nadeau method (LawLess and
Nadeau 1995), the Poisson process method, or the bootstrap methods. The
approximate confidence intervals are provided as well, which are constructed
based on the asymptotic normality of the MCF itself (by default) or the
logarithm of MCF.
For rateReg
object, mcf
estimates the baseline
MCF and its confidence interval at each time grid if argument newdata
is not specified. Otherwise, mcf
estimates MCF and its confidence
interval for the given newdata based on Deltamethod.
A mcf.formula
or mcf.rateReg
object.
A brief description of the slots of a mcf.formula
object is given as
follows:
formula
: Model Formula.
data
: Processed data based on the model formula or an
empty data frame if keep.data
is set to be FALSE
.
MCF
: A data frame containing estimates for sample MCF.
origin
: Time origins.
multiGroup
: A logical value indicating whether MCF
is estimated for different groups respectively.
logConfInt
: A logical value indicating whether the
variance estimates are based on the normality of logarithm of
the MCF estimates.
level
: Confidence level specified.
Most slots of a mcf.rateReg
object are inherited from the input
rateReg
object. A brief description of other slots is given as
follows:
newdata
: Given dataset used to estimate MCF.
MCF
: A data frame containing MCF estimates.
level
: Confidence level specified.
na.action
: The way handling missing values.
control
: The control list.
multiGroup
: A logical value indicating whether MCF
is estimated for different groups respectively.
formula
: Sample MCF from data.
rateReg
: Estimated MCF from a fitted model.
Lawless, J. F. and Nadeau, C. (1995). Some Simple Robust Methods for the Analysis of Recurrent Events. Technometrics, 37, 158–168.
Nelson, W. B. (2003). Recurrent Events Data Analysis for Product Repairs, Disease Recurrences, and Other Applications (Vol. 10). SIAM.
rateReg
for model fitting;
mcfDiff
for comparing twosample MCFs.
plotmethod
for plotting MCF.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63  library(reda)
### sample MCF
## Example 1. valveseat data
## the default variance estimates by Lawless and Nadeau (1995) method
valveMcf0 < mcf(Survr(ID, Days, No.) ~ 1, data = valveSeats)
plot(valveMcf0, conf.int = TRUE, mark.time = TRUE, addOrigin = TRUE) +
ggplot2::xlab("Days") + ggplot2::theme_bw()
## variance estimates following Poisson process model
valveMcf1 < mcf(Survr(ID, Days, No.) ~ 1,
data = valveSeats, variance = "Poisson")
## variance estimates by bootstrap method (with 1,000 bootstrap samples)
valveMcf2 < mcf(Survr(ID, Days, No.) ~ 1,
data = valveSeats, variance = "bootstrap",
control = list(B = 2e2))
## comparing the variance estimates from different methods
library(ggplot2)
ciDat < rbind(cbind(valveMcf0@MCF, Method = "Lawless & Nadeau"),
cbind(valveMcf1@MCF, Method = "Poisson"),
cbind(valveMcf2@MCF, Method = "Bootstrap"))
ggplot(ciDat, aes(x = time, y = se)) +
geom_step(aes(color = Method, linetype = Method)) +
xlab("Days") + ylab("SE estimates") + theme_bw()
## comparing the confidence interval estimates from different methods
ggplot(ciDat, aes(x = time)) +
geom_step(aes(y = MCF)) +
geom_step(aes(y = lower, color = Method, linetype = Method)) +
geom_step(aes(y = upper, color = Method, linetype = Method)) +
xlab("Days") + ylab("Confidence intervals") + theme_bw()
## Example 2. the simulated data
simuMcf < mcf(Survr(ID, time, event) ~ group + gender,
data = simuDat, ID %in% 1 : 50)
plot(simuMcf, conf.int = TRUE, lty = 1 : 4,
legendName = "Treatment & Gender")
### estimate MCF difference between two groups
## one sample MCF object of two groups
mcf0 < mcf(Survr(ID, time, event) ~ group, data = simuDat)
## twosample pseudoscore tests
mcfDiff.test(mcf0)
## difference estimates over time
mcf0_diff < mcfDiff(mcf0, testVariance = "none")
plot(mcf0_diff)
## or explicitly ask for the difference of two sample MCF
mcf1 < mcf(Survr(ID, time, event) ~ 1, data = simuDat,
subset = group %in% "Contr")
mcf2 < mcf(Survr(ID, time, event) ~ 1, data = simuDat,
subset = group %in% "Treat")
## perform twosample tests and estimate difference at the same time
mcf12_diff1 < mcfDiff(mcf1, mcf2)
mcf12_diff2 < mcf1  mcf2 # or equivalently using the `` method
stopifnot(all.equal(mcf12_diff1, mcf12_diff2))
mcf12_diff1
plot(mcf12_diff1)
### For estimated MCF from a fitted model,
### see examples given in function rateReg.

Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.