-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathMixedmodels.Rmd
executable file
·74 lines (58 loc) · 1.6 KB
/
Mixedmodels.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
70
71
72
73
---
title: "Comparisons of microbiome community composition"
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}
-->
## Mixed models for univariate comparisons
Load example data:
```{r boxplot-example_w, warning=FALSE, message=FALSE}
# Load libraries
library(microbiome)
library(ggplot2)
library(dplyr)
library(IRanges)
# Probiotics intervention example data
data(peerj32) # Source: https://peerj.com/articles/32/
pseq <- peerj32$phyloseq # Rename the example data
```
Abundance boxplot
```{r boxplot2_w, warning=FALSE, message=FALSE}
p <- boxplot_abundance(pseq, x = "time", y = "Akkermansia", line = "subject") +
scale_y_log10()
print(p)
```
## Linear model comparison with random effect subject term
Test individual taxonomic group
```{r comparisons-lmer_w, message=FALSE, warning=FALSE}
# Get sample metadata
dfs <- meta(pseq)
# Add abundance as the signal to model
dfs$signal <- abundances(pseq)["Akkermansia", rownames(dfs)]
# Paired comparison
# with fixed group effect and random subject effect
library(lme4)
out <- lmer(signal ~ group + (1|subject), data = dfs)
out0 <- lmer(signal ~ (1|subject), data = dfs)
comp <- anova(out0, out)
pv <- comp[["Pr(>Chisq)"]][[2]]
print(pv)
```