Skip to content
Snippets Groups Projects
README.Rmd 2.46 KiB
Newer Older
---
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.