-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharticletwo-sensitivityanalysis.Rmd
218 lines (169 loc) · 7.15 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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
---
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)
```
```{r load old, eval = FALSE}
load("session/session-sensitivity.Rdata")
```
### 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_species_all_drop50k_2018-12-21.RDs")
bray.dist.m.species <- readRDS("rds/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
Self reported BP medication
```{r bp medication use}
pseq.species %>% meta %>% pull(BP_TREAT) %>% as.factor %>% summary %>% kable
```
```{r sensitivity analysis bp treat}
adonis.species.bptreat <- calculate.betadiversity(pseq = pseq.species,
matrix = bray.dist.m.species,
vars = list("max" = var.CL.opt,
"min" = var.CL.min))
diversity.bptreat <- diversities(pseq = pseq.species,
vars = list("max" = var.CL.opt, "min" = var.CL.min),
betadiversity = adonis.species.bptreat,
names.dset = names.dset)
g.diversity.bptreat <- plot.diversities(diversity.bptreat)
ggsave(file = "cache/sensitivity-alphabeta-bptreat.png", plot = g.diversity.bptreat, height = 6, width = 9)
```
<img src="cache/sensitivity-alphabeta-bptreat.png"/>
Excluding participants with diabtes, CAD, and any cancer
```{r only healthy}
pseq.species %>% meta %>%
filter(PREVAL_DIAB == 1 | PREVAL_CHD == 1 | PREVAL_CR_ANYCANC == 1) %>%
summarize(diab = sum(PREVAL_DIAB == 1),
chd = sum(PREVAL_CHD == 1),
canc = sum(PREVAL_CR_ANYCANC == 1),
any = n()) %>%
kable
```
```{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]
adonis.species.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))
diversity.healthy <- diversities(pseq = pseq.species,
vars = list("max" = var.CL[var.CL != "PREVAL_DIAB"],
"min" = var.CL.min),
betadiversity = adonis.species.healthy,
names.dset = names.dset)
g.diversity.healthy <- plot.diversities(diversity.healthy)
ggsave(file = "cache/sensitivity-alphabeta-healthy.png", plot = g.diversity.healthy, height = 6, width = 9)
```
<img src="cache/sensitivity-alphabeta-healthy.png"/>
## 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]
adonis.species.normalweight <- calculate.betadiversity(pseq = pseq.species.normalweight,
matrix = bray.dist.m.species.normalweight,
vars = list("max" = var.CL[var.CL != "PREVAL_DIAB"],
"min" = var.CL.min))
diversity.normalweight <- diversities(pseq = pseq.species,
vars = list("max" = var.CL[var.CL != "PREVAL_DIAB"],
"min" = var.CL.min),
betadiversity = adonis.species.normalweight,
names.dset = names.dset)
g.diversity.normalweight <- plot.diversities(diversity.normalweight)
ggsave(file = "cache/sensitivity-alphabeta-normalweight.png",
plot = g.diversity.normalweight, height = 6, width = 9)
```
<img src="cache/sensitivity-alphabeta-normalweight.png"/>
```{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]
adonis.species.obese <- calculate.betadiversity(pseq = pseq.species.obese,
matrix = bray.dist.m.species.obese,
vars = list("max" = var.CL[var.CL != "PREVAL_DIAB"],
"min" = var.CL.min))
diversity.obese <- diversities(pseq = pseq.species,
vars = list("max" = var.CL[var.CL != "PREVAL_DIAB"],
"min" = var.CL.min),
betadiversity = adonis.species.obese,
names.dset = names.dset)
g.diversity.obese <- plot.diversities(diversity.obese)
ggsave(file = "cache/sensitivity-alphabeta-obese.png", plot = g.diversity.obese, height = 6, width = 9)
```
<img src="cache/sensitivity-alphabeta-obese.png"/>
```{r save session}
save.image(file = "session/session-sensitivity.Rdata")
```