A convenience wrapper for bdiv_table()
+ stats_table()
.
Usage
bdiv_stats(
biom,
regr = NULL,
stat.by = NULL,
bdiv = "Bray-Curtis",
weighted = TRUE,
tree = NULL,
within = NULL,
between = NULL,
split.by = NULL,
transform = "none",
test = "emmeans",
fit = "gam",
at = NULL,
level = 0.95,
alt = "!=",
mu = 0,
p.adj = "fdr"
)
Arguments
- biom
An rbiom object, such as from
as_rbiom()
. Any value accepted byas_rbiom()
can also be given here.- regr
Dataset field with the x-axis (independent; predictive) values. Must be numeric. Default:
NULL
- stat.by
Dataset field with the statistical groups. Must be categorical. Default:
NULL
- bdiv
Beta diversity distance algorithm(s) to use. Options are:
"Bray-Curtis"
,"Manhattan"
,"Euclidean"
,"Jaccard"
, and"UniFrac"
. For"UniFrac"
, a phylogenetic tree must be present inbiom
or explicitly provided viatree=
. Multiple/abbreviated values allowed. Default:"Bray-Curtis"
- weighted
Take relative abundances into account. When
weighted=FALSE
, only presence/absence is considered. Multiple values allowed. Default:TRUE
- tree
A
phylo
object representing the phylogenetic relationships of the taxa inbiom
. Only required when computing UniFrac distances. Default:biom$tree
- within, between
Dataset field(s) for intra- or inter- sample comparisons. Alternatively, dataset field names given elsewhere can be prefixed with
'=='
or'!='
to assign them towithin
orbetween
, respectively. Default:NULL
- split.by
Dataset field(s) that the data should be split by prior to any calculations. Must be categorical. Default:
NULL
- transform
Transformation to apply. Options are:
c("none", "rank", "log", "log1p", "sqrt", "percent")
."rank"
is useful for correcting for non-normally distributions before applying regression statistics. Default:"none"
- 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 tomu
),'<'
(less thanmu
), or'>'
(greater thanmu
). 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"
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.
Field | Description |
.mean | Estimated marginal mean. See emmeans::emmeans() . |
.mean.diff | Difference in means. |
.slope | Trendline slope. See emmeans::emtrends() . |
.slope.diff | Difference in slopes. |
.h1 | Alternate hypothesis. |
.p.val | Probability that null hypothesis is correct. |
.adj.p | .p.val after adjusting for multiple comparisons. |
.effect.size | Effect size. See emmeans::eff_size() . |
.lower | Confidence interval lower bound. |
.upper | Confidence interval upper bound. |
.se | Standard error. |
.n | Number of samples. |
.df | Degrees of freedom. |
.stat | Wilcoxon or Kruskal-Wallis rank sum statistic. |
.t.ratio | .mean / .se |
.r.sqr | Percent of variation explained by the model. |
.adj.r | .r.sqr , taking degrees of freedom into account. |
.aic | Akaike Information Criterion (predictive models). |
.bic | Bayesian Information Criterion (descriptive models). |
.loglik | Log-likelihood goodness-of-fit score. |
.fit.p | P-value for observing this fit by chance. |
See also
Other beta_diversity:
bdiv_boxplot()
,
bdiv_clusters()
,
bdiv_corrplot()
,
bdiv_heatmap()
,
bdiv_ord_plot()
,
bdiv_ord_table()
,
bdiv_table()
,
distmat_stats()
Other stats_tables:
adiv_stats()
,
distmat_stats()
,
stats_table()
,
taxa_stats()
Examples
library(rbiom)
biom <- rarefy(hmp50)
bdiv_stats(biom, stat.by = "Sex", bdiv = c("bray", "unifrac"))[,1:7]
#> # Model: gam(.distance ~ Sex, method = "REML")
#> # A tibble: 6 × 7
#> .bdiv Sex .mean.diff .h1 .p.val .adj.p .effect.size
#> <fct> <chr> <dbl> <fct> <dbl> <dbl> <dbl>
#> 1 Bray-Curtis Female - Male 0.0599 != 0 0.00402 0.0219 0.261
#> 2 Bray-Curtis Male - Female vs Male -0.0489 != 0 0.00730 0.0219 -0.235
#> 3 UniFrac Female - Female vs M… -0.0259 != 0 0.0866 0.173 -0.109
#> 4 UniFrac Male - Female vs Male -0.0249 != 0 0.187 0.281 -0.115
#> 5 Bray-Curtis Female - Female vs M… 0.0110 != 0 0.430 0.515 0.0503
#> 6 UniFrac Female - Male -0.00105 != 0 0.963 0.963 -0.00419
biom <- subset(biom, `Body Site` %in% c('Saliva', 'Stool', 'Buccal mucosa'))
bdiv_stats(biom, stat.by = "Body Site", split.by = "==Sex")[,1:6]
#> # Model: gam(.distance ~ `Body Site`, method = "REML")
#> # A tibble: 30 × 6
#> Sex `Body Site` .mean.diff .h1 .p.val .adj.p
#> <fct> <chr> <dbl> <fct> <dbl> <dbl>
#> 1 Female Buccal mucosa - Buccal mucosa vs S… -0.791 != 0 1.66e-35 2.91e-34
#> 2 Female Buccal mucosa - Saliva vs Stool -0.789 != 0 1.94e-35 2.91e-34
#> 3 Female Buccal mucosa - Buccal mucosa vs S… -0.596 != 0 5.30e-23 5.30e-22
#> 4 Male Saliva - Saliva vs Stool -0.528 != 0 4.09e-22 3.06e-21
#> 5 Male Saliva - Buccal mucosa vs Stool -0.526 != 0 5.30e-22 3.18e-21
#> 6 Female Buccal mucosa vs Saliva - Buccal m… -0.195 != 0 2.44e-20 1.22e-19
#> 7 Female Buccal mucosa vs Saliva - Saliva v… -0.193 != 0 3.80e-20 1.63e-19
#> 8 Female Saliva - Buccal mucosa vs Stool -0.505 != 0 5.18e-20 1.94e-19
#> 9 Female Saliva - Saliva vs Stool -0.503 != 0 5.95e-20 1.98e-19
#> 10 Male Buccal mucosa - Saliva vs Stool -0.531 != 0 9.76e-19 2.93e-18
#> # ℹ 20 more rows