README.Rmd 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. ---
  2. title: "Working with model objects"
  3. output: github_document
  4. ---
  5. ## Install
  6. - Download and install R (and Rstudio).
  7. - Go to R console or open scripts/README.Rmd in RStudio.
  8. - Install these packages (this needs to be done once).
  9. ```{r}
  10. if(!require(brms)){
  11. install.packages(c("brms", "here"))
  12. library(brms)
  13. library(here)
  14. }
  15. ```
  16. ## Run
  17. In R console OR in .Rmd file:
  18. - Load packages to R environment.
  19. ```{r, message=FALSE}
  20. library(brms)
  21. library(here)
  22. ```
  23. - Load the model object and print model summary.
  24. ```{r}
  25. m <- readRDS(here("models/anticons_detool.rds"))
  26. print(m)
  27. ```
  28. - Get fitted coefficients with 95% credible intervals.
  29. ```{r}
  30. posterior_summary(m)
  31. ```
  32. - Get the full posterior.
  33. ```{r}
  34. post <- posterior_samples(m)
  35. head(post)
  36. ```
  37. - What is the estimated difference in the proportion of anti-conservative p value histograms between DESeq2 and EdgeR?
  38. ```{r}
  39. posterior_deseq_edger <- (inv_logit_scaled(post$b_de_tooldeseq - post$b_de_tooledger))
  40. hist(posterior_deseq_edger, breaks = 40)
  41. ```
  42. - The posterior summary for the effect size.
  43. ```{r}
  44. posterior_summary(posterior_deseq_edger)
  45. ```
  46. ```{r, echo=FALSE}
  47. ps <- posterior_summary(posterior_deseq_edger)
  48. ```
  49. The estimated effect size is somewhere between `r paste(scales::percent(ps[1,3:4]), collapse = " and ")`.
  50. - Get data from model object.
  51. ```{r}
  52. data <- m$data
  53. head(data)
  54. ```
  55. - Extract stan code from model object. This is the fullest model description.
  56. ```{r}
  57. stancode(m)
  58. ```