Newer
Older
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
---
title: "TPH2 KO statistics"
output: github_document
author: "Alex Meng, Joanes Grandjean"
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE, eval=FALSE,warning = FALSE,message=FALSE)
```
# Setup environement
Download DABEST
```{r setup env}
# you just need to run these once.
install.packages('devtools')
devtools::install_github("ACCLAB/dabestr")
devtools::install_github("karthik/wesanderson")
```
# Load pacakges
```{r load env}
library(tidyverse)
library(glue)
library(dabestr)
library(wesanderson) # see https://github.com/karthik/wesanderson
pal <- wes_palette("Darjeeling1")
```
# demo dabest in R
```{r demo dabest}
#load the table. for other cases, it might help to keep naming consistent between tables, see example. Also, avoid spaces or weird characters in table names.
df <- read_csv('assets/tables/testname_measure.csv', col_types = cols()) %>% melt() %>% rename(group = variable) %>% drop_na()
# estimate the p-values using non-parametric test
p_tmp<- c(wilcox.test(df$value[df$group == 'Tph2+/+'], df$value[df$group == 'Tph2+/-'])$p.value, wilcox.test(df$value[df$group == 'Tph2+/+'], df$value[df$group == 'Tph2-/-'])$p.value)
# estimate hedges'g
dabest_hedges <- dabest(df, group, value, idx = c('Tph2+/+','Tph2+/-','Tph2-/-'), paired = FALSE) %>% hedges_g()
#make the plot and save to file
test1a<-plot(dabest_hedges, palette = pal)
ggsave('assets/figure/fig_test1.svg', plot = test1a, device = 'svg',dpi = 300)
#outputs the file to show in the doc.
test1a
#outputs table with added p-values for good measure
dabest_hedges$result %>% mutate(p = p_tmp)
```
# what happens if dabest bugs?
```{r demo dabest debug}
#load the table. for other cases, it might help to keep naming consistent between tables, see example. Also, avoid spaces or weird characters in table names.
df <- read_csv('assets/tables/testname_measure.csv', col_types = cols()) %>% melt() %>% rename(group = variable) %>% drop_na()
dabest_hedges <- dabest(df, group, value, idx = c('Tph2+/+','Tph2+/-'), paired = FALSE) %>% hedges_g()
#figure will require post-pocessing to make do.
plot(dabest_hedges, palette = pal)
dabest_hedges <- dabest(df, group, value, idx = c('Tph2+/+','Tph2-/-'), paired = FALSE) %>% hedges_g()
#figure will require post-pocessing to make do.
plot(dabest_hedges, palette = pal)
```
Finally, you can consider https://rpkgs.datanovia.com/ggpubr/reference/ggarrange.html to make composite figures in R. Happy to help you get started.