generated from UtrechtUniversity/simple-r-project
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Part_2_Descriptives.qmd
240 lines (185 loc) · 10.6 KB
/
Part_2_Descriptives.qmd
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
---
title: "Preoperative Atelectasis"
subtitle: "Part 2: Descriptive characteristics and map"
author: "Javier Mancilla Galindo"
date: "`r Sys.Date()`"
execute:
echo: true
warning: false
toc: true
toc_float: true
format:
html:
embed-resources: true
pdf:
documentclass: scrartcl
editor: visual
---
# Setup
#### Packages used
```{r}
if (!require("pacman", quietly = TRUE)) {
install.packages("pacman")
}
pacman::p_load(
tidyverse, # Used for basic data handling and visualization.
table1, #Used to create table of descriptive characteristics of sample.
RColorBrewer, #Color palettes for data visualization.
gridExtra, #Used to arrange multiple ggplots in a grid.
grid, #Used to arrange multiple ggplots in a grid.
rnaturalearth, #Used to extract geographical data to create maps.
rnaturalearthhires, #Used together with the prior package to create map.
sf, #Used together with the prior package to create map.
plotly, #Used together with prior two packages to create map.
reticulate, #Required together with plotly
flextable, #Used to export tables.
officer, #Used to export tables.
report, #Used to cite packages used in this session.
webshot2 #Required to render this document as pdf.
)
```
```{r}
#| include: false
# If you get an error linked to loading rnaturalearthhires, please run
# this code. If not, ignore this chunk of code.
if (!require("remotes", quietly = TRUE)) {
install.packages("remotes")
}
remotes::install_github("ropensci/rnaturalearthhires")
pacman::p_load(rnaturalearthhires)
```
##### Session and package dependencies
```{r}
#| echo: false
# Credits chunk of code: Alex Bossers, Utrecht University (a.bossers@uu.nl)
# remove clutter
session <- sessionInfo()
session$BLAS <- NULL
session$LAPACK <- NULL
session$loadedOnly <- NULL
# write log file
writeLines(
capture.output(print(session, locale = FALSE)),
paste0("sessions/",lubridate::today(), "_session_Part_2.txt")
)
session
```
```{r}
#| include: false
# Create directories for sub-folders
figfolder <- "../results/output_figures"
tabfolder <- "../results/output_tables"
psfolder <- "../data/processed"
dir.create(figfolder, showWarnings = FALSE)
dir.create(tabfolder, showWarnings = FALSE)
dir.create(psfolder, showWarnings = FALSE)
```
```{r}
#| include: false
# Load dataset
data <- read.csv("../data/processed/atelectasis_included.csv",
na.strings="NA",
row.names = NULL)
# Recode variables
source("scripts/variable_names.R")
```
# State of residence of participants
Map generated with the accompanying script ***Map_USA_Canada.R***
This map was built by partly using code adapted from [contribution by cpsievert](https://community.rstudio.com/t/combining-usa-canada-specific-province-with-plotly-plot-geo-or-ggplot2/12375).
```{r}
#| echo: false
#| warning: false
# This may take a few seconds to run, please be patient and ignore warnings.
source("scripts/Map_USA_Canada.R")
fig
rm(canada, usa, fig, fig_add, figS4, table, us_laea)
```
# Distribution of numerical variables
Distributions were examined with the accompanying sourced function ***distribution_numerical_variables.R***
```{r, fig.height = 4, fig.width = 6}
#| include: false
# If plots are not showing and you wish to see them,
# please change the above to ## include: true ##
source("scripts/distribution_plots.R")
distribution_plots(data)
```
Near normal distribution:\
- Age: light tails\
- height: heavy right tail, 4 outliers right\
- hb: heavy tails, bilateral outliers\
- hct: heavy tails, bilateral outliers\
- leu: near normal, bilateral outliers\
- neu_absolute: heavy right tail, two right outliers\
- linf_absolute: heavy right tail, bilateral outliers (more right)\
- mon_absolute: heavy right tail, bilateral outliers (more right)\
- platelets: two right outliers\
- urea: four right outliers\
- creatinine: three right outliers
Distribution not normal:\
- Weight: right-skewed, outliers are verified observations of extreme weight.\
- BMI: right-skewed, outliers are verified observations of extreme BMI.\
- spo2_VPO: Left-skewed\
- neu_percent: left-skewed\
- linf_percent: right-skewed\
- glucose: right-skewed\
- mon_percent: observations around only 5 data points. Will not use this variable, only absolute monocytes will be used.\
- altitude: distribution not clear as values are quite apart an concentrate around single states with diferring mean altitudes. Will attempt to model a smooth term or categorical term in subsequent analyses.
Outcome variable:\
- atelectasis_percent: Zero-inflated. Would be difficult to manage as categorical ordinal due to low number of patients in some categories. Will re-assess alongside subsequent analyses to decide.
# Characteristics of participants
Table 1 generated with the accompanying sourced script ***table1_arguments.R***
```{r}
#| include: false
source("scripts/table1_arguments.R", local = knitr::knit_global())
```
Characteristics of participants are shown for the total sample and by obesity class category as defined by the [World Health Organization](https://www.who.int/europe/news-room/fact-sheets/item/a-healthy-lifestyle---who-recommendations):
- Class 1, BMI (30-35) kg/m2\
- Class 2, BMI (35-40) kg/m2\
- Class 3, BMI \>40 kg/m2
> Characteristics of participants according to BMI class are shown in **Table 1**.
## Table 1
```{r}
#| echo: false
table1
```
NOTE: The **ASA** physical status variable has not been included in analyses since the [updated version of ASA](https://www.asahq.org/standards-and-practice-parameters/statement-on-asa-physical-status-classification-system) consulted in October 2023 classifies obesity (30\<BMI\<40) as ASA 2 and obesity (BMI ≥40) as ASA 3. The distribution of frequencies of ASA\~obesity class in this dataset does not match such definition. This occurred since an outdated version of ASA that did not include obesity was likely used by clinicians when writing the preoperative assessment medical note:
```{r}
#| echo: false
table(data$ASA,data$type_obesity)
```
# Package references
```{r}
#| include: false
report::cite_packages(session)
```
- Auguie B (2017). *gridExtra: Miscellaneous Functions for "Grid" Graphics*. R package version 2.3, <https://CRAN.R-project.org/package=gridExtra>.
- Chang W (2023). *webshot2: Take Screenshots of Web Pages*. R package version 0.1.1, <https://CRAN.R-project.org/package=webshot2>.
- Gohel D, Moog S (2024). *officer: Manipulation of Microsoft Word and PowerPoint Documents*. R package version 0.6.5, <https://CRAN.R-project.org/package=officer>.
- Gohel D, Skintzos P (2024). *flextable: Functions for Tabular Reporting*. R package version 0.9.5, <https://CRAN.R-project.org/package=flextable>.
- Grolemund G, Wickham H (2011). “Dates and Times Made Easy with lubridate.” *Journal of Statistical Software*, *40*(3), 1-25. <https://www.jstatsoft.org/v40/i03/>.
- Makowski D, Lüdecke D, Patil I, Thériault R, Ben-Shachar M, Wiernik B (2023). “Automated Results Reporting as a Practical Tool to Improve Reproducibility and Methodological Best Practices Adoption.” *CRAN*. <https://easystats.github.io/report/>.
- Massicotte P, South A (2023). *rnaturalearth: World Map Data from Natural Earth*. R package version 1.0.1, <https://CRAN.R-project.org/package=rnaturalearth>.
- Müller K, Wickham H (2023). *tibble: Simple Data Frames*. R package version 3.2.1, <https://CRAN.R-project.org/package=tibble>.
- Neuwirth E (2022). *RColorBrewer: ColorBrewer Palettes*. R package version 1.1-3, <https://CRAN.R-project.org/package=RColorBrewer>.
- Pebesma E, Bivand R (2023). *Spatial Data Science: With applications in R*. Chapman and Hall/CRC. doi:10.1201/9780429459016 <https://doi.org/10.1201/9780429459016>, <https://r-spatial.org/book/>. Pebesma E (2018). “Simple Features for R: Standardized Support for Spatial Vector Data.” *The R Journal*, *10*(1), 439-446. doi:10.32614/RJ-2018-009 <https://doi.org/10.32614/RJ-2018-009>, <https://doi.org/10.32614/RJ-2018-009>.
- R Core Team (2024). *R: A Language and Environment for Statistical Computing*. R Foundation for Statistical Computing, Vienna, Austria. <https://www.R-project.org/>.
- Rich B (2023). *table1: Tables of Descriptive Statistics in HTML*. R package version 1.4.3, <https://CRAN.R-project.org/package=table1>.
- Rinker TW, Kurkiewicz D (2018). *pacman: Package Management for R*. version 0.5.0, <http://github.com/trinker/pacman>.
- Sievert C (2020). *Interactive Web-Based Data Visualization with R, plotly, and shiny*. Chapman and Hall/CRC. ISBN 9781138331457, <https://plotly-r.com>.
- South A, Michael S, Massicotte P (????). *rnaturalearthhires: High Resolution World Vector Map Data from Natural Earth used in rnaturalearth*. R package version 1.0.0.9000, https://github.com/ropensci/rnaturalearthhires, <https://docs.ropensci.org/rnaturalearthhires>.
- Ushey K, Allaire J, Tang Y (2024). *reticulate: Interface to 'Python'*. R package version 1.35.0, <https://CRAN.R-project.org/package=reticulate>.
- Wickham H (2016). *ggplot2: Elegant Graphics for Data Analysis*. Springer-Verlag New York. ISBN 978-3-319-24277-4, <https://ggplot2.tidyverse.org>.
- Wickham H (2023). *forcats: Tools for Working with Categorical Variables (Factors)*. R package version 1.0.0, <https://CRAN.R-project.org/package=forcats>.
- Wickham H (2023). *stringr: Simple, Consistent Wrappers for Common String Operations*. R package version 1.5.1, <https://CRAN.R-project.org/package=stringr>.
- Wickham H, Averick M, Bryan J, Chang W, McGowan LD, François R, Grolemund G, Hayes A, Henry L, Hester J, Kuhn M, Pedersen TL, Miller E, Bache SM, Müller K, Ooms J, Robinson D, Seidel DP, Spinu V, Takahashi K, Vaughan D, Wilke C, Woo K, Yutani H (2019). “Welcome to the tidyverse.” *Journal of Open Source Software*, *4*(43), 1686. doi:10.21105/joss.01686 <https://doi.org/10.21105/joss.01686>.
- Wickham H, François R, Henry L, Müller K, Vaughan D (2023). *dplyr: A Grammar of Data Manipulation*. R package version 1.1.4, <https://CRAN.R-project.org/package=dplyr>.
- Wickham H, Henry L (2023). *purrr: Functional Programming Tools*. R package version 1.0.2, <https://CRAN.R-project.org/package=purrr>.
- Wickham H, Hester J, Bryan J (2024). *readr: Read Rectangular Text Data*. R package version 2.1.5, <https://CRAN.R-project.org/package=readr>.
- Wickham H, Vaughan D, Girlich M (2024). *tidyr: Tidy Messy Data*. R package version 1.3.1, <https://CRAN.R-project.org/package=tidyr>.
```{r}
#| include: false
# Run this chunk if you wish to clear your environment and unload packages.
rm(properties, name, table1, rndr, normal, nonormal, distribution_plots,
abbreviations, abbreviations_stats,data, figfolder, psfolder, tabfolder, session)
pacman::p_unload(negate = TRUE)
```