-
Notifications
You must be signed in to change notification settings - Fork 0
/
articletwo-sensitivityanalysis.Rmd
202 lines (155 loc) · 6.83 KB
/
articletwo-sensitivityanalysis.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
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
---
title: "Hypertension and microbiome"
author: "Joonatan Palmu"
date: "`r format(Sys.time(), '%d.%m.%Y')`"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(include = TRUE, xecho = TRUE, message = FALSE, results='asis',
cache=FALSE, warning=FALSE)
knitr::opts_chunk$set(cache.path = 'cache/', output.dir="cache/",
file.path = 'cache/', fig.path = 'cache/')
options(max.print=100)
```
# Importing libraries:
```{r libraries, cache = FALSE}
library(dplyr)
library(tibble)
library(phyloseq)
library(nortest)
library(microbiome)
library(knitr)
library(tidyr)
library(vegan)
library(reshape)
library(parallel)
library(officer)
library(flextable)
library(xtable)
library(rvg)
library(tableone)
library(scales)
library(ggplot2)
library(gridExtra)
library(png)
library(pander)
library(ggpubr)
library(broom)
library(ggfortify)
library(RColorBrewer)
library(gvlma)
library(purrr)
library(pwr)
library(gtable)
library(car)
library(M3C)
library(emmeans)
```
### RR biome functions
<details>
<summary>Open/Close</summary>
```{r RR biome functions, code=readLines("articletwo-rrbiome.R")}
source("articletwo-rrbiome.R")
```
</details>
### Plot functions
<details>
<summary>Open/Close</summary>
```{r Plot functions, code=readLines("articletwo-ggplot.R")}
source("articletwo-ggplot.R")
```
</details>
# Import previous session
```{r Import previous session}
pseq.species <- import_filter_data("data/phfinrisk_centrifuge_species_all_drop50k_2018-11-30_2019-06-03.RDs")
bray.dist.m.species <- readRDS("rds-20190828/bray.dist.m.species.rds")
names.dset <- getdescriptions()
```
## Variables
```{r my variables}
var.BP <- c("MAP", "SYSTM", "DIASM", "PULSEPRESSURE", "HYPERTENSION")
var.CL.min <- c("BL_AGE", "SEX")
var.CL <- c("BL_AGE", "SEX", "BMI", "CURR_SMOKE", "Q57X", "PREVAL_DIAB",
"BL_USE_RX_C03","BL_USE_RX_C07", "BL_USE_RX_C08", "BL_USE_RX_C09")
var.CL.opt <- c("BL_AGE", "SEX", "BMI", "CURR_SMOKE", "Q57X", "PREVAL_DIAB", "BP_TREAT")
permutations <- 99
```
# Sensitivity analysis
```{r sensitivity analysis bp treat}
alphadiversity.askbp <- calculate.alphadiversity(pseq.species,
list("max" = var.CL.opt,
"min" = var.CL.min))
betadiversity.askbp <- calculate.betadiversity(pseq = pseq.species,
matrix = bray.dist.m.species,
vars = list("max" = var.CL.opt,
"min" = var.CL.min),
npermutations = permutations)
diversities.askbp <- mergediversities(alphadiversity.askbp,
betadiversity.askbp,
names.dset = names.dset)
grid.arrange(plot.diversities(diversities.askbp))
```
Subjects with diabetes, cancer, and coronary disease are dropped. No
easy variable was found for kidney disesase.
```{r sensitivity analysis only healthy}
pseq.species.healthy <- subset_samples(pseq.species,
PREVAL_DIAB == 0 &
PREVAL_CHD == 0 &
PREVAL_CR_ANYCANC == 0)
bray.dist.m.species.healthy <- bray.dist.m.species[pseq.species.healthy %>% meta %>% rownames,
pseq.species.healthy %>% meta %>% rownames]
alphadiversity.healthy <- calculate.alphadiversity(pseq.species.healthy,
list("max" = var.CL[var.CL != "PREVAL_DIAB"],
"min" = var.CL.min))
betadiversity.healthy <- calculate.betadiversity(pseq = pseq.species.healthy,
matrix = bray.dist.m.species.healthy,
vars = list("max" = var.CL[var.CL != "PREVAL_DIAB"],
"min" = var.CL.min),
npermutations = permutations)
diversities.healthy <- mergediversities(alphadiversity.healthy,
betadiversity.healthy,
names.dset = names.dset)
grid.arrange(plot.diversities(diversities.healthy))
```
## BMI
Normal weigth
```{r sensitivity analysis normal weight}
pseq.species.normalweight <- subset_samples(pseq.species, BMI > 18.5 & BMI <= 25)
bray.dist.m.species.normalweight <-
bray.dist.m.species[pseq.species.normalweight %>% meta %>% rownames,
pseq.species.normalweight %>% meta %>% rownames]
alphadiversity.normalweight <- calculate.alphadiversity(pseq.species.normalweight,
list("max" = var.CL[var.CL != "BMI"],
"min" = var.CL.min))
betadiversity.normalweight <- calculate.betadiversity(pseq = pseq.species.normalweight,
matrix = bray.dist.m.species.normalweight,
vars = list("max" = var.CL[var.CL != "BMI"],
"min" = var.CL.min),
npermutations = permutations)
diversities.normalweight <- mergediversities(alphadiversity.normalweight,
betadiversity.normalweight,
names.dset = names.dset)
grid.arrange(plot.diversities(diversities.normalweight))
```
Obese
```{r sensitivity analysis obese}
pseq.species.obese <- subset_samples(pseq.species, BMI > 30 & BMI <= 40)
bray.dist.m.species.obese <-
bray.dist.m.species[pseq.species.obese %>% meta %>% rownames,
pseq.species.obese %>% meta %>% rownames]
alphadiversity.obese <- calculate.alphadiversity(pseq.species.obese,
list("max" = var.CL[var.CL != "BMI"],
"min" = var.CL.min))
betadiversity.obese <- calculate.betadiversity(pseq = pseq.species.obese,
matrix = bray.dist.m.species.obese,
vars = list("max" = var.CL[var.CL != "BMI"],
"min" = var.CL.min),
npermutations = permutations)
diversities.obese <- mergediversities(alphadiversity.obese,
betadiversity.obese,
names.dset = names.dset)
grid.arrange(plot.diversities(diversities.obese))
```
```{r save session}
save.image(file = "session/session-sensitivity.Rdata")
```