if (FALSE) {
# Example provided by the prothrombin data
data("prothr")
# Apply Markov test to grid of monthly time points over the first 7.5 years
year <- 365.25
month <- year / 12
grid <- month * (1 : 90)
# Markov test for transition 1 (wild bootstrap based on 25 replications, 1000 recommended)
MT <- MarkovTest(prothr, id = "id", transition = 1,
grid = grid, B = 25)
# Plot traces
plot(MT, grid, what="states", idx=1:10, states=rownames(attr(prothr, "trans")),
xlab="Days since randomisation", ylab="Log-rank test statistic",
main="Transition Normal -> Low")
plot(MT, grid,what="overall", idx=1:10,
xlab="Days since randomisation", ylab="Chi-square test statistic",
main="Transition Normal -> Low")
# Example using optimal weights and adjustment for covariates
oweights_fun <-
optimal_weights_matrix(prothr, id = "id", grid=grid, transition = 1,
other_weights=list(
function(x) mean(abs(x),na.rm=TRUE),
function(x) max(abs(x),na.rm=TRUE)))
oweights_chi <- optimal_weights_multiple(prothr, id = "id", grid=grid, transition = 1)
# Formula in MarkovTest only works for continuous covariates and dummy coded variables
# No factors allowed
prothr$prednisone <- as.numeric(prothr$treat == "Prednisone")
MT <- MarkovTest(prothr, id = "id",
formula = "prednisone",
transition = 1,
grid = grid, B = 25,
fn = oweights_fun,
fn2 = list(
function(x) weighted.mean(x, w=oweights_chi, na.rm=TRUE),
function(x) mean(x, na.rm=TRUE),
function(x) max(x, na.rm=TRUE)))
}
Run the code above in your browser using DataLab