forked from jinseob2kim/jskm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathREADME.Rmd
More file actions
108 lines (83 loc) · 3.83 KB
/
README.Rmd
File metadata and controls
108 lines (83 loc) · 3.83 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
---
title: "jskm"
output: github_document
editor_options:
chunk_output_type: console
---
Kaplan-Meier Plot with 'ggplot2': 'survfit' and 'svykm' objects from 'survival' and 'survey' packages.
[](https://ci.appveyor.com/project/jinseob2kim/jskm)
[](https://github.com/jinseob2kim/jskm/actions)
[](https://cran.r-project.org/package=jskm)
[](https://CRAN.R-project.org/package=jskm)
[](https://app.codecov.io/github/jinseob2kim/jskm)
[](https://github.com/jinseob2kim/jskm/issues)
[](https://github.com/jinseob2kim/jskm/stargazers)
[](https://github.com/jinseob2kim/jskm/blob/master/LICENSE)
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE, message = F, warning = F, fig.path = "man/figures/README-")
library(jskm)
```
## Install
```r
install.packages("jskm")
## From github: latest version
install.packages("remotes")
remotes::install_github("jinseob2kim/jskm")
library(jskm)
```
## Example
### Survival probability
```{r}
# Load dataset
library(survival)
data(colon)
fit <- survfit(Surv(time, status) ~ rx, data = colon)
# Plot the data
jskm(fit)
jskm(fit,
table = T, pval = T, label.nrisk = "No. at risk", size.label.nrisk = 8,
xlabs = "Time(Day)", ylabs = "Survival", ystratalabs = c("Obs", "Lev", "Lev + 5FU"), ystrataname = "rx",
marks = F, timeby = 365, xlims = c(0, 3000), ylims = c(0.25, 1), showpercent = T
)
```
### Cumulative hazard: 1- Survival probability
```{r}
jskm(fit, ci = T, cumhaz = T, mark = F, ylab = "Cumulative incidence (%)", surv.scale = "percent", pval = T, pval.size = 6, pval.coord = c(300, 0.7))
```
### Landmark analysis
```{r}
jskm(fit, mark = F, surv.scale = "percent", pval = T, table = T, cut.landmark = 500)
jskm(fit, mark = F, surv.scale = "percent", pval = T, table = T, cut.landmark = 500, showpercent = T)
```
### Competing risk analysis
`status2` variable: 0 - censoring, 1 - event, 2 - competing risk
```{r}
## Make competing risk variable, Not real
colon$status2 <- colon$status
colon$status2[1:400] <- 2
colon$status2 <- factor(colon$status2)
fit2 <- survfit(Surv(time, status2) ~ rx, data = colon)
jskm(fit2, mark = F, surv.scale = "percent", table = T, status.cmprsk = "1")
jskm(fit2, mark = F, surv.scale = "percent", table = T, status.cmprsk = "1", showpercent = T, cut.landmark = 500)
```
### Weighted Kaplan-Meier plot - `svykm.object` in **survey** package
```{r}
library(survey)
data(pbc, package = "survival")
pbc$randomized <- with(pbc, !is.na(trt) & trt > 0)
biasmodel <- glm(randomized ~ age * edema, data = pbc)
pbc$randprob <- fitted(biasmodel)
dpbc <- svydesign(id = ~1, prob = ~randprob, strata = ~edema, data = subset(pbc, randomized))
s1 <- svykm(Surv(time, status > 0) ~ 1, design = dpbc)
s2 <- svykm(Surv(time, status > 0) ~ sex, design = dpbc)
svyjskm(s1)
svyjskm(s2, pval = T, table = T, design = dpbc)
svyjskm(s2, cumhaz = T, ylab = "Cumulative incidence (%)", surv.scale = "percent", pval = T, design = dpbc, pval.coord = c(300, 0.7), showpercent = T)
```
If you want to get **confidence interval**, you should apply `se = T` option to `svykm` object.
```{r}
s3 <- svykm(Surv(time, status > 0) ~ sex, design = dpbc, se = T)
svyjskm(s3)
svyjskm(s3, ci = F)
svyjskm(s3, ci = F, surv.scale = "percent", pval = T, table = T, cut.landmark = 1000, showpercent = T)
```