nb_mods: Fit negative binomial models to each taxa within an OTU table

Description Usage Arguments Details Value Note References Examples

View source: R/nb_mods.R

Description

Fit negative binomial models to each taxa within an OTU table through glm.nb in the MASS package. Models can include a random effect if desired. Modesl will then be fit through glmer.nb in the lmer package. Summaries for models or confidence intervals that fail to converge will not be returned, but taxa summaries will be provided in the output. Rank-Sum tests or presence/absence tests can be run on these taxa using tidi_rank_sum or tidi_chisq, respectively

Usage

1
2
3
4
5
6
7
8
nb_mods(
  micro_set,
  table,
  ...,
  Offset = TRUE,
  ref = NULL,
  SS_type = c(2, 3, "II", "III")
)

Arguments

micro_set

A tidy_micro data set

table

OTU table of interest

...

Covariates of interest. Can be interactions such as Group*Age

Offset

Logical; include subject sequencing depth as an offset for negative binomial models. This is highly recommended

ref

A character vector of the desired reference levels for each factor covariate. The order of the specifed references must match the order for the corresponding covariates specified in '...'

SS_type

Type of sums of squares calculated in Anova. Either type II (2) or type III (3) sums of squares

Details

Models containing only fixed effects are fit using glm.nb in the MASS package and models containing random effects are fit using glmer.nb. ANOVA / ANCOVA tests are conducted using a Likelihood Ratio test for fixed effects models and Chi-Squared tests for random effect models.

Value

A list containing several different model components and summaries

Convergend_Summary

A data.frame of model summaries from convergent models. Includes the Taxa name, the model coefficient, the estimated beta, the beta's 95 percent confidence interval, Z score, p_value, false discovery rate p-value, and p-value from likelihood ratio test

Estimate_Summary

A data.frame of model estimates from convergent models intended to be ready for export for publications. Includes the Taxa name, the model coefficient, the estimated Rate Ratio, the Wald 95 percent confidence interval, the Z-score, and false discovery rate p-value

RA_Summary

A data.frame of taxa summaries. Includes the Taxa name, grouping variables (each factor variable in your models), sample size (n), percent of 0 counts, basic summaries of relative abundance, percentiles of relative abundance, and a logical indicator of whether or not the model converged

formula

The formula used in the model

Model_Coef

Model coefficients (used in plotting funcitons)

Model_Covs

Model covariates (used in plotting functions)

Note

False Discovery Rate p-values are calculated using p.adjust. Estimated rate ratios and confidence intervals for interactions in the Estimate_Summary table include all main effects. It is not simply the exponentiated interaction beta, it is the interaction of the sum of the intercept, corresponding main effect betas, and interaction betas

References

Anova, glm.nb, glmer.nb

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
data(bpd_phy); data(bpd_cla); data(bpd_ord); data(bpd_fam); data(bpd_clin)
otu_tabs = list(Phylum = bpd_phy, Class = bpd_cla,
Order = bpd_ord, Family = bpd_fam)

set <- tidy_micro(otu_tabs = otu_tabs, clinical = bpd_clin) %>%
filter(day == 7)

nb_fam <- set %>%
otu_filter(prev_cutoff = 5, ra_cutoff = 0.1, exclude_taxa = c("Unclassified", "Bacteria")) %>%
nb_mods(table = "Family", bpd1)

names(nb_fam)
nb_fam$Estimate_Summary

tidyMicro documentation built on Jan. 13, 2021, 6:18 a.m.