Learn R Programming

rbiom (version 2.2.0)

stats_table: Run non-parametric statistics on a data.frame.

Description

A simple interface to lower-level statistics functions, including stats::wilcox.test(), stats::kruskal.test(), emmeans::emmeans(), and emmeans::emtrends().

Usage

stats_table(
  df,
  regr = NULL,
  resp = attr(df, "response"),
  stat.by = NULL,
  split.by = NULL,
  test = "emmeans",
  fit = "gam",
  at = NULL,
  level = 0.95,
  alt = "!=",
  mu = 0,
  p.adj = "fdr"
)

Value

A tibble data.frame with fields from the table below. This tibble object provides the $code operator to print the R code used to generate the statistics.

FieldDescription
.meanEstimated marginal mean. See emmeans::emmeans().
.mean.diffDifference in means.
.slopeTrendline slope. See emmeans::emtrends().
.slope.diffDifference in slopes.
.h1Alternate hypothesis.
.p.valProbability that null hypothesis is correct.
.adj.p.p.val after adjusting for multiple comparisons.
.effect.sizeEffect size. See emmeans::eff_size().
.lowerConfidence interval lower bound.
.upperConfidence interval upper bound.
.seStandard error.
.nNumber of samples.
.dfDegrees of freedom.
.statWilcoxon or Kruskal-Wallis rank sum statistic.
.t.ratio.mean / .se
.r.sqrPercent of variation explained by the model.
.adj.r.r.sqr, taking degrees of freedom into account.
.aicAkaike Information Criterion (predictive models).
.bicBayesian Information Criterion (descriptive models).
.loglikLog-likelihood goodness-of-fit score.
.fit.pP-value for observing this fit by chance.

Arguments

df

The dataset (data.frame or tibble object). "Dataset fields" mentioned below should match column names in df. Required.

regr

Dataset field with the x-axis (independent; predictive) values. Must be numeric. Default: NULL

resp

Dataset field with the y-axis (dependent; response) values, such as taxa abundance or alpha diversity. Default: attr(df, 'response')

stat.by

Dataset field with the statistical groups. Must be categorical. Default: NULL

split.by

Dataset field(s) that the data should be split by prior to any calculations. Must be categorical. Default: NULL

test

Method for computing p-values: 'wilcox', 'kruskal', 'emmeans', or 'emtrends'. Default: 'emmeans'

fit

How to fit the trendline. 'lm', 'log', or 'gam'. Default: 'gam'

at

Position(s) along the x-axis where the means or slopes should be evaluated. Default: NULL, which samples 100 evenly spaced positions and selects the position where the p-value is most significant.

level

The confidence level for calculating a confidence interval. Default: 0.95

alt

Alternative hypothesis direction. Options are '!=' (two-sided; not equal to mu), '<' (less than mu), or '>' (greater than mu). Default: '!='

mu

Reference value to test against. Default: 0

p.adj

Method to use for multiple comparisons adjustment of p-values. Run p.adjust.methods for a list of available options. Default: "fdr"

See Also

Other stats_tables: adiv_stats(), bdiv_stats(), distmat_stats(), taxa_stats()

Examples

Run this code
    library(rbiom)
    
    biom <- rarefy(hmp50)
    
    df <- taxa_table(biom, rank = "Family")
    stats_table(df, stat.by = "Body Site")[,1:6]
    
    df <- adiv_table(biom)
    stats_table(df, stat.by = "Sex", split.by = "Body Site")[,1:7]

Run the code above in your browser using DataLab