trans_beta: Create 'trans_beta' object for beta-diversity analysis based...

trans_betaR Documentation

Create trans_beta object for beta-diversity analysis based on the distance matrix

Description

This class is a wrapper for a series of beta-diversity related analysis, including ordination calculation and plot 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.

Methods

Public methods


Method new()

Usage
trans_beta$new(dataset = NULL, measure = NULL, group = NULL)
Arguments
dataset

the object of microtable class.

measure

default NULL; bray, jaccard, wei_unifrac or unwei_unifrac, or other name of matrix stored in microtable$beta_diversity; used for ordination, manova, group distance comparision, etc. The measure must be one of names in microtable$beta_diversity list. Please see cal_betadiv function of microtable class for more details.

group

default NULL; sample group used for manova, betadisper or group distance comparision.

Returns

parameters stored in the object.

Examples
data(dataset)
t1 <- trans_beta$new(dataset = dataset, measure = "bray", group = "Group")

Method cal_ordination()

Unconstrained ordination.

Usage
trans_beta$cal_ordination(
  ordination = "PCoA",
  ncomp = 3,
  trans_otu = FALSE,
  scale_species = FALSE,
  ...
)
Arguments
ordination

default "PCoA"; "PCA", "PCoA" or "NMDS". PCA: principal component analysis; PCoA: principal coordinates analysis; NMDS: non-metric multidimensional scaling.

ncomp

default 3; dimensions needed in the result.

trans_otu

default FALSE; whether species abundance will be square transformed; only available when ordination = PCA.

scale_species

default FALSE; whether species loading in PCA will be scaled.

...

parameters passed to vegan::rda function when ordination = "PCA", or ape::pcoa function when ordination = "PCoA", or vegan::metaMDS function when when ordination = "NMDS".

Returns

res_ordination stored in the object.

Examples
t1$cal_ordination(ordination = "PCoA")		

Method plot_ordination()

Plot the ordination result.

Usage
trans_beta$plot_ordination(
  plot_type = "point",
  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,
  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"
)
Arguments
plot_type

default "point"; one or more elements of "point", "ellipse", "chull" and "centroid".

'point'

add point

'ellipse'

add confidence ellipse for points of each group

'chull'

add convex hull for points of each group

'centroid'

add centroid line of each group

color_values

default RColorBrewer::brewer.pal(8, "Dark2"); colors palette for different groups.

shape_values

default 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_color

default NULL; a colname of sample_table to assign colors to different groups in plot.

plot_shape

default NULL; a colname of sample_table to assign shapes to different groups in plot.

plot_group_order

default NULL; a vector used to order the groups in the legend of plot.

add_sample_label

default NULL; a column name in sample_table; If provided, show the point name in plot.

point_size

default 3; point size when "point" is in plot_type parameter.

point_alpha

default .8; point transparency in plot when "point" is in plot_type parameter.

centroid_segment_alpha

default 0.6; segment transparency in plot when "centroid" is in plot_type parameter.

centroid_segment_size

default 1; segment size in plot when "centroid" is in plot_type parameter.

centroid_segment_linetype

default 3; the line type related with centroid in plot when "centroid" is in plot_type parameter.

ellipse_chull_fill

default TRUE; whether fill colors to the area of ellipse or chull.

ellipse_chull_alpha

default 0.1; color transparency in the ellipse or convex hull depending on whether "ellipse" or "centroid" is in plot_type parameter.

ellipse_level

default .9; confidence level of ellipse when "ellipse" is in plot_type parameter.

ellipse_type

default "t"; ellipse type when "ellipse" is in plot_type parameter; see type in stat_ellipse.

Returns

ggplot.

Examples
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 cal_manova()

Calculate perMANOVA based on <doi:10.1111/j.1442-9993.2001.01070.pp.x> and R vegan adonis2 function.

Usage
trans_beta$cal_manova(
  manova_all = TRUE,
  manova_set = NULL,
  group = NULL,
  p_adjust_method = "fdr",
  ...
)
Arguments
manova_all

default TRUE; TRUE represents test for all the groups, i.e. the overall test; FALSE represents test for all the paired groups.

manova_set

