-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdemographic report.Rmd
More file actions
116 lines (90 loc) · 2.61 KB
/
demographic report.Rmd
File metadata and controls
116 lines (90 loc) · 2.61 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
108
109
110
111
112
113
114
115
116
---
title: "Example knitr/R Markdown document"
author: "Your name"
date: "22/5/2020"
output:
word_document: default
---
```{r include=FALSE}
knitr::opts_chunk$set(message=FALSE)
knitr::opts_chunk$set(dpi = 300)
```
# Load necessary library
```{r}
if (!require("pacman")) install.packages("pacman")
pacman::p_load(ggplot2, tidyr, dplyr, tidyverse, knitr, finalfit, here)
```
# Demographic Table
```{r warning=FALSE}
# Specify explanatory variables of interest
explanatory <- c("age", "sex.factor",
"extent.factor", "obstruct.factor",
"nodes")
colon_s %>%
summary_factorlist("differ.factor", explanatory,
p=TRUE, na_include=TRUE)
```
# Generate Final Table
```{r warning=FALSE}
colon_s <- colon_s %>%
mutate(
nodes = ff_label(nodes, "Lymph nodes involved")
)
table1 <- colon_s %>%
summary_factorlist("differ.factor", explanatory,
p=TRUE, na_include=TRUE,
add_dependent_label=TRUE,
dependent_label_prefix = "Exposure: "
)
table1
```
# Logistic Regression Table
```{r warning=FALSE}
explanatory <- c( "differ.factor", "age", "sex.factor",
"extent.factor", "obstruct.factor",
"nodes")
dependent <- "mort_5yr"
table2 <- colon_s %>%
finalfit(dependent, explanatory,
dependent_label_prefix = "")
table2
```
# Odds Ratio Plot
```{r warning=FALSE}
colon_s %>%
or_plot(dependent, explanatory,
breaks = c(0.5, 1, 5, 10, 20, 30),
table_text_size = 2.5)
```
# Save objects for knitr/markdown
```{r}
# creat folder
dir.create(here::here("data"), showWarnings = FALSE, recursive = TRUE)
# Verify the path
file_path <- here::here("data", "out.rda")
print(file_path)
# Save the objects
save(table1, table2, dependent, explanatory, file = file_path)
```
## Load Data
```{r}
load(here::here("data", "out.rda"))
```
## Table 1 - Demographics
```{r table1, echo = FALSE, warning=FALSE}
kable(table1, row.names=FALSE, align=c("l", "l", "r", "r", "r", "r"))
```
## Table 2 - Association between tumour factors and 5-year mortality
```{r table2, echo = FALSE, warning=FALSE}
kable(table2, row.names=FALSE, align=c("l", "l", "r", "r", "r", "r"))
```
## Figure 1 - Association between tumour factors and 5-year mortality
```{r figure1, echo = FALSE, warning=FALSE}
explanatory = c( "differ.factor", "age", "sex.factor",
"extent.factor", "obstruct.factor",
"nodes")
dependent = "mort_5yr"
colon_s %>%
or_plot(dependent, explanatory, breaks = c(0.5, 1, 5, 10, 20, 30),
table_text_size = 2.5)
```