-
Notifications
You must be signed in to change notification settings - Fork 0
/
topONE.Rmd
461 lines (311 loc) · 14.6 KB
/
topONE.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
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
---
title: "topONE"
author: "Claire"
date: "2024-08-15"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
# tinytex::install_tinytex()
```
## Setup
```{r}
library(dplyr)
library(car)
library(FSA)
```
```{r}
df <- read.csv("Documents/PGC Bioinfo Training/Viral Recombination/Topo ARG/country_homologies.csv")
attach(df); View(df)
```
We take manual setting of data frames per country.
```{r}
ph_df <- df %>%
filter(country_code == 'PH', homology == 1) %>%
select(gene_type, b_time, d_time)
cn_df <- df %>%
filter(country_code == 'CN', homology == 1) %>%
select(gene_type, b_time, d_time)
sg_df <- df %>%
filter(country_code == 'SG', homology == 1) %>%
select(gene_type, b_time, d_time)
sk_df <- df %>%
filter(country_code == 'SK', homology == 1) %>%
select(gene_type, b_time, d_time)
us_df <- df %>%
filter(country_code == 'US', homology == 1) %>%
select(gene_type, b_time, d_time)
```
Try input them into one list for brevity
```{r}
country_dfs <- list()
country_dfs[['PH']] <- ph_df
country_dfs[['CN']] <- cn_df
country_dfs[['SG']] <- sg_df
country_dfs[['SK']] <- sk_df
country_dfs[['US']] <- us_df
```
# Philippines
## Births
Test assumptions on the anova model
```{r}
model_ph_births <- aov(b_time ~ gene_type, ph_df)
# homogeneity of variance
leveneTest(model_ph_births) #pval>0.05 --> homoscedastic
# normality of residuals
resid_ph <- residuals(model_ph_births)
shapiro.test(resid_ph) #p-val<0.05 i.e., not normal
```
- For the test on homogeneity of variance, at \$p\$-val \$=0.3381 \> 0.05\$, we fail to reject the null hypothesis, i.e. the model is homoscedastic.
- With a Shapiro-Wilk normality test, at p-val \< 0.05, we reject the null hypothesis, i.e., the residuals are not normally distributed.
Since the assumptions are not satisfied, we proceed with a nonparametric Kruskal-Wallis test.
```{r}
# ... Assumptions failed, nonparametric: Kruskal-Wallis
kruskal.test(b_time ~ gene_type, ph_df)
# p-val = 0.0489 < 0.05 --> there is a significant difference in birth times between gene types
# post-hoc
dunnTest(b_time ~ gene_type, data=ph_df, method="bonferroni")
#__ all three time pairs are significantly different
```
The Kruskal-Wallis test returns a p-value = 0.0489 \< 0.05 so we reject the null hypothesis. That is, there is a significant difference in birth times between the three gene types. Post-hoc analysis shows the following:
- Mixed vs Nonrecombinant —\> significant
- Mixed vs Recombinant —\> not significant
- Non-recombinant vs Recombinant —\> not significant
\*Graphs\*
```{r}
order1 <- c("recombinant", "nonrecombinant", "mixed")
genetype <- factor(gene_type, levels=order1)
boxplot(b_time~gene_type, data=ph_df, ylab="Birth Times", main="Birth Times of SARS-CoV-2 in the PH across different Gene Types", xlab="Gene Type")
```
## Deaths
Test assumptions on the anova model
```{r}
model_ph_deaths <- aov(d_time ~ gene_type, ph_df)
# homogeneity of variance
leveneTest(model_ph_deaths) #pval>0.05 --> homoscedastic
# normality of residuals
resid_ph2 <- residuals(model_ph_deaths)
shapiro.test(resid_ph2) #p-val<0.05 i.e., not normal
```
- For the test on homogeneity of variance, at \$p\$-val \$=0.5452 \> 0.05\$, we fail to reject the null hypothesis, i.e. the model is homoscedastic.
- With a Shapiro-Wilk normality test, at p-val \< 0.05, we reject the null hypothesis, i.e., the residuals are not normally distributed.
Since the assumptions are not satisfied, we proceed with a nonparametric Kruskal-Wallis test.
```{r}
# ... Assumptions failed, nonparametric: Kruskal-Wallis
kruskal.test(d_time ~ gene_type, ph_df)
# p-val = 0.0489 < 0.05 --> there is a significant difference in birth times between gene types
# post-hoc
dunnTest(d_time ~ gene_type, data=ph_df, method="bonferroni")
#__ all three time pairs are significantly different
```
The Kruskal-Wallis test returns a p-value = 0.1425 \> 0.05 so we fail to reject the null hypothesis. That is, there is no significant difference in birth times between the three gene types. Post-hoc analysis shows the following:
- Mixed vs Nonrecombinant —\> not significant
- Mixed vs Recombinant —\> not significant
- Non-recombinant vs Recombinant —\> not significant
\*Graphs\*
```{r}
order1 <- c("recombinant", "nonrecombinant", "mixed")
genetype <- factor(gene_type, levels=order1)
boxplot(d_time~gene_type, data=ph_df, ylab="Death Times", main="Birth Times of SARS-CoV-2 in the PH across different Gene Types", xlab="Gene Type")
```
##
# China
## Births
Test assumptions on the anova model
```{r}
model_cn_births <- aov(b_time ~ gene_type, cn_df)
# homogeneity of variance
leveneTest(model_cn_births) #pval>0.05 --> heteroscedastic
# normality of residuals
resid_cn <- residuals(model_cn_births)
shapiro.test(resid_cn) #p-val<0.05 i.e., not normal
```
- For the test on homogeneity of variance, at \$p\$-val \$ \> 0.05\$, we fail to reject the null hypothesis, i.e. the model is homoscedastic.
- With a Shapiro-Wilk normality test, at p-val \< 0.05, we reject the null hypothesis, i.e., the residuals are not normally distributed.
Since the assumptions are not satisfied, we proceed with a nonparametric Kruskal-Wallis test.
```{r}
# ... Assumptions failed, nonparametric: Kruskal-Wallis
kruskal.test(b_time ~ gene_type, cn_df)
# p-val = 1 > 0.05 --> there is no significant difference in birth times between gene types
# post-hoc
dunnTest(b_time ~ gene_type, data=cn_df, method="bonferroni")
#__ all three time pairs are significantly different
```
The Kruskal-Wallis test returns a p-value = 0.0489 \< 0.05 so we reject the null hypothesis. That is, there is a significant difference in birth times between the three gene types. Post-hoc analysis shows the following:
- Mixed vs Nonrecombinant —\> significant
\*Graphs\*
```{r}
order1 <- c("recombinant", "nonrecombinant", "mixed")
genetype <- factor(gene_type, levels=order1)
boxplot(b_time~gene_type, data=cn_df, ylab="Birth Times", main="Birth Times of SARS-CoV-2 in the CN across different Gene Types", xlab="Gene Type")
```
## Deaths
Test assumptions on the anova model
```{r}
model_cn_deaths <- aov(d_time ~ gene_type, cn_df)
# homogeneity of variance
leveneTest(model_cn_deaths) #pval>0.05 --> homoscedastic
# normality of residuals
resid_ph3<- residuals(model_cn_deaths)
shapiro.test(resid_ph3) #p-val<0.05 i.e., not normal
```
- For the test on homogeneity of variance, at \$p\$-val \$\> 0.05\$, we fail to reject the null hypothesis, i.e. the model is homoscedastic.
- With a Shapiro-Wilk normality test, at p-val \< 0.05, we reject the null hypothesis, i.e., the residuals are not normally distributed.
Since the assumptions are not satisfied, we proceed with a nonparametric Kruskal-Wallis test.
```{r}
# ... Assumptions failed, nonparametric: Kruskal-Wallis
kruskal.test(d_time ~ gene_type, cn_df)
# p-val = 0.0489 < 0.05 --> there is a significant difference in birth times between gene types
# post-hoc
dunnTest(d_time ~ gene_type, data=cn_df, method="bonferroni")
#__ all three time pairs are significantly different
```
The Kruskal-Wallis test returns a p-value = 0.1425 \> 0.05 so we fail to reject the null hypothesis. That is, there is no significant difference in deaths times between the three gene types. Post-hoc analysis shows the following:
- Mixed vs Nonrecombinant —\> not significant
\*Graphs\*
```{r}
order1 <- c("recombinant", "nonrecombinant", "mixed")
genetype <- factor(gene_type, levels=order1)
boxplot(d_time~gene_type, data=cn_df, ylab="Death Times", main="Birth Times of SARS-CoV-2 in the PH across different Gene Types", xlab="Gene Type")
```
# Singapore
## Births
Test assumptions on the anova model
```{r}
model_sg_births <- aov(b_time ~ gene_type, sg_df)
# homogeneity of variance
leveneTest(model_sg_births) #pval>0.05 --> heteroscedastic
# normality of residuals
resid_sg <- residuals(model_sg_births)
shapiro.test(resid_sg) #p-val<0.05 i.e., not normal
```
- For the test on homogeneity of variance, at \$p\$-val \$ \> 0.05\$, we fail to reject the null hypothesis, i.e. the model is homoscedastic.
- With a Shapiro-Wilk normality test, at p-val \< 0.05, we reject the null hypothesis, i.e., the residuals are not normally distributed.
Since the assumptions are not satisfied, we proceed with a nonparametric Kruskal-Wallis test.
```{r}
# ... Assumptions failed, nonparametric: Kruskal-Wallis
kruskal.test(b_time ~ gene_type, data = sg_df)
# p-val = 1 > 0.05 --> there is no significant difference in birth times between gene types
# post-hoc
dunnTest(b_time ~ gene_type, data=sg_df, method="bonferroni")
#__ all three time pairs are significantly different
```
The Kruskal-Wallis test returns a p-value = 1 \> 0.05 so we fail reject the null hypothesis. That is, there is no significant difference in birth times between the three gene types. Post-hoc analysis shows the following:
- Mixed vs Nonrecombinant —\> significant
\*Graphs\*
```{r}
order1 <- c("recombinant", "nonrecombinant", "mixed")
genetype <- factor(gene_type, levels=order1)
boxplot(b_time~gene_type, data=sg_df, ylab="Birth Times", main="Birth Times of SARS-CoV-2 in SG across different Gene Types", xlab="Gene Type")
```
## Deaths
Test assumptions on the anova model
```{r}
model_sg_deaths <- aov(d_time ~ gene_type, sg_df)
# homogeneity of variance
leveneTest(model_sg_deaths) #pval>0.05 --> homoscedastic
# normality of residuals
resid_sg<- residuals(model_sg_deaths)
shapiro.test(resid_sg) #p-val<0.05 i.e., not normal
```
- For the test on homogeneity of variance, at \$p\$-val \$\> 0.05\$, we fail to reject the null hypothesis, i.e. the model is homoscedastic.
- With a Shapiro-Wilk normality test, at p-val \< 0.05, we reject the null hypothesis, i.e., the residuals are not normally distributed.
Since the assumptions are not satisfied, we proceed with a nonparametric Kruskal-Wallis test.
```{r}
# ... Assumptions failed, nonparametric: Kruskal-Wallis
kruskal.test(d_time ~ gene_type, sg_df)
# p-val = 0.0489 < 0.05 --> there is a significant difference in birth times between gene types
# post-hoc
dunnTest(d_time ~ gene_type, data=sg_df, method="bonferroni")
#__ all three time pairs are significantly different
```
The Kruskal-Wallis test returns a p-value = 0.1425 \> 0.05 so we fail to reject the null hypothesis. That is, there is no significant difference in deaths times between the three gene types. Post-hoc analysis shows the following:
- Mixed vs Nonrecombinant —\> not significant
\*Graphs\*
```{r}
order1 <- c("recombinant", "nonrecombinant", "mixed")
genetype <- factor(gene_type, levels=order1)
boxplot(d_time~gene_type, data=sg_df, ylab="Death Times", main="Birth Times of SARS-CoV-2 in the SG across different Gene Types", xlab="Gene Type")
```
##
# South Korea
## Births
(Skipping the assumptions for brevity of file but all are failed)
```{r}
# ... Assumptions failed, nonparametric: Kruskal-Wallis
kruskal.test(b_time ~ gene_type, data = sk_df)
# p-val = 1 > 0.05 --> there is no significant difference in birth times between gene types
# post-hoc
dunnTest(b_time ~ gene_type, data=sk_df, method="bonferroni")
#__ all three time pairs are significantly different
```
The Kruskal-Wallis test returns a p-value = 0.0461 \< 0.05 so we reject the null hypothesis. That is, there is a significant difference in birth times between the three gene types. Post-hoc analysis shows the following:
- Mixed vs Nonrecombinant —\> not significant
- Mixed vs Recombinant —\> (not) significant
- Non-recombinant vs Recombinant —\> (not) significant
\*Graphs\*
```{r}
order1 <- c("recombinant", "nonrecombinant", "mixed")
genetype <- factor(gene_type, levels=order1)
boxplot(b_time~gene_type, data=sk_df, ylab="Death Times", main="Birth Times of SARS-CoV-2 in SK across different Gene Types", xlab="Gene Type")
```
## Deaths
(Skipping the assumptions for brevity of file but all are failed)
```{r}
# ... Assumptions failed, nonparametric: Kruskal-Wallis
kruskal.test(d_time ~ gene_type, data = sk_df)
# p-val = 1 > 0.05 --> there is no significant difference in birth times between gene types
# post-hoc
dunnTest(d_time ~ gene_type, data=sk_df, method="bonferroni")
#__ all three time pairs are significantly different
```
The Kruskal-Wallis test returns a p-value = 0.04732 \< 0.05 so we reject the null hypothesis. That is, there is a significant difference in birth times between the three gene types. Post-hoc analysis shows the following:
- Mixed vs Nonrecombinant —\> not significant
- Mixed vs Recombinant —\> (not) significant
- Non-recombinant vs Recombinant —\> (not) significant
\*Graphs\*
```{r}
order1 <- c("recombinant", "nonrecombinant", "mixed")
genetype <- factor(gene_type, levels=order1)
boxplot(d_time~gene_type, data=sk_df, ylab="Death Times", main="Death Times of SARS-CoV-2 in SK across different Gene Types", xlab="Gene Type")
```
##
# United States
## Births
(Skipping the assumptions for brevity of file but all are failed)
```{r}
# ... Assumptions failed, nonparametric: Kruskal-Wallis
kruskal.test(b_time ~ gene_type, data = us_df)
# p-val = 1 > 0.05 --> there is no significant difference in birth times between gene types
# post-hoc
dunnTest(b_time ~ gene_type, data=us_df, method="bonferroni")
#__ all three time pairs are significantly different
```
The Kruskal-Wallis test returns a p-value = 1\>0.05 so we fail to reject the null hypothesis. That is, there is no significant difference in birth times between the three gene types. Post-hoc analysis shows the following:
- Mixed vs Nonrecombinant —\> not significant
\*Graphs\*
```{r}
order1 <- c("recombinant", "nonrecombinant", "mixed")
genetype <- factor(gene_type, levels=order1)
boxplot(b_time~gene_type, data=us_df, ylab="Death Times", main="Birth Times of SARS-CoV-2 in the US across different Gene Types", xlab="Gene Type")
```
## Deaths
(Skipping the assumptions for brevity of file but all are failed)
```{r}
# ... Assumptions failed, nonparametric: Kruskal-Wallis
kruskal.test(d_time ~ gene_type, data = us_df)
# p-val = 1 > 0.05 --> there is no significant difference in birth times between gene types
# post-hoc
dunnTest(d_time ~ gene_type, data=us_df, method="bonferroni")
#__ all three time pairs are significantly different
```
The Kruskal-Wallis test returns a p-value = 1\> 0.05 so we fail to reject the null hypothesis. That is, there is no significant difference in birth times between the three gene types. Post-hoc analysis shows the following:
- Mixed vs Nonrecombinant —\> not significant
\*Graphs\*
```{r}
order1 <- c("recombinant", "nonrecombinant", "mixed")
genetype <- factor(gene_type, levels=order1)
boxplot(d_time~gene_type, data=us_df, ylab="Death Times", main="Death Times of SARS-CoV-2 in the US across different Gene Types", xlab="Gene Type")
```
##
#