default NULL; other specified group set for manova, such as "Group + Type" and "Group*Type"; see also adonis2. manova_set has higher priority than manova_all parameter. If manova_set is provided; manova_all is disabled.

group

default NULL; a column name of sample_table used for manova. If NULL, search group variable stored in the object.

p_adjust_method

default "fdr"; p.adjust method; available when manova_all = FALSE; see method parameter of p.adjust function for available options.

...

parameters passed to adonis2 function of vegan package.

Returns

res_manova stored in object.

Examples
t1$cal_manova(manova_all = TRUE)

Method cal_anosim()

Analysis of similarities (ANOSIM) based on R vegan anosim function.

Usage
trans_beta$cal_anosim(
  group = NULL,
  paired = FALSE,
  p_adjust_method = "fdr",
  ...
)
Arguments
group

default NULL; a column name of sample_table. If NULL, search group variable stored in the object.

paired

default FALSE; whether perform paired test between any two combined groups from all the input groups.

p_adjust_method

default "fdr"; p.adjust method; available when paired = TRUE; see method parameter of p.adjust function for available options.

...

parameters passed to anosim function of vegan package.

Returns

res_anosim stored in object.

Examples
t1$cal_anosim()

Method cal_betadisper()

A wrapper for betadisper function in vegan package for multivariate homogeneity test of groups dispersions.

Usage
trans_beta$cal_betadisper(...)
Arguments
...

parameters passed to betadisper function.

Returns

res_betadisper stored in object.

Examples
t1$cal_betadisper()

Method cal_group_distance()

Convert sample distances within groups or between groups.

Usage
trans_beta$cal_group_distance(
  within_group = TRUE,
  by_group = NULL,
  ordered_group = NULL,
  sep = " vs "
)
Arguments
within_group

default TRUE; whether transform sample distance within groups, if FALSE, transform sample distance between any two groups.

by_group

default 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_group

default NULL; a vector representing the ordered elements of group parameter; only useful when within_group = FALSE.

sep

default TRUE; a character string to separate the group names after merging them into a new name.

Returns

res_group_distance stored in object.

Examples
\donttest{
t1$cal_group_distance(within_group = TRUE)
}

Method cal_group_distance_diff()

Differential test of distances among groups.

Usage
trans_beta$cal_group_distance_diff(
  group = NULL,
  by_group = NULL,
  by_ID = NULL,
  ...
)
Arguments
group

default NULL; a column name of object$res_group_distance used for the statistics; If NULL, use the group inside the object.

by_group

default 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_ID

default 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.

Returns

res_group_distance_diff stored in object.

Examples
\donttest{
t1$cal_group_distance_diff()
}

Method plot_group_distance()

Plotting the distance between samples within or between groups.

Usage
trans_beta$plot_group_distance(plot_group_order = NULL, ...)
Arguments
plot_group_order

default NULL; a vector used to order the groups in the plot.

...

parameters (except measure) passed to plot_alpha function of trans_alpha class.

Returns

ggplot.

Examples
\donttest{
t1$plot_group_distance()
}

Method plot_clustering()

Plotting clustering result based on the ggdendro package.

Usage
trans_beta$plot_clustering(
  color_values = RColorBrewer::brewer.pal(8, "Dark2"),
  measure = NULL,
  group = NULL,
  replace_name = NULL
)
Arguments
color_values

default RColorBrewer::brewer.pal(8, "Dark2"); color palette for the text.

measure

default NULL; beta diversity index; If NULL, using the measure when creating object

group

default NULL; if provided, use this group to assign color.

replace_name

default NULL; if provided, use this as label.

Returns

ggplot.

Examples
t1$plot_clustering(group = "Group", replace_name = c("Saline", "Type"))

Method clone()

The objects of this class are cloneable with this method.

Usage
trans_beta$clone(deep = FALSE)
Arguments
deep

Whether to make a deep clone.

Examples


## ------------------------------------------------
## Method `trans_beta$new`
## ------------------------------------------------

data(dataset)
t1 <- trans_beta$new(dataset = dataset, measure = "bray", group = "Group")

## ------------------------------------------------
## Method `trans_beta$cal_ordination`
## ------------------------------------------------

t1$cal_ordination(ordination = "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"))

microeco documentation built on Nov. 18, 2023, 9:06 a.m.