-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathio28-mockstudy_analysis_chisq.Rmd
executable file
·128 lines (97 loc) · 2.81 KB
/
io28-mockstudy_analysis_chisq.Rmd
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
---
title: "Chisq and basic graphs from mockstudy"
author: "Peter Higgins"
date: "4/25/2019"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(arsenal)
library(survival)
library(survminer)
library(patchwork)
library(tidyverse)
library(janitor)
library(gt)
data("mockstudy")
```
### Take a look at the data
```{r glimpse}
glimpse(mockstudy)
```
### Set up a chisquared table
with text interpretation with inline r code.
```{r table, warning=FALSE}
mockstudy %>%
tabyl(arm, fu.stat) ->
outcome_table
names(outcome_table) <- c("Study Arm", "Lived", "Died")
outcome_table %>%
gt()
```
```{r chisq, messages=FALSE}
mockstudy %>%
tabyl(arm, fu.stat) %>%
column_to_rownames('arm') %>%
chisq.test() ->
results
results$statistic
results$parameter
```
### Study Results
This is a statement of study results. <br>
In the evaluation of followup status by study arm, the null hypothesis of independence was rejected, with a chi-squared statistic of `r round(results$statistic,2)`, with `r results$parameter` degrees of freedom, and a p value of `r results$p.value`, using the `r results$method` method.
```{r}
```
### Start with a barplot
for percent survival
tag it as panel A for a multipanel plot
```{r survival_barplot}
mockstudy %>%
group_by(arm) %>%
summarize(surv = length(which(fu.stat==1)),
died = length(which(fu.stat==2)),
pct_surv = surv*100/(died+surv)) %>%
select(arm, surv, died, pct_surv) %>%
ggplot() +
aes(x=arm, y = pct_surv, fill=arm,
label= round(pct_surv,1)) +
geom_bar(stat= 'identity') +
labs(y= "Percent Survived \n To End of Followup", x= "Study Arm", tag ="A") +
theme_classic2(base_size = 15) +
theme(legend.position = 'none') +
geom_text(size=5, vjust=-0.3) +
scale_fill_manual(values = c("black", "green", "blue")) +
ylim(0,18) ->
p1
```
### Now add a boxplot, make it multipanel
tagged as panel B
```{r survivaltime_boxplot}
mockstudy %>%
group_by(arm) %>%
ggplot() +
aes(x=arm, y = fu.time, fill=arm) +
geom_violin(alpha =0.3) +
geom_jitter(width =0.25, alpha=0.15) +
labs(y= "Survival Time in \nDays (Censored)", x= "Study Arm", tag = "B") +
theme_classic2(base_size = 15) +
theme(legend.position = 'none') +
scale_fill_manual(values = c("black", "green", "blue")) ->
p2
p1 + p2 + plot_layout(ncol=2, heights = c(4,4))
```
### Now add a survival curve
For some reason, patchwork does not work with this survival curve
```{r survival_curves}
survfit(formula = Surv(fu.time, fu.stat) ~ arm, data= mockstudy) ->
fit
ggsurvplot(fit,
pval = TRUE, conf.int = TRUE,
risk.table = TRUE,
risk.table.col = "strata",
linetype = "strata",
surv.median.line = "hv",
ggtheme = theme_bw(),
palette = c("black", "blue", "gray80"))
```