generated from UtrechtUniversity/simple-r-project
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPart_3_Independent_variables.qmd
2537 lines (1905 loc) · 62.1 KB
/
Part_3_Independent_variables.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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
---
title: "Preoperative Atelectasis"
subtitle: "Part 3: Assessment of Independent Variables"
author: "Javier Mancilla Galindo"
date: "`r Sys.Date()`"
execute:
echo: false
warning: false
toc: true
toc_float: true
format:
html:
embed-resources: true
pdf:
documentclass: scrartcl
editor: visual
---
\pagebreak
# Setup
#### Packages used
```{r}
#| echo: true
if (!require("pacman", quietly = TRUE)) {
install.packages("pacman")
}
pacman::p_load(
tidyverse, # Used for basic data handling and visualization.
table1, #Used to add lables to variables.
mgcv, #Used to model non-linear relationships with a general additive model.
ggmosaic, #Used to create mosaic plots.
car, #Used to visualize distribution of continuous variables (stacked Q-Q plots).
dagitty, #Used in conjunction with https://www.dagitty.net/ to create
#directed acyclic graph to inform statistical modelling.
report #Used to cite packages used in this session.
)
```
##### Session and package dependencies
```{r}
# Credits chunk of code: Alex Bossers, Utrecht University ([email protected])
# 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_3.txt")
)
session
```
```{r}
#| include: false
# Create directories for sub-folders
figfolder <- "../results/output_figures"
dir.create(figfolder, 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")
```
\pagebreak
# Assessment of independent variables
The selection of variables that will be assessed is according to the following directed acyclic graph which will be used again before statistical modelling, to assess conditional independencies.
## DAG
DAG generated in the [DAGitty website](https://www.dagitty.net/) and sourced from the accompanying script ***DAG_atelectasis.R***
```{r}
source("scripts/DAG_atelectasis.R")
plot(DAG)
rm(DAG)
```
The rationale for variables in this DAG are as follows:
## Exposure
The increasing degree of obesity, according to the WHO obesity class categories or BMI, is the exposure of interest.
## Primary outcome
Having atelectasis (Yes or No) and an increasing degree of atelectasis (atelectasis_percent) are the main outcomes of interest. An arrow from type_obesity to atelectasis represents the exposure-outcome relationship of interest.
## Secondary outcome
Decreasing preoperative SpO2 is hypothesized to be related to an increasing degree of obesity. An arrow from type_obesity to spo2_VPO represents this. Atelectasis_percentage is thought to be the main mediator of the effect of BMI on preoperative SpO2. An arrow from type_obesity to atelectasis_percent, followed by an arrow from atelectasis_percent to spo2_VPO.
## Covariates
#### Sex and Age
These two variables are known to be associated with a higher risk of developing postoperative atelectasis in patients with obesity undergoing bariatric surgery. [Baltieri, et al.](https://doi.org/10.1016/j.bjane.2014.11.016). Arrows originating from these variables and going to type_obesity, atelectasis_percent, and spo2_VPO represent these relationships.\
The implications for analyses is that ***sex*** and ***age*** are both **confonders** to be accounted for in both the models with atelectasis and SpO2 as outcomes.
#### Obstructive sleep apnea
Increasing BMI is a strong risk factor for OSA and OSA severity. [Baltieri, et al.](https://doi.org/10.1378%2Fchest.09-0360) Therefore, an arrow originating in type_obesity, pointing towards OSA represents this relationship. OSA is hypothesized to lead to the degree of atelectasis and preoperative SpO2. Therefore, an arrow from OSA to atelectasis_percent and spo2_VPO represents these relationships. The implications for the analysis are the following:
1. OSA is a potential mediator of the effect of BMI on atelectasis percentage. Therefore, this variable should **not** be adjusted for in the models with ***atelectasis*** as the outcome.\
2. OSA is a **confounder** of the mediator-outcome relationship in the models with ***SpO2*** as the outcome.
#### Asthma
It has been shown that obesity leads to asthma, whereas the inverse relationship is very unlikely to be possible. Thus, an arrow from type obesity to asthma was drawn. [Yang-Ching, et al.](https://www.nature.com/articles/s41366-018-0160-8).
It has been reported that obesity-assiciated late onset non-allergic asthma is negatively related to atelectasis due to a tendency to develop more air trapping than atelectasis in these patients, compared to patients with obesity and no diagnosis of asthma in whom the airways collapse slowly and air is expelled, leading to atelectasis. [Bhatawadekar , et al.](https://www.atsjournals.org/doi/10.1513/AnnalsATS.202010-1317RL). During sleep, asthma affects SpO2 independently of BMI and OSA. [Sundbom, et al.](https://doi.org/10.5664/jcsm.10178) For these reasons, an arrow from asthma to atelectasis, and an arrow from asthma to SpO2 was drawn.
The implications for the analysis are the following:
1. Asthma is a potential mediator of the effect of BMI on atelectasis percentage. Therefore, this variable should **not** be adjusted for in the models with ***atelectasis*** as the outcome.\
2. Asthma is a potential **confounder** of the mediator-outcome relationship in the models with ***SpO2*** as the outcome.
#### COPD
Although there is a strong relationship between undernutrition and COPD, the releationship between obesity and COPD has been inconsistent among studies. Since this study only included patients with obesity, the potential relationship between underweight and COPD is likely not relevant for this particular study. Furthermore, there is still doubt regarding any potential role of obesity-related pathophysiological mechanisms which could potentially lead to COPD. [Hanson, et al](https://doi.org/10.2147/copd.s50111). For these reasons, an arrow between COPD and obesity (or the inverse) was not drawn. This assumption was checked through the conditional independencies check (see Part 4), and this assumption is consistent with the data.
Regarding a relationship between COPD and SpO2, there is a clear relationship between these variables, reason why an arrow going from COPD to SpO2 was drawn. As for atelectasis, studies have found atelectasis, especially in patients with wood smoke-realted COPD. [González-García, et al](https://doi.org/10.1590/s1806-37132013000200005) and [Carmo Moreira, et al](https://doi.org/10.1590/s1806-37132013000200006) Thus, an arrow from COPD to atelectasis was drawn.
#### Altitude
Although not directly linked to obesity, participants with OSA at an an altitude above 1600 meters can develop hypobaric hypoxia, which "promotes frequent central apneas in addition to obstructive events, resulting in combined intermittent and sustained hypoxia". [Bloch, et al](https://doi.org/10.1089/ham.2015.0016)
For the atelectasis outcome, I could not find evidence either supporting or rejecting an association between altitude and prevalence of atelectasis. However, during the conditional independencies assumptions testing procedure, the data suggested a correlation, reason why an arrow from altitude to atelectasis was drawn as the reverse is less likely to be true (i.e., obesity would hardly determine the altitude of the place of residence).
The implications for analyses is that ***altitude_cat*** is a potential **confounder** to be accounted for in both the models with atelectasis and SpO2 as outcomes.
#### Oxygen use at home and CPAP use at home
These variables are descendants of the exposure, mediator, outcomes, and covariates of interest. The implications for analyses is that these 2 variables should **not** be adjusted for in any of the models.
#### Hemoglobin
There is no strong evidence supporting a link between BMI and hemoglobin. In any case, hemoglobin would be a descendant of all main variables of interest (exposure, mediator, and outcomes). Thus, hemoglobin was excluded from this DAG for simplification.
#### Other variables
Other variables that are potential confounders are not shown in this DAG since they were addressed by design in this study as follows:
- Current COVID-19: Exclusion criteria were applied to **n=2** patients with CO-RADS 3 and **n=2** with CO-RADS 4. Only participants with low probability of COVID-19 (CO-RADS 1 and 2) were included in this study.
- Prior COVID-19: This was an exclusion criterion (**n=3**).
- Bronchiectasis in chest CT: This was an exclusion criterion (n=0).
- Neuromuscular diseases: This was an exclusion criterion (n=0).
- Prior of current tuberculosis: This was an exclusion criterion (n=0).
#### Unmeasured variables
Due to the possibility of unmeasured confounders, E-values will be calculated and presented when possible as sensitivity analyses.
\pagebreak
## Description of independent variables
```{r}
#| include: false
attach(data)
```
#### Age
Summary:
```{r}
summary(age)
```
> The mean age was `r round(mean(data$age, na.rm=TRUE),1)` (SD: `r round(sd(data$age, na.rm=TRUE),2)`).
#### Sex
Frequencies:
```{r}
frequencies <- table(sex)
frequencies
```
Percentage:
```{r}
percentage <- round(prop.table(frequencies)*100,1)
percentage
```
> Most patients in the sample were woman (n=`r frequencies[1]`, `r percentage[1]`%).
```{r}
#| include: false
rm(frequencies,percentage)
```
#### Body mass index (BMI)
Summary:
```{r}
summary(BMI)
```
Frequencies:
```{r}
frequencies <- table(type_obesity)
frequencies
```
Percentage:
```{r}
percentage <- round(prop.table(frequencies)*100,1)
percentage
```
Distribution of BMI was assessed earlier. It is right-skewed due to extreme values (verified outliers). The WHO classification of BMI for obesity class will be used to complement descriptions and for potential use later during statistical modelling.
> The median BMI was `r median(data$BMI)` (IQR: `r quantile(data$BMI, 0.25)`- `r quantile(data$BMI, 0.75)`). The distribution of BMI was right-skewed due to extreme BMI values (range: `r min(data$BMI)`- `r max(data$BMI)`). Most patients were in the class 3 obesity category (n=`r frequencies[3]`, `r percentage[3]`%), followed by class 1 (n=`r frequencies[1]`, `r percentage[1]`%) and 2 (n=`r frequencies[2]`, `r percentage[2]`%). a
```{r}
#| include: false
rm(frequencies,percentage)
```
#### Obstructive sleep apnea
Frequencies:
```{r}
frequencies <- table(sleep_apnea)
frequencies
```
Percentage:
```{r}
percentage <- round(prop.table(frequencies)*100,1)
percentage
```
> Patients with a diagnosis of OSA were `r percentage[2]`% (n=`r frequencies[2]`) of the sample.
```{r}
#| include: false
rm(frequencies,percentage)
```
#### Asthma
Frequencies:
```{r}
frequencies <- table(asthma)
frequencies
```
Percentage:
```{r}
percentage <- round(prop.table(frequencies)*100,1)
percentage
```
> Patients with a diagnosis of asthma were `r percentage[2]`% (n=`r frequencies[2]`) of the sample.
```{r}
#| include: false
rm(frequencies,percentage)
```
#### COPD
Frequencies:
```{r}
frequencies <- table(COPD)
frequencies
```
Percentage:
```{r}
percentage <- round(prop.table(frequencies)*100,1)
percentage
```
> Patients with COPD were `r percentage[2]`% (n=`r frequencies[2]`) of the sample.
```{r}
#| include: false
rm(frequencies,percentage)
```
#### Altitude
Summary:
```{r}
summary(altitude)
```
Distribution of altitude was assessed earlier. Distribution is very unclear due to very widespread datapoints. Thus, I will create a new variable categorizing values according to the [study by Crocker ME, et al](https://doi.org/10.1016/S2214-109X(19)30543-1).
```{r}
data <- data %>%
mutate(altitude_cat = cut(altitude,
breaks=c(0,1000,2500),
right=FALSE,
labels=c("Low altitude","Moderate altitude")
)
)
```
```{r}
#| include: false
detach(data)
attach(data)
# This is done to update the attached dataset with the newly created variable.
```
Frequencies:
```{r}
frequencies <- table(altitude_cat)
frequencies
```
Percentage:
```{r}
round(prop.table(frequencies)*100,1)
```
```{r}
#| include: false
rm(frequencies)
```
#### SpO2
Summary:
```{r}
summary(spo2_VPO)
```
Distribution of SpO2 during the pre-anesthetic is left-skewed due to some participants exhibiting decreased SpO2. I will categorize according to clinical categories to assess the proportion of patients with decreased SpO2:
###### Proportion of patients with decreased SpO2
```{r}
# Creation of SpO2 categories:
data <- data %>%
mutate(spo2_cat = cut(spo2_VPO,
breaks=c(87,90,94,100),
right=TRUE,
labels=c("≤90","90 to 94",">94")
)
)
```
```{r}
#| include: false
detach(data)
attach(data)
# This is done to update the attached dataset with the newly created variable.
```
Frequencies:
```{r}
frequencies <- table(spo2_cat)
frequencies
```
Percentage:
```{r}
percentage <- round(prop.table(frequencies)*100,1)
percentage
```
> The median SpO2 during the pre-anethetic assessment was `r median(data$spo2_VPO)` (IQR: `r quantile(data$spo2_VPO, 0.25)`-`r quantile(data$spo2_VPO, 0.75)`) %, with a minimum value of `r min(data$spo2_VPO)`%. Of these, n=`r frequencies[3]` (`r percentage[3]`%) had normal SpO2 (above 94%), whereas n=`r frequencies[2]` (`r percentage[2]`%) had a value in the 90-94% range, and n=`r frequencies[1]` (`r percentage[1]`%) had ≤90%.
```{r}
#| include: false
rm(frequencies,percentage)
```
#### Oxygen use
Frequencies:
```{r}
frequencies <- table(oxygen_use)
frequencies
```
Percentage:
```{r}
percentage <- round(prop.table(frequencies)*100,1)
percentage
```
> A total `r frequencies[2]` (`r percentage[2]`%) patients used oxygen at home.
```{r}
#| include: false
rm(frequencies,percentage)
```
#### CPAP use
Frequencies:
```{r}
frequencies <- table(CPAP_use)
frequencies
```
Percentage:
```{r}
percentage <- round(prop.table(frequencies)*100,1)
percentage
```
> whereas `r percentage[2]`% (n=`r frequencies[2]`) reported using CPAP.
```{r}
#| include: false
rm(frequencies,percentage)
```
#### Hemoglobin
Summary:
```{r}
summary(hb)
```
Distribution of hemoglobin was assessed and follows a normal distribution. Two participants don't have a hemoglobin value.
## Relationships between independent variables
### BMI and SpO2
```{r}
plot(spo2_VPO~BMI,
main="Scatterplot",
xlab="Body mass index (kg/m²)",
ylab="SpO2 (%)"
)
```
Relationship does not seem to be linear (also, variables were not normally distributed, with outliers), but suggests a negative correlation. Will assess if a smooth BMI term explains SpO2 better, and if so, what is the best number of knots to model this relationship:
Models evaluated with the accompanying sourced script ***nonlinear_BMI_SpO2.R***
```{r}
#| include: false
source("scripts/nonlinear_BMI_SpO2.R", local = knitr::knit_global())
```
All non-linear models are significantly better than linear. Thus, using a smooth term for BMI is better than modelling a linear relationship.
Best AIC:
```{r}
#| echo: true
list(AIC_k2,AIC_k4,AIC_k6,AIC_k8,AIC_k12)
```
Regarding AIC, the models with k\>6 are not better at explaining the variance. Thus, I will with k=5 since the best model is expected to be anywhere between k=4 and k=6:
```{r}
#| echo: true
list(AIC_k4,AIC_k5,AIC_k6)
```
Model with k=5 still offers and advantage compared to k=4 (drop in AIC). No other improvements in k-index or visual representation are achieved with higher k. Thus, will use k=5 to model.
```{r}
fig1b
```
Negative non-monotonic relationship since SpO2 decreases, but then seems to increase slightly again at BMI 40, followed by a marked decrease as BMI decreases at values higher than \~42.
Spearman's correlation coefficient shouldn't be used due to relationship not being monotonically decreasing. However, I will calculate it just to have a rough idea (but will not report this in the paper).
```{r}
spearman <- cor.test(spo2_VPO, BMI,
method="spearman",
exact=FALSE
)
spearman
```
> BMI exhibited a negative non-linear monotonic relationship with SpO2 (**Figure 1B**, rho= `r round(spearman$estimate,3)`, p\<0.001).
```{r}
#| include: false
rm(AIC_k2,AIC_k4,AIC_k5,AIC_k6,AIC_k8,AIC_k12,model,spearman,fig1b)
```
### BMI and age
```{r}
plot(age~BMI,
main="Scatterplot",
ylab="Age (years)",
xlab="Body mass index (kg/m²)"
)
```
Datapoints scattered. Relationship monotonic and probably linear, but there are influential true outliers with extreme BMI. Will assess with Spearman correlation analysis due to extreme BMI values.
```{r}
spearman <- cor.test(age,BMI,
method="spearman",
exact=FALSE
)
spearman
```
> Age had a weak negative correlation with BMI (rho= `r round(spearman$estimate,3)`, p=`r round(spearman$p.value,3)`).
```{r}
#| include: false
rm(spearman)
```
### BMI and sex
Median BMI:
```{r}
data_BMI <- data %>% group_by(sex)
median_bmi <- data_BMI %>%
summarize(n = n(),
median = median(BMI),
Q1 = quantile(BMI,0.25),
Q3 = quantile(BMI,0.75),
min = min(BMI),
max = max(BMI)
)
median_bmi
```
```{r}
boxplot(BMI ~ sex,
ylab="Body mass index (kg/m²)",
xlab="Sex"
)
```
Distribution not normal and influential outliers. Will assess non-parametrically.
```{r}
wil <- wilcox.test(BMI ~ sex,
data = data_BMI,
exact = FALSE
)
wil
```
> The median BMI was not different between men (`r round(median_bmi$median[2],1)`, IQR: `r round(median_bmi$Q1[2],1)`-`r round(median_bmi$Q3[2],1)`) and women (`r round(median_bmi$median[1],1)`, IQR: `r round(median_bmi$Q1[1],1)`-`r round(median_bmi$Q3[1],1)`) (p=`r round(wil$p.value,3)`).
```{r}
#| include: false
rm(data_BMI,median_bmi,wil)
```
### BMI and sleep apnea
```{r}
boxplot(BMI ~ sleep_apnea,
ylab="Body mass index (kg/m²)",
xlab="Obstructive sleep apnea"
)
```
Distribution not normal and influential outliers. Will assess non-parametrically.
```{r}
data_BMI <- data %>% group_by(sleep_apnea)
median_bmi <- data_BMI %>%
summarize(n = n(),
median = median(BMI),
Q1 = quantile(BMI,0.25),
Q3 = quantile(BMI,0.75),
min = min(BMI),
max = max(BMI)
)
median_bmi
```
```{r}
wil <- wilcox.test(BMI ~ sleep_apnea,
data = data_BMI,
exact = FALSE
)
wil
```
> The median BMI was significantly higher in participants with sleep apnea (`r round(median_bmi$median[2],1)`, IQR: `r round(median_bmi$Q1[2],1)`-`r round(median_bmi$Q3[2],1)`) compared to those without OSA (`r round(median_bmi$median[1],1)`, IQR: `r round(median_bmi$Q1[1],1)`-`r round(median_bmi$Q3[1],1)`) (p=`r round(wil$p.value,3)`).
```{r}
#| include: false
rm(data_BMI,median_bmi,wil)
```
### BMI and asthma
```{r}
boxplot(BMI ~ asthma,
ylab="Body mass index (kg/m²)",
xlab="Asthma"
)
```
Distribution not normal and influential outliers. Will assess non-parametrically.
```{r}
data_BMI <- data %>% group_by(asthma)
median_bmi <- data_BMI %>%
summarize(n = n(),
median = median(BMI),
Q1 = quantile(BMI,0.25),
Q3 = quantile(BMI,0.75),
min = min(BMI),
max = max(BMI)
)
median_bmi
```
```{r}
wil <- wilcox.test(BMI ~ asthma,
data = data_BMI,
exact = FALSE
)
wil
```
> The median BMI was not significantly different in patients with asthma (`r round(median_bmi$median[2],1)`, IQR: `r round(median_bmi$Q1[2],1)`-`r round(median_bmi$Q3[2],1)`) compared to those without (`r round(median_bmi$median[1],1)`, IQR: `r round(median_bmi$Q1[1],1)`-`r round(median_bmi$Q3[1],1)`) (p=`r round(wil$p.value,3)`).
```{r}
#| include: false
rm(data_BMI,median_bmi,wil)
```
### BMI and COPD
```{r}
boxplot(BMI ~ COPD,
ylab="Body mass index (kg/m²)",
xlab="Chronic obstructive pulmonary disease"
)
```
Distribution not normal and influential outliers. Will assess non-parametrically.
```{r}
data_BMI <- data %>% group_by(COPD)
median_bmi <- data_BMI %>%
summarize(n = n(),
median = median(BMI),
Q1 = quantile(BMI,0.25),
Q3 = quantile(BMI,0.75),
min = min(BMI),
max = max(BMI)
)
median_bmi
```
```{r}
wil <- wilcox.test(BMI ~ COPD,
data = data_BMI,
exact = FALSE
)
wil
```
> The median BMI was significantly higher in participants with COPD (`r round(median_bmi$median[2],1)`, IQR: `r round(median_bmi$Q1[2],1)`-`r round(median_bmi$Q3[2],1)`) than those without COPD (`r round(median_bmi$median[1],1)`, IQR: `r round(median_bmi$Q1[1],1)`-`r round(median_bmi$Q3[1],1)`) (p=`r round(wil$p.value,3)`).
```{r}
#| include: false
rm(data_BMI,median_bmi,wil)
```
### BMI and oxygen use
```{r}
boxplot(BMI ~ oxygen_use,
ylab="Body mass index (kg/m²)",
xlab="Supplementary oxygen use at home"
)
```
Distribution not normal and influential outliers. Will assess non-parametrically.
```{r}
data_BMI <- data %>% group_by(oxygen_use)
median_bmi <- data_BMI %>%
summarize(n = n(),
median = median(BMI),
Q1 = quantile(BMI,0.25),
Q3 = quantile(BMI,0.75),
min = min(BMI),
max = max(BMI)
)
median_bmi
```
```{r}
wil <- wilcox.test(BMI ~ oxygen_use,
data = data_BMI,
exact = FALSE
)
wil
```
> The median BMI was significantly higher in patients who reported oxygen use at home (`r round(median_bmi$median[2],1)`, IQR: `r round(median_bmi$Q1[2],1)`-`r round(median_bmi$Q3[2],1)`) compared to those with no supplementary oxygen use (`r round(median_bmi$median[1],1)`, IQR: `r round(median_bmi$Q1[1],1)`-`r round(median_bmi$Q3[1],1)`) (p\<0.001).
```{r}
#| include: false
rm(data_BMI,median_bmi,wil)
```
### BMI and CPAP use
```{r}
boxplot(BMI ~ CPAP_use,
ylab="Body mass index (kg/m²)",
xlab="Continuous positive airway pressure (CPAP)"
)
```
Distribution not normal and influential outliers. Will assess non-parametrically.
```{r}
data_BMI <- data %>% group_by(CPAP_use)
median_bmi <- data_BMI %>%
summarize(n = n(),
median = median(BMI),
Q1 = quantile(BMI,0.25),
Q3 = quantile(BMI,0.75),
min = min(BMI),
max = max(BMI)
)
median_bmi
```
```{r}
wil <- wilcox.test(BMI ~ CPAP_use,
data = data_BMI,
exact = FALSE
)
wil
```
> The median BMI was significantly higher in participants with CPAP use at home (`r round(median_bmi$median[2],1)`, IQR: `r round(median_bmi$Q1[2],1)`-`r round(median_bmi$Q3[2],1)`) compared to those who did not report CPAP use (`r round(median_bmi$median[1],1)`, IQR: `r round(median_bmi$Q1[1],1)`-`r round(median_bmi$Q3[1],1)`) (p\<0.001).
```{r}
#| include: false
rm(data_BMI,median_bmi,wil)
```
### Age and SpO2
```{r}
plot(spo2_VPO~age,
main="Scatterplot",
xlab="Age (years)",
ylab="SpO2 (%)"
)
```
Do not seem to be correlated. Will apply Spearman's correlation test:
```{r}
spearman <- cor.test(spo2_VPO,age,
method="spearman",
exact=FALSE
)
spearman
```
> Age and SpO2 were not correlated (rho= `r round(spearman$estimate,3)`, p=`r round(spearman$p.value,3)`).
```{r}
#| include: false
rm(spearman)
```
### Age and sex
```{r}
boxplot(age~sex,
ylab="Age (years)",
xlab="Sex"
)
```
```{r}
data_age <- data %>% group_by(sex)
```
```{r}
#| include: false
## Change 'false' for 'true' above to show plot.
ggplot(data_age,aes(x = age)) +
geom_histogram(fill = "firebrick3", colour = "black") +
facet_grid(sex ~ .)
```
```{r}
#| include: false
## Change 'false' for 'true' above to show plot.
qqPlot(age ~ sex, data=data_age)
```
Distribution near-normal, but light tails for women. However, t-test could be robust to deviations from normality and differences in group size. Will assess mean and variance for further testing:
```{r}
mean_age <- data_age %>%
summarise(n=n(),
age_mean = mean(age),
sd = sd(age),
variance = var(age)
)
mean_age
```
Variances are similar. However, group sizes differ my 10x. Welch's t-test more suitable:
```{r}
t_test <- t.test(age ~ sex, data = data_age)
t_test
```
> Mean age was similar bethween men (`r round(mean_age$age_mean[2],1)`, sd:`r round(mean_age$sd[2],1)`) and women (`r round(mean_age$age_mean[1],1)`, sd:`r round(mean_age$sd[1],1)`) (p=`r round(t_test$p.value,3)`).
```{r}
#| include: false
rm(data_age,mean_age,t_test)
```
### Age and sleep apnea
```{r}
#| include: false
## Change 'false' for 'true' above to show plot.
data_age <- data %>% group_by(sleep_apnea)
ggplot(data_age, aes(x = age, fill=sleep_apnea)) +
geom_histogram(position = "identity", alpha = 0.4)
```
```{r}
#| include: false
## Change 'false' for 'true' above to show plot.
qqPlot(age ~ sleep_apnea)
```
Distribution near-normal. Will assess mean and variance for further testing.
```{r}
mean_age <- data_age %>%
summarise(n=n(),
age_mean = mean(age),
sd = sd(age),
variance = var(age)
)
mean_age
```
Size per group very different, variances do not look similar. Welch's t-test more suitable:
```{r}
t_test <- t.test(age ~ sleep_apnea, data = data_age)
t_test
```
> Age was not significantly different between participants with OSA (`r round(mean_age$age_mean[2],1)`, sd:`r round(mean_age$sd[2],1)`) and those without (`r round(mean_age$age_mean[1],1)`, sd:`r round(mean_age$sd[1],1)`) (p=`r round(t_test$p.value,3)`).
```{r}
#| include: false
rm(data_age,mean_age,t_test)
```
### Age and asthma
```{r}
#| include: false
## Change 'false' for 'true' above to show plot.
data_age <- data %>% group_by(asthma)
ggplot(data_age, aes(x = age, fill=asthma)) +
geom_histogram(position = "identity", alpha = 0.4)
```
```{r}
#| include: false
## Change 'false' for 'true' above to show plot.
qqPlot(age ~ asthma)
```
Distribution normal. Will assess mean and variance for further testing.
```{r}
mean_age <- data_age %>%
summarise(n=n(),
age_mean = mean(age),
sd = sd(age),
variance = var(age)
)
mean_age
```
Size per group very different, variances look similar. Welch's t-test more suitable due to differring group size:
```{r}
t_test <- t.test(age ~ asthma, data = data_age)
t_test
```
> Age was not significantly different between participants with asthma (`r round(mean_age$age_mean[2],1)`, sd:`r round(mean_age$sd[2],1)`) and those without (`r round(mean_age$age_mean[1],1)`, sd:`r round(mean_age$sd[1],1)`) (p=`r round(t_test$p.value,3)`).
```{r}
#| include: false
rm(data_age,mean_age,t_test)
```
### Age and COPD
```{r}
#| include: false
## Change 'false' for 'true' above to show plot.
data_age <- data %>% group_by(COPD)
ggplot(data_age, aes(x = age, fill=COPD)) +
geom_histogram(position = "identity", alpha = 0.4)
```
```{r}
#| include: false
## Change 'false' for 'true' above to show plot.
qqPlot(age ~ COPD)
```