| 1 |
% Generated by roxygen2: do not edit by hand |
| 2 |
% Please edit documentation in R/vis.mirror.pt.R |
| 3 |
\name{vis.mirror.pt} |
| 4 |
\alias{vis.mirror.pt} |
| 5 |
\title{Mirror plot comparing two probtrans objects} |
| 6 |
\usage{ |
| 7 |
vis.mirror.pt( |
| 8 |
x, |
| 9 |
titles, |
| 10 |
size_titles = 5, |
| 11 |
horizon = NULL, |
| 12 |
breaks_x_left, |
| 13 |
breaks_x_right, |
| 14 |
from = 1, |
| 15 |
cols, |
| 16 |
ord, |
| 17 |
xlab = "Time", |
| 18 |
ylab = "Probability", |
| 19 |
legend.pos = "right" |
| 20 |
) |
| 21 |
} |
| 22 |
\arguments{ |
| 23 |
\item{x}{A list of two \code{"probtrans"} objects. |
| 24 |
The first element will be on the left of the mirror plot, |
| 25 |
and the second on the right} |
| 26 |
|
| 27 |
\item{titles}{A character vector c("Title for left", "Title for right")} |
| 28 |
|
| 29 |
\item{size_titles}{Numeric, size of the title text} |
| 30 |
|
| 31 |
\item{horizon}{Numeric, position denoting (in time) where to symmetrically |
| 32 |
mirror the plots. Default is maximum follow-up of from both plots.} |
| 33 |
|
| 34 |
\item{breaks_x_left}{Numeric vector specifying axis breaks on the left plot} |
| 35 |
|
| 36 |
\item{breaks_x_right}{Numeric vector specifying axis breaks on the right plot} |
| 37 |
|
| 38 |
\item{from}{The starting state from which the probabilities are used to plot} |
| 39 |
|
| 40 |
\item{cols}{A vector specifying colors for the different transitions; |
| 41 |
default is a palette from green to red, when type=\code{"filled"} (reordered |
| 42 |
according to \code{ord}, and 1 (black), otherwise} |
| 43 |
|
| 44 |
\item{ord}{A vector of length equal to the number of states, specifying the |
| 45 |
order of plotting in case type=\code{"stacked"} or \code{"filled"}} |
| 46 |
|
| 47 |
\item{xlab}{A title for the x-axis, default is "Time"} |
| 48 |
|
| 49 |
\item{ylab}{A title for the y-axis, default is "Probability"} |
| 50 |
|
| 51 |
\item{legend.pos}{Position of the legend, default is "right"} |
| 52 |
} |
| 53 |
\value{ |
| 54 |
A ggplot2 object. |
| 55 |
} |
| 56 |
\description{ |
| 57 |
A mirror plot for comparing two different \code{"probtrans"} objects. Useful |
| 58 |
for comparing predicted probabilities for different levels of a covariate, |
| 59 |
or for different subgroups at some prediction time horizon. |
| 60 |
} |
| 61 |
\examples{ |
| 62 |
|
| 63 |
library(ggplot2) |
| 64 |
|
| 65 |
data("aidssi") |
| 66 |
head(aidssi) |
| 67 |
si <- aidssi |
| 68 |
|
| 69 |
# Prepare transition matrix |
| 70 |
tmat <- trans.comprisk(2, names = c("event-free", "AIDS", "SI")) |
| 71 |
|
| 72 |
# Run msprep |
| 73 |
si$stat1 <- as.numeric(si$status == 1) |
| 74 |
si$stat2 <- as.numeric(si$status == 2) |
| 75 |
|
| 76 |
silong <- msprep( |
| 77 |
time = c(NA, "time", "time"), |
| 78 |
status = c(NA, "stat1", "stat2"), |
| 79 |
data = si, keep = "ccr5", trans = tmat |
| 80 |
) |
| 81 |
|
| 82 |
# Run cox model |
| 83 |
silong <- expand.covs(silong, "ccr5") |
| 84 |
c1 <- coxph(Surv(time, status) ~ ccr5WM.1 + ccr5WM.2 + strata(trans), |
| 85 |
data = silong) |
| 86 |
|
| 87 |
# 1. Prepare reference patient data - both CCR5 genotypes |
| 88 |
WW <- data.frame( |
| 89 |
ccr5WM.1 = c(0, 0), |
| 90 |
ccr5WM.2 = c(0, 0), |
| 91 |
trans = c(1, 2), |
| 92 |
strata = c(1, 2) |
| 93 |
) |
| 94 |
|
| 95 |
WM <- data.frame( |
| 96 |
ccr5WM.1 = c(1, 0), |
| 97 |
ccr5WM.2 = c(0, 1), |
| 98 |
trans = c(1, 2), |
| 99 |
strata = c(1, 2) |
| 100 |
) |
| 101 |
|
| 102 |
# 2. Make msfit objects |
| 103 |
msf.WW <- msfit(c1, WW, trans = tmat) |
| 104 |
msf.WM <- msfit(c1, WM, trans = tmat) |
| 105 |
|
| 106 |
# 3. Make probtrans objects |
| 107 |
pt.WW <- probtrans(msf.WW, predt = 0) |
| 108 |
pt.WM <- probtrans(msf.WM, predt = 0) |
| 109 |
|
| 110 |
# Mirror plot split at 10 years - see vignette for more details |
| 111 |
vis.mirror.pt( |
| 112 |
x = list(pt.WW, pt.WM), |
| 113 |
titles = c("WW", "WM"), |
| 114 |
horizon = 10 |
| 115 |
) |
| 116 |
|
| 117 |
} |
| 118 |
\seealso{ |
| 119 |
\code{\link{plot.probtrans}} |
| 120 |
} |
| 121 |
\author{ |
| 122 |
Edouard F. Bonneville \email{[email protected]} |
| 123 |
} |