models2stats: Extract statistics from taxatree_models or tax_model output

taxatree_models2statsR Documentation

Extract statistics from taxatree_models or tax_model output

Description

Runs a function e.g. broom::tidy on a list of models, i.e. the output of taxatree_models or tax_model

Usage

taxatree_models2stats(data, fun = "auto", ..., .keep_models = FALSE)

tax_models2stats(data, rank = NULL, fun = "auto", ..., .keep_models = FALSE)

Arguments

data

psExtra with attached tax_models or taxatree_models list, or just the list of models

fun

function to assist extraction of stats dataframe from models, or "auto"

...

extra arguments passed to fun

.keep_models

should the models list be kept in the psExtra output?

rank

string naming rank at which tax_model was run (needed if data is a list)

Value

data.frame, attached to psExtra

Functions

  • taxatree_models2stats(): Extract stats from list or psExtra output of taxatree_models

  • tax_models2stats(): Extract stats from list or psExtra output of tax_model

Examples

# This example is an abbreviated excerpt from article on taxon modelling on
# the microViz documentation website

library(dplyr)
data("ibd", package = "microViz")

# We'll keep only the Ulcerative Colitis and Healthy Control samples, to
# simplify the analyses for this example. We'll also remove the Species
# rank information, as most OTUs in this dataset are not assigned to a
# species. We'll also use `tax_fix` to fill any gaps where the Genus is
# unknown, with the family name or whatever higher rank classification is
# known.

phylo <- ibd %>%
  ps_filter(DiseaseState %in% c("UC", "nonIBD")) %>%
  tax_mutate(Species = NULL) %>%
  tax_fix()

# Let's make some sample data variables that are easier to use and compare
# in the statistical modelling ahead. We will convert dichotomous
# categorical variables into similar binary variables (values: 1 for true,
# or 0 for false). We will also scale and center the numeric variable for
# age.

phylo <- phylo %>%
  ps_mutate(
    UC = ifelse(DiseaseState == "UC", yes = 1, no = 0),
    female = ifelse(gender == "female", yes = 1, no = 0),
    antibiotics = ifelse(abx == "abx", yes = 1, no = 0),
    steroids = ifelse(steroids == "steroids", yes = 1, no = 0),
    age_scaled = scale(age, center = TRUE, scale = TRUE)
  )

lm_models <- phylo %>%
  tax_fix() %>%
  tax_prepend_ranks() %>%
  tax_transform("compositional", rank = "Genus") %>%
  tax_filter(min_prevalence = 0.1, use_counts = TRUE) %>%
  taxatree_models(
    type = lm,
    trans = "log2", trans_args = list(zero_replace = "halfmin"),
    ranks = c("Phylum", "Class", "Genus"),
    variables = c("UC", "female", "antibiotics", "steroids", "age_scaled")
  )

lm_stats <- lm_models %>% taxatree_models2stats()

# inspect the psExtra returned, now with taxatree_stats dataframe added
lm_stats

# inspect the dataframe itself
lm_stats %>% taxatree_stats_get()

# keep the models on the psExtra object
lm_models %>% taxatree_models2stats(.keep_models = TRUE)

# you can adjust the p values with taxatree_stats_p_adjust

# you can plot the results with taxatree_plots

david-barnett/microViz documentation built on April 17, 2025, 4:25 a.m.