README.Rmd 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. ---
  2. title: "Working with model objects"
  3. output: github_document
  4. ---
  5. ## Install
  6. <<<<<<< HEAD
  7. - Download and install R [https://www.r-project.org](https://www.r-project.org) (and RStudio [https://www.rstudio.com/products/rstudio/](https://www.rstudio.com/products/rstudio/)).
  8. =======
  9. - Download and install R (and Rstudio).
  10. >>>>>>> 6416228e39f1b6de21e374074ffdd2ecf62b9007
  11. - Go to R console or open scripts/README.Rmd in RStudio.
  12. - Install these packages (this needs to be done once).
  13. ```{r}
  14. if(!require(brms)){
  15. install.packages(c("brms", "here"))
  16. library(brms)
  17. library(here)
  18. }
  19. ```
  20. ## Run
  21. In R console OR in .Rmd file:
  22. - Load packages to R environment.
  23. ```{r, message=FALSE}
  24. library(brms)
  25. library(here)
  26. ```
  27. - Load the model object and print model summary.
  28. ```{r}
  29. m <- readRDS(here("models/anticons_detool.rds"))
  30. print(m)
  31. ```
  32. - Get fitted coefficients with 95% credible intervals.
  33. ```{r}
  34. posterior_summary(m)
  35. ```
  36. - Get the full posterior.
  37. ```{r}
  38. post <- posterior_samples(m)
  39. head(post)
  40. ```
  41. - What is the estimated difference in the proportion of anti-conservative p value histograms between DESeq2 and EdgeR?
  42. <<<<<<< HEAD
  43. ```{r, eval=FALSE}
  44. posterior_deseq_edger <- inv_logit_scaled(post$b_de_tooldeseq - post$b_de_tooledger)
  45. hist(posterior_deseq_edger, breaks = 40)
  46. ```
  47. ```{r, echo=FALSE, message=FALSE}
  48. posterior_deseq_edger <- inv_logit_scaled(post$b_de_tooldeseq - post$b_de_tooledger)
  49. png(here("plots/posterior.png"))
  50. hist(posterior_deseq_edger, breaks = 40)
  51. invisible(dev.off())
  52. ```
  53. ![](plots/posterior.png)
  54. =======
  55. ```{r}
  56. posterior_deseq_edger <- (inv_logit_scaled(post$b_de_tooldeseq - post$b_de_tooledger))
  57. hist(posterior_deseq_edger, breaks = 40)
  58. ```
  59. >>>>>>> 6416228e39f1b6de21e374074ffdd2ecf62b9007
  60. - The posterior summary for the effect size.
  61. ```{r}
  62. posterior_summary(posterior_deseq_edger)
  63. ```
  64. ```{r, echo=FALSE}
  65. ps <- posterior_summary(posterior_deseq_edger)
  66. <<<<<<< HEAD
  67. =======
  68. >>>>>>> 6416228e39f1b6de21e374074ffdd2ecf62b9007
  69. ```
  70. The estimated effect size is somewhere between `r paste(scales::percent(ps[1,3:4]), collapse = " and ")`.
  71. - Get data from model object.
  72. ```{r}
  73. data <- m$data
  74. head(data)
  75. ```
  76. - Extract stan code from model object. This is the fullest model description.
  77. ```{r}
  78. stancode(m)
  79. ```
  80. <<<<<<< HEAD
  81. ## This document
  82. This README.md was generated by running:
  83. ```{r, eval=FALSE}
  84. rmarkdown::render("scripts/README.Rmd", output_file = here::here("README.md"))
  85. ```
  86. =======
  87. >>>>>>> 6416228e39f1b6de21e374074ffdd2ecf62b9007