-
Notifications
You must be signed in to change notification settings - Fork 10
/
Negativebinomial.Rmd
executable file
·71 lines (54 loc) · 1.58 KB
/
Negativebinomial.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
---
title: "Negative binomial"
author: "Leo Lahti, Sudarshan Shetty et al."
bibliography:
- bibliography.bib
output:
BiocStyle::html_document:
number_sections: no
toc: yes
toc_depth: 4
toc_float: true
self_contained: true
thumbnails: true
lightbox: true
gallery: true
use_bookdown: false
highlight: haddock
---
<!--
%\VignetteEngine{knitr::rmarkdown}
%\VignetteIndexEntry{microbiome tutorial - comparisons}
%\usepackage[utf8]{inputenc}
%\VignetteEncoding{UTF-8}
-->
## Group-wise comparisons with negative binomial
[Read more on negative binomials](http://www.ats.ucla.edu/stat/r/dae/nbreg.htm)
Load example data:
```{r boxplot-example, warning=FALSE, message=FALSE}
# Load libraries
library(microbiome)
library(ggplot2)
library(dplyr)
# Probiotics intervention example data
data(peerj32) # Source: https://peerj.com/articles/32/
pseq <- peerj32$phyloseq # Rename the example data
```
Visually compare Akkermansia abundance between time point 1 and 2
```{r boxplot2, warning=FALSE, message=FALSE}
p <- boxplot_abundance(pseq, x = "time", y = "Akkermansia", line = "subject") + scale_y_log10()
print(p)
```
Test statistical significance with negative binomial:
```{r comparisons2b, message=FALSE, error=FALSE, warning=FALSE}
library(MASS)
library(tidyr)
# Analyse specific taxa
tax <- "Akkermansia"
# Pick the signal (abundance) for this tax
sample_data(pseq)$signal <- get_sample(pseq, tax)
# Negative binomial test with group and gender included
res <- glm.nb(signal ~ group + sex, data = meta(pseq))
# Show the results
print(coef(summary(res)))
```