| 1 |
% Generated by roxygen2: do not edit by hand |
| 2 |
% Please edit documentation in R/MarkovTest.R |
| 3 |
\name{MarkovTest} |
| 4 |
\alias{MarkovTest} |
| 5 |
\alias{optimal_weights_multiple} |
| 6 |
\alias{optimal_weights_matrix} |
| 7 |
\title{Log-rank based test for the validity of the Markov assumption} |
| 8 |
\usage{ |
| 9 |
MarkovTest( |
| 10 |
data, |
| 11 |
id, |
| 12 |
formula = NULL, |
| 13 |
transition, |
| 14 |
grid, |
| 15 |
B = 1000, |
| 16 |
fn = list(function(x) mean(abs(x), na.rm = TRUE)), |
| 17 |
fn2 = list(function(x) mean(x, na.rm = TRUE)), |
| 18 |
min_time = 0, |
| 19 |
other_weights = NULL, |
| 20 |
dist = c("poisson", "normal") |
| 21 |
) |
| 22 |
} |
| 23 |
\arguments{ |
| 24 |
\item{data}{Multi-state data in \code{msdata} format. Should also contain |
| 25 |
(dummy codings of) the relevant covariates; no factors allowed} |
| 26 |
|
| 27 |
\item{id}{Column name in \code{data} containing subject id} |
| 28 |
|
| 29 |
\item{formula}{Right-hand side of the formula. If NULL will fit with no |
| 30 |
covariates (formula="1" will also work), offset terms can also be specified.} |
| 31 |
|
| 32 |
\item{transition}{Transition number of the transition to be tested (in the |
| 33 |
transition matrix as attribute to \code{data})} |
| 34 |
|
| 35 |
\item{grid}{Grid of time points at which to compute the statistic} |
| 36 |
|
| 37 |
\item{B}{Number of wild bootstrap replications to perform} |
| 38 |
|
| 39 |
\item{fn}{A list of summary functions to be applied to the individual zbar |
| 40 |
traces (or a list of lists)} |
| 41 |
|
| 42 |
\item{fn2}{A list of summary functions to be applied to the overall |
| 43 |
chi-squared trace} |
| 44 |
|
| 45 |
\item{min_time}{The minimum time for calculating optimal weights} |
| 46 |
|
| 47 |
\item{other_weights}{Other (than optimal) weights can be specified here} |
| 48 |
|
| 49 |
\item{dist}{Distribution of wild bootstrap random weights, either "poisson" |
| 50 |
for centred Poisson (default), or "normal" for standard normal} |
| 51 |
} |
| 52 |
\value{ |
| 53 |
MarkovTest returns an object of class "MarkovTest", which is a list |
| 54 |
with the following items: \item{orig_stat}{Summary statistic for each of the |
| 55 |
starting states} \item{orig_ch_stat}{Overall chi-squared summary statistic} |
| 56 |
\item{p_stat_wb}{P-values corresponding to each of the summary statistics |
| 57 |
for each starting state} \item{p_ch_stat_wb}{P-values for overall |
| 58 |
chi-squared summary statistic} \item{b_stat_wb}{Bootstrap summary statistics |
| 59 |
for each of the starting states} \item{zbar}{Individual traces for each of |
| 60 |
the starting states} \item{nobs_grid}{The number of events after time s for |
| 61 |
each s in the grid} \item{Nsub}{Number of patients who are ever at risk of |
| 62 |
the transition of interest} \item{est_quant}{Pointwise 2.5 and 97.5 quantile |
| 63 |
limits for each of the traces} \item{obs_chisq_trace}{Trace of the |
| 64 |
chi-squared statistic} \item{nch_wb_trace}{Individual values of the |
| 65 |
chi-squared statistic trace for the wild bootstrap samples} |
| 66 |
\item{n_wb_trace}{Individual values of the log-rank z statistic traces for |
| 67 |
the wild bootstrap samples} \item{est_cov}{Estimated covariance matrix |
| 68 |
between the log-rank statistics at each grid point} \item{transition}{The |
| 69 |
transition number tested} \item{from}{The from state of the transition |
| 70 |
tested} \item{to}{The to state of the transition tested} \item{B}{The number |
| 71 |
of wild bootstrap replications} \item{dist}{The distribution used in the |
| 72 |
wild bootstrap} \item{qualset}{Set of qualifying states corresponding to the |
| 73 |
components of the above traces} \item{coxfit}{Fitted coxph object} |
| 74 |
\item{fn}{List of functions applied to state-specific trace} \item{fn2}{List |
| 75 |
of functions applied to overall trace} |
| 76 |
} |
| 77 |
\description{ |
| 78 |
Log-rank based test for the validity of the Markov assumption |
| 79 |
} |
| 80 |
\details{ |
| 81 |
Function MarkovTest performs the log-rank test described in Titman & Putter |
| 82 |
(2020). Function optimal_weights_matrix implements the optimal weighting for |
| 83 |
the state-specific trace. Function optimal_weights_multiple implements the |
| 84 |
optimal weighting for the chi-squared trace. |
| 85 |
} |
| 86 |
\examples{ |
| 87 |
|
| 88 |
\dontrun{ |
| 89 |
# Example provided by the prothrombin data |
| 90 |
data("prothr") |
| 91 |
# Apply Markov test to grid of monthly time points over the first 7.5 years |
| 92 |
year <- 365.25 |
| 93 |
month <- year / 12 |
| 94 |
grid <- month * (1 : 90) |
| 95 |
# Markov test for transition 1 (wild bootstrap based on 25 replications, 1000 recommended) |
| 96 |
MT <- MarkovTest(prothr, id = "id", transition = 1, |
| 97 |
grid = grid, B = 25) |
| 98 |
|
| 99 |
# Plot traces |
| 100 |
plot(MT, grid, what="states", idx=1:10, states=rownames(attr(prothr, "trans")), |
| 101 |
xlab="Days since randomisation", ylab="Log-rank test statistic", |
| 102 |
main="Transition Normal -> Low") |
| 103 |
plot(MT, grid,what="overall", idx=1:10, |
| 104 |
xlab="Days since randomisation", ylab="Chi-square test statistic", |
| 105 |
main="Transition Normal -> Low") |
| 106 |
|
| 107 |
# Example using optimal weights and adjustment for covariates |
| 108 |
oweights_fun <- |
| 109 |
optimal_weights_matrix(prothr, id = "id", grid=grid, transition = 1, |
| 110 |
other_weights=list( |
| 111 |
function(x) mean(abs(x),na.rm=TRUE), |
| 112 |
function(x) max(abs(x),na.rm=TRUE))) |
| 113 |
|
| 114 |
oweights_chi <- optimal_weights_multiple(prothr, id = "id", grid=grid, transition = 1) |
| 115 |
|
| 116 |
# Formula in MarkovTest only works for continuous covariates and dummy coded variables |
| 117 |
# No factors allowed |
| 118 |
prothr$prednisone <- as.numeric(prothr$treat == "Prednisone") |
| 119 |
MT <- MarkovTest(prothr, id = "id", |
| 120 |
formula = "prednisone", |
| 121 |
transition = 1, |
| 122 |
grid = grid, B = 25, |
| 123 |
fn = oweights_fun, |
| 124 |
fn2 = list( |
| 125 |
function(x) weighted.mean(x, w=oweights_chi, na.rm=TRUE), |
| 126 |
function(x) mean(x, na.rm=TRUE), |
| 127 |
function(x) max(x, na.rm=TRUE))) |
| 128 |
} |
| 129 |
|
| 130 |
} |
| 131 |
\references{ |
| 132 |
Titman AC, Putter H (2020). General tests of the Markov property |
| 133 |
in multi-state models. \emph{Biostatistics} To appear. |
| 134 |
} |
| 135 |
\author{ |
| 136 |
Andrew Titman \email{[email protected]}, transported to |
| 137 |
mstate by Hein Putter \email{[email protected]} |
| 138 |
} |
| 139 |
\keyword{univar} |