trans_alpha {microeco} | R Documentation |
Create trans_alpha
object for alpha diversity statistics and visualization.
Description
This class is a wrapper for a series of alpha diversity analysis, including the statistics and visualization.
Methods
Public methods
Method new()
Usage
trans_alpha$new( dataset = NULL, group = NULL, by_group = NULL, by_ID = NULL, order_x = NULL )
Arguments
dataset
an object of
microtable
class.group
default NULL; a column name of
sample_table
used for the statistics.by_group
default NULL; a column name of
sample_table
used to perform the differential test among groups (fromgroup
parameter) for each group (fromby_group
parameter) separately.by_ID
default NULL; a column name of
sample_table
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). Soby_ID
in sample_table should be the smallest unit of sample collection without any repetition in it.order_x
default NULL; a
sample_table
column name or a vector with sample names; if provided, order samples by usingfactor
.
Returns
data_alpha
and data_stat
stored in the object.
Examples
\donttest{ data(dataset) t1 <- trans_alpha$new(dataset = dataset, group = "Group") }
Method cal_diff()
Differential test on alpha diversity.
Usage
trans_alpha$cal_diff( measure = NULL, method = c("KW", "KW_dunn", "wilcox", "t.test", "anova", "scheirerRayHare", "lm", "lme", "betareg", "glmm", "glmm_beta")[1], formula = NULL, p_adjust_method = "fdr", KW_dunn_letter = TRUE, alpha = 0.05, anova_post_test = "duncan.test", return_model = FALSE, ... )
Arguments
measure
default NULL; character vector; If NULL, all indexes will be calculated; see names of
microtable$alpha_diversity
, e.g.c("Observed", "Chao1", "Shannon")
.method
default "KW"; see the following available options:
- 'KW'
Kruskal-Wallis Rank Sum Test for all groups (>= 2)
- 'KW_dunn'
Dunn's Kruskal-Wallis Multiple Comparisons <10.1080/00401706.1964.10490181> based on
dunnTest
function inFSA
package- 'wilcox'
Wilcoxon Rank Sum Test for all paired groups
- 't.test'
Student's t-Test for all paired groups
- 'anova'
Variance analysis. For one-way anova, the post hoc test is Duncan's new multiple range test based on
duncan.test
function ofagricolae
package. Please useanova_post_test
parameter to change post hoc method. For multi-way anova, Please useformula
parameter to specify the model and seeaov
for more details- 'scheirerRayHare'
Scheirer-Ray-Hare test (nonparametric test) for a two-way factorial experiment; see
scheirerRayHare
function ofrcompanion
package- 'lm'
Linear Model based on the
lm
function- 'lme'
Linear Mixed Effect Model based on the
lmerTest
package- 'betareg'
Beta Regression for Rates and Proportions based on the
betareg
package- 'glmm'
Generalized linear mixed model (GLMM) based on the
glmmTMB
package. A family function can be provided using parameter passing, such as:family = glmmTMB::lognormal(link = "log")
- 'glmm_beta'
Generalized linear mixed model (GLMM) with a family function of beta distribution. This is an extension of the GLMM model in
'glmm'
option. The only difference is inglmm_beta
the family function is fixed with the beta distribution function, facilitating the fitting for proportional data (ranging from 0 to 1). The link function is fixed with"logit"
.
formula
default NULL; applied to two-way or multi-factor anova when method =
"anova"
or"scheirerRayHare"
or"lme"
or"betareg"
or"glmm"
; specified set for independent variables, i.e. the latter part of a general formula, such as'block + N*P*K'
.p_adjust_method
default "fdr" (for "KW", "wilcox", "t.test" methods) or "holm" (for "KW_dunn"); P value adjustment method; For
method = 'KW', 'wilcox' or 't.test'
, please see method parameter ofp.adjust
function for available options; Formethod = 'KW_dunn'
, please seedunn.test::p.adjustment.methods
for available options.KW_dunn_letter
default TRUE; For
method = 'KW_dunn'
,TRUE
denotes paired significances are presented by letters;FALSE
means significances are shown by asterisk for paired comparison.alpha
default 0.05; Significant level; used for generating significance letters when method is 'anova' or 'KW_dunn'.
anova_post_test
default "duncan.test". The post hoc test method for one-way anova. Other available options include "LSD.test" and "HSD.test". All those are the function names in
agricolae
package.return_model
default FALSE; whether return the original lmer or glmm model list in the object.
...
parameters passed to
kruskal.test
(whenmethod = "KW"
) orwilcox.test
function (whenmethod = "wilcox"
) ordunnTest
function ofFSA
package (whenmethod = "KW_dunn"
) oragricolae::duncan.test
/agricolae::LSD.test
/agricolae::HSD.test
(whenmethod = "anova"
, one-way anova) orrcompanion::scheirerRayHare
(whenmethod = "scheirerRayHare"
) orlmerTest::lmer
(whenmethod = "lme"
) orbetareg::betareg
(whenmethod = "betareg"
) orglmmTMB::glmmTMB
(whenmethod = "glmm"
).
Returns
res_diff
, stored in object with the format data.frame
.
When method is "betareg", "lm", "lme" or "glmm",
"Estimate" and "Std.Error" columns represent the fitted coefficient and its standard error, respectively.
Examples
\donttest{ t1$cal_diff(method = "KW") t1$cal_diff(method = "anova") t1 <- trans_alpha$new(dataset = dataset, group = "Type", by_group = "Group") t1$cal_diff(method = "anova") }
Method plot_alpha()
Plot the alpha diversity. Box plot is used for the visualization of alpha diversity when the group
is found in the object.
Heatmap is employed automatically to show the significances of differential test
when the formula is found in the res_diff
table in the object.
Usage
trans_alpha$plot_alpha( color_values = RColorBrewer::brewer.pal(8, "Dark2"), measure = "Shannon", group = NULL, add_sig = TRUE, add_sig_label = "Significance", add_sig_text_size = 3.88, add_sig_label_num_dec = 4, boxplot_add = "jitter", order_x_mean = FALSE, y_start = 0.1, y_increase = 0.05, xtext_angle = 30, xtext_size = 13, ytitle_size = 17, barwidth = 0.9, use_boxplot = TRUE, plot_SE = TRUE, errorbar_size = 1, errorbar_width = 0.2, point_size = 3, point_alpha = 0.8, add_line = FALSE, line_size = 0.8, line_type = 2, line_color = "grey50", line_alpha = 0.5, heatmap_cell = "P.unadj", heatmap_sig = "Significance", heatmap_x = "Factors", heatmap_y = "Measure", heatmap_lab_fill = "P value", coefplot_sig_pos = 2, ... )
Arguments
color_values
default
RColorBrewer::brewer.pal
(8, "Dark2"); color pallete for groups.measure
default "Shannon"; one alpha diversity index in the object.
group
default NULL; group name used for the plot.
add_sig
default TRUE; wheter add significance label using the result of
cal_diff
function, i.e.object$res_diff
; This is manily designed to add post hoc test of anova or other significances to make the label mapping easy.add_sig_label
default "Significance"; select a colname of
object$res_diff
for the label text when 'Letter' is not in the table, such as 'P.adj' or 'Significance'.add_sig_text_size
default 3.88; the size of text in added label.
add_sig_label_num_dec
default 4; reserved decimal places when the parameter
add_sig_label
use numeric column, like 'P.adj'.boxplot_add
default "jitter"; points type, see the add parameter in
ggpubr::ggboxplot
.order_x_mean
default FALSE; whether order x axis by the means of groups from large to small.
y_start
default 0.1; the y axis value from which to add the significance asterisk label; the default 0.1 means
max(values) + 0.1 * (max(values) - min(values))
.y_increase
default 0.05; the increasing y axia space to add the label (asterisk or letter); the default 0.05 means
0.05 * (max(values) - min(values))
; this parameter is also used to label the letters of anova result with the fixed space.xtext_angle
default 30; number (e.g. 30) used to make x axis text generate angle.
xtext_size
default 13; x axis text size. NULL means the default size in ggplot2.
ytitle_size
default 17; y axis title size.
barwidth
default 0.9; the bar width in plot; applied when by_group is not NULL.
use_boxplot
default TRUE; TRUE denotes boxplot by using the data_alpha table in the object. FALSE represents mean-sd or mean-se plot by invoking the data_stat table in the object.
plot_SE
default TRUE; TRUE: the errorbar is
mean±se
; FALSE: the errorbar ismean±sd
.errorbar_size
default 1; errorbar size. Available when
use_boxplot = FALSE
.errorbar_width
default 0.2; errorbar width. Available when
use_boxplot = FALSE
andby_group
is NULL.point_size
default 3; point size for taxa. Available when
use_boxplot = FALSE
.point_alpha
default 0.8; point transparency. Available when
use_boxplot = FALSE
.add_line
default FALSE; whether add line. Available when
use_boxplot = FALSE
.line_size
default 0.8; line size when
add_line = TRUE
. Available whenuse_boxplot = FALSE
.line_type
default 2; an integer; line type when
add_line = TRUE
. Available whenuse_boxplot = FALSE
.line_color
default "grey50"; line color when
add_line = TRUE
. Available whenuse_boxplot = FALSE
andby_group
is NULL.line_alpha
default 0.5; line transparency when
add_line = TRUE
. Available whenuse_boxplot = FALSE
.heatmap_cell
default "P.unadj"; the column of
res_diff
table for the cell of heatmap when formula with multiple factors is found in the method.heatmap_sig
default "Significance"; the column of
res_diff
for the significance label of heatmap.heatmap_x
default "Factors"; the column of
res_diff
for the x axis of heatmap.heatmap_y
default "Taxa"; the column of
res_diff
for the y axis of heatmap.heatmap_lab_fill
default "P value"; legend title of heatmap.
coefplot_sig_pos
default 2; Significance label position in the coefficient point and errorbar plot. The formula is
Estimate + coefplot_sig_pos * Std.Error
. This plot is used when there is only one measure found in the table, and 'Estimate' and 'Std.Error' are both in the column names (such as forlm
andlme methods
). The x axis is 'Estimate', and y axis denotes 'Factors'. When coefplot_sig_pos is a negative value, the label is in the left of the errorbar. Errorbar size and width in the coefficient point plot can be adjusted with the parameterserrorbar_size
anderrorbar_width
. Point size and alpha can be adjusted with parameterspoint_size
andpoint_alpha
. The significance label size can be adjusted with parameteradd_sig_text_size
. Furthermore, the vertical line around 0 can be adjusted with parametersline_size
,line_type
,line_color
andline_alpha
....
parameters passing to
ggpubr::ggboxplot
function when box plot is used orplot_cor
function intrans_env
class for the heatmap of multiple factors when formula is found in theres_diff
of the object.
Returns
ggplot.
Examples
\donttest{ t1 <- trans_alpha$new(dataset = dataset, group = "Group") t1$cal_diff(method = "wilcox") t1$plot_alpha(measure = "Shannon", add_sig = TRUE) t1 <- trans_alpha$new(dataset = dataset, group = "Type", by_group = "Group") t1$cal_diff(method = "wilcox") t1$plot_alpha(measure = "Shannon", add_sig = TRUE) }
Method print()
Print the trans_alpha object.
Usage
trans_alpha$print()
Method clone()
The objects of this class are cloneable with this method.
Usage
trans_alpha$clone(deep = FALSE)
Arguments
deep
Whether to make a deep clone.
Examples
## ------------------------------------------------
## Method `trans_alpha$new`
## ------------------------------------------------
data(dataset)
t1 <- trans_alpha$new(dataset = dataset, group = "Group")
## ------------------------------------------------
## Method `trans_alpha$cal_diff`
## ------------------------------------------------
t1$cal_diff(method = "KW")
t1$cal_diff(method = "anova")
t1 <- trans_alpha$new(dataset = dataset, group = "Type", by_group = "Group")
t1$cal_diff(method = "anova")
## ------------------------------------------------
## Method `trans_alpha$plot_alpha`
## ------------------------------------------------
t1 <- trans_alpha$new(dataset = dataset, group = "Group")
t1$cal_diff(method = "wilcox")
t1$plot_alpha(measure = "Shannon", add_sig = TRUE)
t1 <- trans_alpha$new(dataset = dataset, group = "Type", by_group = "Group")
t1$cal_diff(method = "wilcox")
t1$plot_alpha(measure = "Shannon", add_sig = TRUE)