R/getPERMANOVA.R
getPERMANOVA.Rd
These functions perform PERMANOVA to assess the significance of group
differences based on a specified dissimilarity matrix. The results can be
returned directly or added to metadata in an object of class
TreeSummarizedExperiment
.
getPERMANOVA(x, ...)
addPERMANOVA(x, ...)
# S4 method for class 'SingleCellExperiment'
getPERMANOVA(x, ...)
# S4 method for class 'SummarizedExperiment'
getPERMANOVA(x, assay.type = "counts", formula = NULL, col.var = NULL, ...)
# S4 method for class 'ANY'
getPERMANOVA(x, formula, data, method = "bray", test.homogeneity = TRUE, ...)
# S4 method for class 'SummarizedExperiment'
addPERMANOVA(x, name = "permanova", ...)
additional arguments passed to vegan::adonis2
.
by
: Character scalar
. Specifies how significance is
calculated. (Default: "margin"
)
na.action
: function
. Action to take when missing
values for any of the variables in formula
are encountered.
(Default: na.fail
)
full
Logical scalar
. should all the results from the
homogeneity calculations be returned. When FALSE
, only
summary tables are returned. (Default: FALSE
)
homogeneity.test
: Character scalar
. Specifies
the significance test used to analyse
vegan::betadisper
results.
Options include 'permanova'
(vegan::permutest
), 'anova'
(stats::anova
) and 'tukeyhsd'
(stats::TukeyHSD
).
(Default: "permanova"
)
Character scalar
. Specifies which assay to use for
calculation. (Default: "counts"
)
formula
. If x
is a
SummarizedExperiment
a formula can be supplied. Based on the right-hand side of the given formula
colData
is subset to col.var
.
col.var
and formula
can be missing, which turns the CCA
analysis into a CA analysis and dbRDA into PCoA/MDS.
Character scalar
. When x
is a
SummarizedExperiment
,col.var
can be used to specify variables
from colData
.
data.frame
or coarcible to one. The covariance table
including covariates defined by formula
.
Character scalar
. A dissimilarity metric used in
PERMANOVA and group dispersion calculation. (Default: "bray"
)
Logical scalar
. Should the homogeneity of
group dispersions be evaluated? (Default: TRUE
)
Character scalar
. A name for the results that will be
stored to metadata. (Default: "permanova"
)
getPERMANOVA
returns the PERMANOVA results or a list containing the
PERMANOVA results and homogeneity test results if
test.homogeneity = TRUE
. addPERMANOVA
adds these results to
metadata of x
.
PERMANOVA is a non-parametric method used to test whether the centroids of different groups (as defined by the formula or covariates) are significantly different in terms of multivariate space.
PERMANOVA relies on the assumption of group homogeneity, meaning the groups should be distinct and have similar variances within each group. This assumption is essential as PERMANOVA is sensitive to differences in within-group dispersion, which can otherwise confound results. This is why the functions return homogeneity test results by default.
The functions utilize vegan::adonis2
to compute
PERMANOVA. For homogeneity testing,
vegan::betadisper
along
with vegan::permutest
are utilized by default,
which allow testing for equal dispersion across groups and validate the
homogeneity assumption.
PERMANOVA and distance-based redundancy analysis (dbRDA) are closely related methods for analyzing multivariate data. PERMANOVA is non-parametric, making fewer assumptions about the data. In contrast, dbRDA assumes a linear relationship when constructing the ordination space, although it also employs a PERMANOVA-like approach to test the significance of predictors within this space. dbRDA offers a broader scope overall, as it provides visualization of the constrained ordination, which can reveal patterns and relationships. However, when the underlying data structure is non-linear, the results from the two methods can differ significantly due to dbRDA's reliance on linear assumptions.
For more details on the actual implementation see
vegan::adonis2
,
vegan::betadisper
, and
vegan::permutest
. See also
addCCA
and addRDA
data(GlobalPatterns)
tse <- GlobalPatterns
# Apply relative transformation
tse <- transformAssay(tse, method = "relabundance")
# Perform PERMANOVA
tse <- addPERMANOVA(
tse,
assay.type = "relabundance",
method = "bray",
formula = x ~ SampleType,
permutations = 99
)
# The results are stored to metadata
metadata(tse)[["permanova"]]
#> $permanova
#> Permutation test for adonis under reduced model
#> Marginal effects of terms
#> Permutation: free
#> Number of permutations: 99
#>
#> adonis2(formula = formula, data = data, permutations = 99, method = ..1, by = by, na.action = na.action)
#> Df SumOfSqs R2 F Pr(>F)
#> SampleType 8 8.2466 0.73109 5.7773 0.01 **
#> Residual 17 3.0332 0.26891
#> Total 25 11.2798 1.00000
#> ---
#> Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#>
#> $homogeneity
#> Df Sum Sq Mean Sq F N.Perm Pr(>F) Total variance
#> SampleType 8 0.4996524 0.06245655 5.807135 99 0.01 0.6824898
#> Explained variance
#> SampleType 0.7321024
#>
# Calculate dbRDA
rda_res <- getRDA(
tse, assay.type = "relabundance", method = "bray",
formula = x ~ SampleType, permutations = 99)
# Significance results are similar to PERMANOVA
attr(rda_res, "significance")
#> $permanova
#> Df SumOfSqs F Pr(>F) Total variance Explained variance
#> Model 8 8.24659 5.777341 0.001 11.27982 0.7310924
#> SampleType 8 8.24659 5.777341 0.010 11.27982 0.7310924
#> Residual 17 3.03323 NA NA 11.27982 0.2689076
#>
#> $homogeneity
#> Df Sum Sq Mean Sq F N.Perm Pr(>F) Total variance
#> SampleType 8 0.4996524 0.06245655 5.807135 99 0.01 0.6824898
#> Explained variance
#> SampleType 0.7321024
#>