| trans_beta | R Documentation |
trans_beta object for beta-diversity analysisThis class is a wrapper for a series of beta-diversity related analysis,
including ordination analysis based on An et al. (2019) <doi:10.1016/j.geoderma.2018.09.035>, group distance comparision,
clustering, perMANOVA based on Anderson al. (2008) <doi:10.1111/j.1442-9993.2001.01070.pp.x>, ANOSIM and PERMDISP.
Note that the beta diversity analysis methods related with environmental variables are encapsulated within the trans_env class.
new()trans_beta$new(dataset = NULL, measure = NULL, group = NULL)
datasetan object of microtable class.
measuredefault NULL; a matrix name (or index) stored in microtable$beta_diversity list, such as "bray" or "jaccard",
or a customized matrix (also supports dist object and data.frame format with sample names as row and column names);
used for ordination, manova, group distance comparision, etc.;
Please see cal_betadiv function of microtable class for more details.
groupdefault NULL; a column name of sample_table in the input dataset; group information will be used for manova, betadisper or distance comparision.
measure, group and dataset stored in the object.
data(dataset) t1 <- trans_beta$new(dataset = dataset, measure = "bray", group = "Group")
cal_ordination()Unconstrained ordination.
trans_beta$cal_ordination( method = "PCoA", ncomp = 2, taxa_level = NULL, NMDS_matrix = TRUE, trans = FALSE, scale_species = FALSE, scale_species_ratio = 0.8, orthoI = NA, ordination = deprecated(), ... )
methoddefault "PCoA"; "PCoA", "NMDS", "PCA", "DCA", "PLS-DA" or "OPLS-DA". PCoA: principal coordinates analysis; NMDS: non-metric multidimensional scaling, PCA: principal component analysis; DCA: detrended correspondence analysis; PLS-DA: partial least squares discriminant analysis; OPLS-DA: orthogonal partial least squares discriminant analysis. For the methods details, please refer to the papers <doi:10.1111/j.1574-6941.2007.00375.x> (for PCoA, NMDS, PCA and DCA) and <doi:10.1186/s12859-019-3310-7> (for PLS-DA or OPLS-DA).
ncompdefault 2; dimensions in the result. For the method option "PCA", "PCoA" or "DCA",
the corresponding dimension information will be selected from the original model based on this parameter..
For all the dimension information, please refer to model in the results.
For the method option "NMDS", this argument will be passed to the k parameter in the vegan::metaMDS function.
taxa_leveldefault NULL; available for PCA, DCA, PLS-DA, OPLS-DA or NMDS (NMDS_matrix = FALSE).
Default NULL means using the otu_table in the microtable object.
For other options, please provide the taxonomic rank names in tax_table, such as "Phylum" or "Genus".
In such cases, the data will be merged according to the provided taxonomic levels to generated a new abundance table.
Note that this parameter has no effect on the methods "PCoA" and "NMDS" with NMDS_matrix = TRUE, as they use the distance matrix.
NMDS_matrixdefault TRUE; For the NMDS method, whether use a distance matrix as input like PCoA. If it is FALSE, the input will be the abundance table like PCA.
transdefault FALSE; whether species abundance will be square root transformed; only available when method is "PCA" or "DCA".
For method "NMDS" and NMDS_matrix = FALSE, please set the autotransform parameter, which will be passed to vegan::metaMDS function directly.
scale_speciesdefault FALSE; whether species loading in PCA, DCA or NMDS (NMDS_matrix = FALSE) is scaled.
scale_species_ratiodefault 0.8; the ratio to scale up the loading; multiply by the maximum distance between samples and origin.
Only available when scale_species = TURE.
orthoIdefault NA; number of orthogonal components (for OPLS-DA only). Default NA means the number of orthogonal components is automatically computed.
Please also see orthoI parameter in opls function of ropls package.
ordinationdeprecated. Please use method argument instead.
...parameters passed to vegan::rda function when method = "PCA",
or vegan::decorana function when method = "DCA",
or ape::pcoa function when method = "PCoA",
or vegan::metaMDS function when method = "NMDS",
or ropls::opls function when method = "PLS-DA" or method = "OPLS-DA" .
res_ordination list stored in the object.
In the list, model is the original analysis results; scores is the sample scores table; loading is the feature loading table.
Note that in the loading table, an extra column dist represents the distance of each feature to the origin,
i.e. the sum of squares of the loading values of the selected dimensions; the table is sorted by this column in decreasing order,
so the most influential features are in the first rows.
t1$cal_ordination(method = "PCoA")
plot_ordination()Plot the ordination result.
trans_beta$plot_ordination( plot_type = "point", choices = c(1, 2), color_values = RColorBrewer::brewer.pal(8, "Dark2"), shape_values = c(16, 17, 7, 8, 15, 18, 11, 10, 12, 13, 9, 3, 4, 0, 1, 2, 14), plot_color = NULL, plot_shape = NULL, plot_group_order = NULL, add_sample_label = NULL, point_size = 3, point_alpha = 0.8, point_second = FALSE, point_second_size = NULL, point_second_alpha = NULL, point_second_color = NULL, centroid_segment_alpha = 0.6, centroid_segment_size = 1, centroid_segment_linetype = 3, ellipse_chull_fill = TRUE, ellipse_chull_alpha = 0.1, ellipse_level = 0.9, ellipse_type = "t", NMDS_stress_pos = c(1, 1), NMDS_stress_text_prefix = "", loading_arrow = FALSE, loading_taxa_num = 10, loading_text_taxlevel = NULL, loading_text_color = "black", loading_arrow_color = "grey30", loading_text_size = 3, loading_text_prefix = FALSE, loading_text_italic = FALSE )
plot_typedefault "point"; one or more elements of "point", "ellipse", "chull" and "centroid".
add sample points
add confidence ellipse for points of each group
add convex hull for points of each group
add centroid line for points in each group
choicesdefault c(1, 2); selected axis for the visualization; must be a numeric vector with two elements.
The maximum value must not exceed the parameter ncomp in the cal_ordination function.
color_valuesdefault RColorBrewer::brewer.pal(8, "Dark2"); colors palette for different groups.
shape_valuesdefault c(16, 17, 7, 8, 15, 18, 11, 10, 12, 13, 9, 3, 4, 0, 1, 2, 14); a vector for point shape types of groups, see ggplot2 tutorial.
plot_colordefault NULL; a colname of sample_table to assign colors to different groups in plot.
plot_shapedefault NULL; a colname of sample_table to assign shapes to different groups in plot.
plot_group_orderdefault NULL; a vector used to order the groups in the legend of plot.
Only available when plot_color parameter is provided.
add_sample_labeldefault NULL; a column name in sample_table; If provided, show the point name in plot.
point_sizedefault 3; point size when "point" is in plot_type parameter.
point_size can also be a variable name in sample_table, such as "pH".
point_alphadefault .8; point transparency in plot when "point" is in plot_type parameter.
point_seconddefault FALSE; whether plot the second group of points.
Only available when input point_size is numeric value.
point_second_sizedefault NULL; size value of the second type of point. Default means point_size * 0.6
point_second_alphadefault NULL; point transparency of the second type of point.
point_second_colordefault NULL; a color value of the second type of point. If NULL, same with previous setting.
centroid_segment_alphadefault 0.6; segment transparency in plot when "centroid" is in plot_type parameter.
centroid_segment_sizedefault 1; segment size in plot when "centroid" is in plot_type parameter.
centroid_segment_linetypedefault 3; the line type related with centroid in plot when "centroid" is in plot_type parameter.
ellipse_chull_filldefault TRUE; whether fill colors to the area of ellipse or chull.
ellipse_chull_alphadefault 0.1; color transparency in the ellipse or convex hull depending on whether "ellipse" or "centroid" is in plot_type parameter.
ellipse_leveldefault .9; confidence level of ellipse when "ellipse" is in plot_type parameter.
ellipse_typedefault "t"; ellipse type when "ellipse" is in plot_type parameter; see type in stat_ellipse.
NMDS_stress_posdefault c(1, 1); a numerical vector with two values used to represent the insertion position of the stress text.
The first one denotes the x-axis, while the second one corresponds to the y-axis.
The assigned position is determined by multiplying the respective value with the maximum point on the corresponding coordinate axis.
Thus, the x-axis position is equal to max(points of x axis) * NMDS_stress_pos[1],
and the y-axis position is equal to max(points of y axis) * NMDS_stress_pos[2]. Negative values can also be utilized for the negative part of the axis.
NMDS_stress_pos = NULL denotes no stress text to show.
NMDS_stress_text_prefixdefault ""; If NMDS_stress_pos is not NULL, this parameter can be used to add text in front of the stress value.
loading_arrowdefault FALSE; whether show the loading using arrow. Only valid when there is a loading object in the ordination results, for example, when the ordination method is "PCA" or "DCA".
loading_taxa_numdefault 10; the number of taxa used for the loading. Only available when loading_arrow = TRUE.
loading_text_taxleveldefault NULL; which level of taxonomic table will be used.
Default NULL means using the taxa_level parameter in the previous cal_ordination function.
loading_text_colordefault "black"; the color of taxa text. Only available when loading_arrow = TRUE.
loading_arrow_colordefault "grey30"; the color of taxa arrow. Only available when loading_arrow = TRUE.
loading_text_sizedefault 3; the size of taxa text. Only available when loading_arrow = TRUE.
loading_text_prefixdefault FALSE; whether show the prefix (e.g., g__) in the taxa text. Only available when loading_arrow = TRUE.
loading_text_italicdefault FALSE; whether using italic for the taxa text. Only available when loading_arrow = TRUE.
ggplot.
t1$plot_ordination(plot_type = "point")
t1$plot_ordination(plot_color = "Group", plot_shape = "Group", plot_type = "point")
t1$plot_ordination(plot_color = "Group", plot_type = c("point", "ellipse"))
t1$plot_ordination(plot_color = "Group", plot_type = c("point", "centroid"),
centroid_segment_linetype = 1)
cal_manova()Calculate perMANOVA (Permutational Multivariate Analysis of Variance) based on the adonis2 function of vegan package <doi:10.1111/j.1442-9993.2001.01070.pp.x>.
trans_beta$cal_manova( manova_all = TRUE, manova_set = NULL, group = NULL, by_group = NULL, p_adjust_method = "fdr", by = "terms", by_auto_set = TRUE, permutations = 999, ... )
manova_alldefault TRUE; TRUE represents test for all the groups, i.e. the overall test; FALSE represents test for all the paired groups.
manova_setdefault NULL; other specified group set for manova, such as "Group + Type", "Group*Type" or "~Cropping+Fertilization".
Please also see the formula parameter (only right-hand side) in adonis2 function of vegan package.
The parameter manova_set has higher priority than manova_all parameter. If manova_set is provided; manova_all is disabled.
groupdefault NULL; a column name of sample_table used for manova. If NULL, search group variable stored in the object.
Available when manova_set is not provided.
by_groupdefault NULL; one column name in sample_table; used to perform paired comparisions within each group.
Only available when manova_all = FALSE and manova_set is not provided.
p_adjust_methoddefault "fdr"; p.adjust method; available when manova_all = FALSE;
see method parameter of p.adjust function for available options.
bydefault "terms"; same with the by parameter in adonis2 function of vegan package.
by_auto_setdefault TRUE; Whether automatically set the options for by parameter ("marginal" or "terms") when manova_set is provided.
The primary reason for setting this parameter is that using marginal effects (also known as "Type III" effects) is more robust for unbalanced experimental designs.
Since the option by = "margin" in the adonis2 function ignores main effects when interaction effects are present,
we automatically set by = "margin" when there are no interaction effects, and set by = "terms" when interaction effects exist.
If the user wants to use parameter by, please set by_auto_set = FALSE. Note that this parameter is only available when manova_set is provided.
permutationsdefault 999; same with the permutations parameter in adonis2 function of vegan package.
...parameters passed to adonis2 function of vegan package.
res_manova stored in object with data.frame class.
t1$cal_manova(manova_all = TRUE)
cal_anosim()Analysis of similarities (ANOSIM) based on the anosim function of vegan package.
trans_beta$cal_anosim( paired = FALSE, group = NULL, by_group = NULL, p_adjust_method = "fdr", permutations = 999, ... )
paireddefault FALSE; whether perform paired test between any two combined groups from all the input groups.
groupdefault NULL; a column name of sample_table. If NULL, search group variable stored in the object.
by_groupdefault NULL; one column name in sample_table; used to perform paired comparisions within each group.
Only available when paired = TRUE.
p_adjust_methoddefault "fdr"; p.adjust method; available when paired = TRUE; see method parameter of p.adjust function for available options.
permutationsdefault 999; same with the permutations parameter in anosim function of vegan package.
...parameters passed to anosim function of vegan package.
res_anosim stored in object with data.frame class.
t1$cal_anosim()
cal_betadisper()Multivariate homogeneity test of groups dispersions (PERMDISP) based on betadisper function in vegan package.
trans_beta$cal_betadisper(group = NULL, permutest_args = list(), ...)
groupdefault NULL; a column name of sample_table used for the test. If NULL, search group variable stored in the object.
permutest_argsdefault empty list; a list of parameters passed to permutest function of vegan package,
such as list(permutations = 999). Note that the elements in the list should be named.
The pairwise comparison is always performed, so the pairwise parameter is not necessary.
...parameters passed to betadisper function.
res_betadisper stored in object.
t1$cal_betadisper()
cal_group_distance()Convert symmetric distance matrix to distance table of paired samples that are within groups or between groups.
trans_beta$cal_group_distance( within_group = TRUE, by_group = NULL, ordered_group = NULL, sep = " vs " )
within_groupdefault TRUE; whether obtain distance table of paired samples within groups; if FALSE, obtain distances of paired samples between any two groups.
by_groupdefault NULL; one colname name of sample_table in microtable object.
If provided, transform distances by the provided by_group parameter. This is especially useful for ordering and filtering values further.
When within_group = TRUE, the result of by_group parameter is the format of paired groups.
When within_group = FALSE, the result of by_group parameter is the format same with the group information in sample_table.
ordered_groupdefault NULL; a vector representing the ordered elements of group parameter; only useful when within_group = FALSE.
sepdefault " vs "; a character string to separate the group names after merging them into a new name.
res_group_distance, stored in object.
\donttest{
t1$cal_group_distance(within_group = TRUE)
}
cal_group_distance_diff()Differential test of converted distances across groups.
trans_beta$cal_group_distance_diff( group = NULL, by_group = NULL, by_ID = NULL, ... )
groupdefault NULL; a column name of object$res_group_distance used for the statistics; If NULL, use the group inside the object.
by_groupdefault NULL; a column of object$res_group_distance used to perform the differential test
among elements in group parameter for each element in by_group parameter. So by_group has a larger scale than group parameter.
This by_group is very different from the by_group parameter in the cal_group_distance function.
by_IDdefault NULL; a column of object$res_group_distance used to perform paired t test or paired wilcox test for the paired data,
such as the data of plant compartments for different plant species (ID).
So by_ID should be the smallest unit of sample collection without any repetition in it.
...parameters passed to cal_diff function of trans_alpha class.
res_group_distance_diff, stored in object.
\donttest{
t1$cal_group_distance_diff()
}
plot_group_distance()Plot the distances of paired groups within or between groups.
trans_beta$plot_group_distance(plot_group_order = NULL, ...)
plot_group_orderdefault NULL; a vector used to order the groups in the plot.
...parameters (except measure) passed to plot_alpha function of trans_alpha class.
ggplot.
\donttest{
t1$plot_group_distance()
}
plot_clustering()Plot clustering result based on the ggdendro package.
trans_beta$plot_clustering( color_values = RColorBrewer::brewer.pal(8, "Dark2"), measure = NULL, group = NULL, replace_name = NULL, legend_position = "none" )
color_valuesdefault RColorBrewer::brewer.pal(8, "Dark2"); color palette for the text.
measuredefault NULL; beta diversity index; If NULL, using the measure (the distance matrix) when creating the object.
It can be a matrix name or index in the beta_diversity list, or a customized matrix (also supports dist object and data.frame).
If the object has no measure and the beta_diversity list is not NULL, the first matrix in the list is used with a message.
groupdefault NULL; if provided, use this group to assign color.
replace_namedefault NULL; if provided, use this as label.
legend_positiondefault "none"; the position of legend; only available when group parameter is provided.
Options include "none", "left", "right", "bottom" and "top".
ggplot.
t1$plot_clustering(group = "Group", replace_name = c("Saline", "Type"))
clone()The objects of this class are cloneable with this method.
trans_beta$clone(deep = FALSE)
deepWhether to make a deep clone.
## ------------------------------------------------
## Method `trans_beta$new`
## ------------------------------------------------
data(dataset)
t1 <- trans_beta$new(dataset = dataset, measure = "bray", group = "Group")
## ------------------------------------------------
## Method `trans_beta$cal_ordination`
## ------------------------------------------------
t1$cal_ordination(method = "PCoA")
## ------------------------------------------------
## Method `trans_beta$plot_ordination`
## ------------------------------------------------
t1$plot_ordination(plot_type = "point")
t1$plot_ordination(plot_color = "Group", plot_shape = "Group", plot_type = "point")
t1$plot_ordination(plot_color = "Group", plot_type = c("point", "ellipse"))
t1$plot_ordination(plot_color = "Group", plot_type = c("point", "centroid"),
centroid_segment_linetype = 1)
## ------------------------------------------------
## Method `trans_beta$cal_manova`
## ------------------------------------------------
t1$cal_manova(manova_all = TRUE)
## ------------------------------------------------
## Method `trans_beta$cal_anosim`
## ------------------------------------------------
t1$cal_anosim()
## ------------------------------------------------
## Method `trans_beta$cal_betadisper`
## ------------------------------------------------
t1$cal_betadisper()
## ------------------------------------------------
## Method `trans_beta$cal_group_distance`
## ------------------------------------------------
t1$cal_group_distance(within_group = TRUE)
## ------------------------------------------------
## Method `trans_beta$cal_group_distance_diff`
## ------------------------------------------------
t1$cal_group_distance_diff()
## ------------------------------------------------
## Method `trans_beta$plot_group_distance`
## ------------------------------------------------
t1$plot_group_distance()
## ------------------------------------------------
## Method `trans_beta$plot_clustering`
## ------------------------------------------------
t1$plot_clustering(group = "Group", replace_name = c("Saline", "Type"))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.