### Import Qiime2 data using system.file paths Source: https://github.com/cafferychen777/microbiomestat/blob/main/docs/reference/mStat_import_qiime2_as_data_obj.html This example demonstrates importing Qiime2 data using file paths obtained via `system.file`. It assumes the necessary packages are installed. ```R otuqza_file <- system.file("extdata", "table.qza", package = "microbiomeMarker") taxaqza_file <- system.file("extdata", "taxonomy.qza", package = "microbiomeMarker") sample_file <- system.file("extdata", "sample-metadata.tsv", package = "microbiomeMarker") treeqza_file <- system.file("extdata", "tree.qza", package = "microbiomeMarker") data.obj <- mStat_import_qiime2_as_data_obj( otu_qza = otuqza_file, taxa_qza = taxaqza_file, sam_tab = sample_file, tree_qza = treeqza_file, ) ``` -------------------------------- ### Quick Start: Alpha Diversity Analysis Source: https://github.com/cafferychen777/microbiomestat/blob/main/README.md Demonstrates calculating and visualizing alpha diversity using example data. Requires loading the library and example data. ```r library(MicrobiomeStat) # Load example data data(peerj32.obj) # Alpha diversity alpha.obj <- mStat_calculate_alpha_diversity( peerj32.obj$feature.tab, alpha.name = c("shannon", "observed_species") ) generate_alpha_boxplot_single( data.obj = peerj32.obj, alpha.obj = alpha.obj, alpha.name = "shannon", subject.var = "subject", time.var = "time", t.level = "2", group.var = "group", strata.var = "sex" ) ``` -------------------------------- ### Install MicrobiomeStat from GitHub Source: https://github.com/cafferychen777/microbiomestat/blob/main/docs/index.html Install the development version of MicrobiomeStat directly from GitHub. This is recommended for users who need the latest features, especially for longitudinal data analysis. ```r devtools::install_github("cafferychen777/MicrobiomeStat") ``` -------------------------------- ### Example 2: Generate Volcano Plots with ECAM Data Source: https://github.com/cafferychen777/microbiomestat/blob/main/docs/reference/generate_taxa_volatility_volcano_long.html This example shows how to generate volcano plots using the `ecam.obj` dataset. Similar to the first example, it first obtains test results using `generate_taxa_volatility_test_long` and then generates the plots with `generate_taxa_volatility_volcano_long`. ```R data("ecam.obj") test.list <- generate_taxa_volatility_test_long( data.obj = ecam.obj, time.var = "month_num", subject.var = "subject.id", group.var = "antiexposedall", adj.vars = "delivery", prev.filter = 0.1, abund.filter = 0.0001, feature.level = c("Order", "Family", "Genus"), feature.dat.type = "proportion", transform = "CLR" ) plot.list <- generate_taxa_volatility_volcano_long( data.obj = ecam.obj, group.var = "antiexposedall", test.list = test.list, feature.sig.level = 0.1, feature.mt.method = "none" ) ``` -------------------------------- ### Generate Taxa Test Single Example Source: https://github.com/cafferychen777/microbiomestat/blob/main/docs/reference/generate_taxa_test_single.html This example demonstrates how to use the generate_taxa_test_single function with specified parameters. It also shows how to use the generate_taxa_volcano_single function with the results. ```R if (FALSE) { data(peerj32.obj) test.list <- generate_taxa_test_single( data.obj = peerj32.obj, time.var = "time", t.level = "2", group.var = "group", adj.vars = "sex", feature.dat.type = "count", feature.level = c("Phylum","Genus","Family"), prev.filter = 0.1, abund.filter = 0.0001, ) plot.list <- generate_taxa_volcano_single( data.obj = peerj32.obj, group.var = "group", test.list = test.list, feature.sig.level = 0.1, feature.mt.method = "none" ) } ``` -------------------------------- ### Example Usage of generate_beta_change_per_time_test_long Source: https://github.com/cafferychen777/microbiomestat/blob/main/docs/reference/generate_beta_change_per_time_test_long.html Demonstrates how to use generate_beta_change_per_time_test_long with a sample dataset. This example shows setting up the necessary parameters like time, subject, and group variables, and specifying beta diversity indices. ```R data(subset_T2D.obj) result1 <- generate_beta_change_per_time_test_long( data.obj = subset_T2D.obj, dist.obj = NULL, time.var = "visit_number_num", t0.level = unique(subset_T2D.obj$meta.dat$visit_number_num)[1], ts.levels = unique(subset_T2D.obj$meta.dat$visit_number_num)[-1], subject.var = "subject_id", group.var = "subject_race", adj.vars = NULL, dist.name = c('BC', 'Jaccard') ) # Visualizing the results for the Type 2 Diabetes dataset dotplot_T2D <- generate_beta_per_time_dotplot_long( data.obj = subset_T2D.obj, test.list = result1, ``` -------------------------------- ### Example 1: Generate Volcano Plots with Subset T2D Data Source: https://github.com/cafferychen777/microbiomestat/blob/main/docs/reference/generate_taxa_volatility_volcano_long.html This example demonstrates how to generate volcano plots using the `subset_T2D.obj` dataset. It first calls `generate_taxa_volatility_test_long` to get the test results and then uses `generate_taxa_volatility_volcano_long` to create the plots. ```R data("subset_T2D.obj") test.list <- generate_taxa_volatility_test_long( data.obj = subset_T2D.obj, time.var = "visit_number", subject.var = "subject_id", group.var = "subject_race", adj.vars = "sample_body_site", prev.filter = 0.1, abund.filter = 0.0001, feature.level = c("Order", "Family", "Genus"), feature.dat.type = "count", transform = "CLR" ) plot.list <- generate_taxa_volatility_volcano_long(data.obj = subset_T2D.obj, group.var = "subject_race", test.list = test.list, feature.sig.level = 0.1, feature.mt.method = "none") ``` -------------------------------- ### Example Usage with peerj32.obj Dataset Source: https://github.com/cafferychen777/microbiomestat/blob/main/docs/reference/generate_beta_pc_boxplot_long.html Illustrates the use of the generate_beta_pc_boxplot_long function with the peerj32.obj dataset. This example is a placeholder and would typically include specific parameters for data analysis and plotting. ```r data(peerj32.obj) ``` -------------------------------- ### Generate Beta Trend Test Long Example 1 Source: https://github.com/cafferychen777/microbiomestat/blob/main/docs/reference/generate_beta_trend_test_long.html This example demonstrates calling generate_beta_trend_test_long with specified adjusted variables and distance metrics. ```R data(subset_T2D.obj) generate_beta_trend_test_long( data.obj = subset_T2D.obj, dist.obj = NULL, subject.var = "subject_id", time.var = "visit_number", group.var = "subject_race", adj.vars = c("subject_gender","sample_body_site"), dist.name = c("BC", "Jaccard") ) ``` -------------------------------- ### Example Usage of generate_taxa_change_dotplot_pair Source: https://github.com/cafferychen777/microbiomestat/blob/main/docs/reference/generate_taxa_change_dotplot_pair.html Illustrates how to call the generate_taxa_change_dotplot_pair function. This example is within a \`dontrun\` block, indicating it's for reference and not automatically executed. ```R if (FALSE) { # \`dontrun\` ``` -------------------------------- ### Quick Start: Beta Diversity Ordination Source: https://github.com/cafferychen777/microbiomestat/blob/main/README.md Demonstrates generating a beta diversity ordination plot for a single sample group using example data. Requires relevant data objects and variables. ```r generate_beta_ordination_single( data.obj = peerj32.obj, dist.obj = NULL, pc.obj = NULL, subject.var = "subject", time.var = "time", t.level = "2", group.var = "group", strata.var = "sex", dist.name = "BC" ) ``` -------------------------------- ### Generate Taxa Change Heatmap Pair Example Source: https://github.com/cafferychen777/microbiomestat/blob/main/docs/reference/generate_taxa_change_heatmap_pair.html This example demonstrates how to use the generate_taxa_change_heatmap_pair function with specified parameters to visualize taxa changes. Ensure the subset_pairs.obj is loaded before running. ```R data(subset_pairs.obj) generate_taxa_change_heatmap_pair( data.obj = subset_pairs.obj, subject.var = "MouseID", time.var = "Antibiotic", group.var = "Sex", strata.var = NULL, change.base = "Baseline", feature.change.func = "relative change", feature.level = c("Genus"), feature.dat.type = "count", features.plot = NULL, top.k.plot = 10, top.k.func = "sd", prev.filter = 0.1, abund.filter = 0.001, base.size = 10, palette = NULL, cluster.rows = FALSE, cluster.cols = FALSE, pdf = TRUE, file.ann = NULL, pdf.wid = 11, pdf.hei = 8.5 ) ``` ```R generate_taxa_change_heatmap_pair( data.obj = subset_pairs.obj, subject.var = "MouseID", time.var = "Antibiotic", group.var = "Sex", strata.var = NULL, change.base = "Baseline", feature.change.func = "relative change", feature.level = c("Genus"), feature.dat.type = "count", features.plot = NULL, top.k.plot = 10, top.k.func = "sd", prev.filter = 0.1, abund.filter = 0.001, base.size = 10, palette = NULL, cluster.rows = NULL, cluster.cols = FALSE, pdf = TRUE, file.ann = NULL, pdf.wid = 11, pdf.hei = 8.5 ) ``` ```R generate_taxa_change_heatmap_pair( data.obj = subset_pairs.obj, subject.var = "MouseID", time.var = "Antibiotic", group.var = "Sex", strata.var = NULL, change.base = "Baseline", feature.change.func = "relative change", feature.level = c("Genus"), feature.dat.type = "count", features.plot = NULL, top.k.plot = 10, top.k.func = "sd", prev.filter = 0.1, abund.filter = 0.001, base.size = 10, palette = NULL, cluster.rows = FALSE, cluster.cols = FALSE, pdf = TRUE, file.ann = NULL, pdf.wid = 11, pdf.hei = 8.5 ) ``` -------------------------------- ### Generate Single Taxa Dotplot Example Source: https://github.com/cafferychen777/microbiomestat/blob/main/docs/reference/generate_taxa_dotplot_single.html Example of how to load necessary libraries, prepare data, and call the generate_taxa_dotplot_single function. This demonstrates basic usage with specified subject and time variables. ```r # Load required libraries library(vegan) library(ggh4x) data(peerj32.obj) # Call the function generate_taxa_dotplot_single( data.obj = peerj32.obj, subject.var = "subject", time.var = "time", ) ``` -------------------------------- ### Generate Beta Change Boxplot with Example Data Source: https://github.com/cafferychen777/microbiomestat/blob/main/docs/reference/generate_beta_change_boxplot_long.html This example demonstrates how to use generate_beta_change_boxplot_long with the peerj32.obj dataset, specifying subject, time, and group variables, along with other aesthetic and output parameters. ```R library(vegan) data(peerj32.obj) dist.obj <- mStat_calculate_beta_diversity(peerj32.obj, dist.name = "BC") generate_beta_change_boxplot_long( data.obj = peerj32.obj, dist.obj = NULL, subject.var = "subject", time.var = "time", group.var = "group", strata.var = "sex", adj.vars = "sex", t0.level = "1", dist.name = c('BC'), base.size = 20, theme.choice = "bw", custom.theme = NULL, palette = "lancet", pdf = TRUE, file.ann = NULL, pdf.wid = 11, pdf.hei = 8.5 ) ``` -------------------------------- ### Example Usage of generate_beta_pc_spaghettiplot_long Source: https://github.com/cafferychen777/microbiomestat/blob/main/docs/reference/generate_beta_pc_spaghettiplot_long.html Demonstrates how to use the `generate_beta_pc_spaghettiplot_long` function with the `ecam.obj` dataset. This example calculates beta diversity and PC, then plots the spaghetti plot, specifying subject, time, group, and strata variables, along with theme choice. ```R library(vegan) # Example with ecam.obj dataset data(ecam.obj) dist.obj <- mStat_calculate_beta_diversity(ecam.obj, "BC") pc.obj <- mStat_calculate_PC(dist.obj) generate_beta_pc_spaghettiplot_long( data.obj = ecam.obj, dist.obj = NULL, pc.obj = NULL, subject.var = "studyid", time.var = "month", t0.level = "0", ts.levels = as.character(sort(as.numeric(unique(ecam.obj$meta.dat$month))))[2:10], group.var = "diet", strata.var = "delivery", adj.vars = NULL, dist.name = c('BC'), base.size = 20, theme.choice = "bw", custom.theme = NULL, ``` -------------------------------- ### Custom ggplot Theme Example Source: https://github.com/cafferychen777/microbiomestat/blob/main/docs/reference/generate_alpha_per_time_dotplot_long.html Provides an example of how to create a custom ggplot theme object for plot customization. This allows for fine-grained control over plot elements like axis titles, text, legend, and panel backgrounds. ```R my_theme <- ggplot2::theme( axis.title = ggplot2::element_text(size=14, face="bold"), axis.text = ggplot2::element_text(size=12), legend.position = "top", legend.background = ggplot2::element_rect(fill="lightgray"), panel.background = ggplot2::element_rect(fill="white", colour="black"), panel.grid.major = ggplot2::element_line(colour = "grey90"), panel.grid.minor = ggplot2::element_blank(), plot.title = ggplot2::element_text(size=16, hjust=0.5) ) ``` -------------------------------- ### Custom ggplot2 Theme Example Source: https://github.com/cafferychen777/microbiomestat/blob/main/docs/reference/mStat_generate_report_change_pair.html This example demonstrates how to create and apply a custom ggplot2 theme to override default plotting styles. Pass the created theme object to the 'custom.theme' argument of the mStat functions. ```r my_theme <- ggplot2::theme( axis.title = ggplot2::element_text(size=16, color="red"), legend.position = "none" ) ``` -------------------------------- ### Generate Alpha Diversity Spaghetti Plot (Partial Example) Source: https://github.com/cafferychen777/microbiomestat/blob/main/docs/reference/generate_alpha_spaghettiplot_long.html A partial example for generating alpha diversity spaghetti plots, demonstrating the function call with data object and alpha diversity names. Assumes internal calculation of alpha diversity. ```R generate_alpha_spaghettiplot_long( data.obj = ecam.obj, alpha.obj = NULL, alpha.name = c("shannon","simpson", "observed_species"), ``` -------------------------------- ### Example 1: Analyze ECAM dataset for delivery method impact over months Source: https://github.com/cafferychen777/microbiomestat/blob/main/docs/reference/generate_taxa_test_long.html Demonstrates analyzing the ECAM dataset to understand the impact of delivery method on microbial composition over months. Requires the ecam.obj dataset and generates a dotplot for visualization. ```R # Example 1: Analyzing the ECAM dataset data("ecam.obj") # Analyzing the impact of delivery method on microbial composition over months result1 <- generate_taxa_test_long( data.obj = ecam.obj, subject.var = "studyid", time.var = "month_num", group.var = "delivery", adj.vars = "diet", feature.level = c("Phylum", "Class"), feature.dat.type = "proportion" ) # Visualizing the results for the ECAM dataset dotplot_ecam <- generate_taxa_dotplot_long( data.obj = ecam.obj, time.test.list = result1, group.var = "delivery", time.var = "month_num", feature.level = c("Phylum", "Class") ) ``` -------------------------------- ### Example: Generate Beta Diversity Change Test Pair Source: https://github.com/cafferychen777/microbiomestat/blob/main/docs/reference/generate_beta_change_test_pair.html Demonstrates how to use the generate_beta_change_test_pair function with sample data. Ensure necessary packages are loaded and data objects are correctly formatted. ```R # Load packages library(vegan) # Load data data(peerj32.obj) generate_beta_change_test_pair( data.obj = peerj32.obj, dist.obj = NULL, time.var = "time", subject.var = "subject", group.var = "group", adj.vars = NULL, ``` -------------------------------- ### Generate Beta Ordination Pair with Default Settings Source: https://github.com/cafferychen777/microbiomestat/blob/main/docs/reference/generate_beta_ordination_pair.html This example demonstrates how to use `generate_beta_ordination_pair` with a loaded dataset and default parameters. Ensure the `vegan` library is loaded and the data object is available. The output is saved to a PDF file. ```R library(vegan) data(peerj32.obj) generate_beta_ordination_pair( data.obj = peerj32.obj, dist.obj = NULL, pc.obj = NULL, subject.var = "subject", time.var = "time", group.var = "group", strata.var = "sex", adj.vars = "sex", dist.name = c("BC"), base.size = 16, theme.choice = "bw", custom.theme = NULL, palette = NULL, pdf = TRUE, file.ann = NULL, pdf.wid = 11, pdf.hei = 8.5 ) ``` -------------------------------- ### Plot linda results Source: https://github.com/cafferychen777/microbiomestat/blob/main/docs/reference/linda.plot.html This example demonstrates how to use the linda.plot function to visualize results from the linda function. It involves subsetting data, running linda, and then plotting the results. Ensure the 'ggrepel' package is installed for enhanced plotting. ```R library(ggrepel) data(smokers) ind <- smokers$meta$AIRWAYSITE == "Throat" ului <- smokers$otu[, ind] meta <- cbind.data.frame( Smoke = factor(smokers$meta$SMOKER[ind]), Sex = factor(smokers$meta$SEX[ind]), Site = factor(smokers$meta$SIDEOFBODY[ind]), SubjectID = factor(smokers$meta$HOST_SUBJECT_ID[ind]) ) ind1 <- which(meta$Site == "Left") res.left <- linda(otu.tab[, ind1], meta[ind1, ], formula = "~Smoke+Sex" ) ind2 <- which(meta$Site == "Right") res.right <- linda(otu.tab[, ind2], meta[ind2, ], formula = "~Smoke+Sex" ) rownames(res.left$output[[1]])[which(res.left$output[[1]]$reject)] rownames(res.right$output[[1]])[which(res.right$output[[1]]$reject)] linda.obj <- linda(otu.tab, meta, formula = "~Smoke+Sex+(1|SubjectID)" ) ``` -------------------------------- ### Generate Beta PC Volatility Test Long Format Example Source: https://github.com/cafferychen777/microbiomestat/blob/main/docs/reference/generate_beta_pc_volatility_test_long.html Demonstrates how to use the `generate_beta_pc_volatility_test_long` function with sample data. Ensure the necessary libraries are loaded and data objects are correctly formatted. ```R library(vegan) data(ecam.obj) generate_beta_pc_volatility_test_long( data.obj = ecam.obj, dist.obj = NULL, pc.obj = NULL, pc.ind = c(1, 2), subject.var = "studyid", time.var = "month", group.var = "diet", adj.vars = NULL, dist.name = c('BC') ) ``` -------------------------------- ### Install devtools Package Source: https://github.com/cafferychen777/microbiomestat/blob/main/docs/index.html Before installing MicrobiomeStat from GitHub, ensure the devtools package is installed. This package provides tools for package development and installation from various sources. ```r install.packages("devtools") ``` -------------------------------- ### Install MicrobiomeStat from CRAN Source: https://github.com/cafferychen777/microbiomestat/blob/main/README.md Install the stable version of the MicrobiomeStat package from the Comprehensive R Archive Network (CRAN). ```r install.packages("MicrobiomeStat") ``` -------------------------------- ### Generate Beta Trend Test Long Example 2 Source: https://github.com/cafferychen777/microbiomestat/blob/main/docs/reference/generate_beta_trend_test_long.html This example shows calling generate_beta_trend_test_long without specifying a group variable or adjusted variables. ```R generate_beta_trend_test_long( data.obj = subset_T2D.obj, dist.obj = NULL, subject.var = "subject_id", time.var = "visit_number", group.var = NULL, adj.vars = NULL, dist.name = c("BC", "Jaccard") ) ``` -------------------------------- ### Perform PERMANOVA with pre-calculated distance matrix Source: https://github.com/cafferychen777/microbiomestat/blob/main/docs/reference/generate_beta_test_single.html This example demonstrates performing PERMANOVA using a pre-calculated distance matrix. Ensure the distance matrix is correctly computed and passed to the dist.obj argument. ```R dist.obj <- mStat_calculate_beta_diversity(ecam.obj, dist.name = c('BC', 'Jaccard')) generate_beta_test_single( data.obj = ecam.obj, dist.obj = dist.obj, time.var = "month", t.level = "1", group.var = "delivery", adj.vars = "diet" ) ``` -------------------------------- ### Import DADA2 Data into MicrobiomeStat Object Source: https://github.com/cafferychen777/microbiomestat/blob/main/docs/reference/mStat_import_dada2_as_data_obj.html This example demonstrates how to load DADA2 output files (sequence table, taxonomy table, sample metadata) and convert them into a MicrobiomeStat data object using the mStat_import_dada2_as_data_obj function. Ensure necessary libraries are loaded and data files are accessible. ```R library(Biostrings) seq_tab <- readRDS( system.file( "extdata", "dada2_seqtab.rds", package = "microbiomeMarker" ) ) tax_tab <- readRDS( system.file( "extdata", "dada2_taxtab.rds", package = "microbiomeMarker" ) ) sam_tab <- read.table( system.file( "extdata", "dada2_samdata.txt", package = "microbiomeMarker" ), sep = "\t", header = TRUE, row.names = 1 ) data_obj <- mStat_import_dada2_as_data_obj(seq_tab = seq_tab, tax_tab = tax_tab, sam_tab = sam_tab) ``` -------------------------------- ### Convert DGEList to MicrobiomeStat Data Object Source: https://github.com/cafferychen777/microbiomestat/blob/main/docs/reference/mStat_convert_DGEList_to_data_obj.html This example demonstrates loading necessary libraries, preparing a DGEList object from a DESeq2 dataset, and then converting it into a MicrobiomeStat data object. The conversion retains only features with a sum greater than 0. ```R if (FALSE) { # \dontrun! { # Load necessary packages # library(airway) # library(DESeq2) # library(edgeR) # Load dataset # data("airway") # dds <- DESeqDataSet(airway, design = ~ cell + dex) # dge <- DGEList(counts = counts(dds), group = dds$dex) # Convert to MicrobiomeStat data object # data.obj <- mStat_convert_DGEList_to_data_obj(dge) } # } ``` -------------------------------- ### Subset Distance Matrix Example Source: https://github.com/cafferychen777/microbiomestat/blob/main/docs/reference/mStat_subset_dist.html Demonstrates how to calculate beta diversity and then subset the resulting distance object by selected sample IDs. Ensure required libraries are loaded and data is available. ```R library(vegan) data(peerj32.obj) # Calculate beta diversity dist.obj <- mStat_calculate_beta_diversity(peerj32.obj, dist.name = c('BC', 'Jaccard')) # Select sample IDs sample_ids <- sample(colnames(peerj32.obj$feature.tab), 10) # Subset distance object by sample IDs subsetted_dist.obj <- mStat_subset_dist(dist.obj, sample_ids) ``` -------------------------------- ### Convert phyloseq to MicrobiomeStat data object Source: https://github.com/cafferychen777/microbiomestat/blob/main/docs/reference/mStat_convert_phyloseq_to_data_obj.html This example demonstrates how to convert a phyloseq object to a MicrobiomeStat data object. Ensure necessary libraries like 'microbiome' and 'phangorn' are loaded if dealing with phylogenetic trees. ```R if (FALSE) { # \dontrun{ #library(microbiome) # Load phangorn for midpoint rooting if tree is present #library(phangorn) #data(peerj32) #peerj32.phy <- peerj32$phyloseq #data.obj <- mStat_convert_phyloseq_to_data_obj(peerj32.phy) } # } ``` -------------------------------- ### Example 4: Test trend without group variable Source: https://github.com/cafferychen777/microbiomestat/blob/main/docs/reference/generate_alpha_trend_test_long.html This example demonstrates testing trends for 'shannon' and 'observed_species' alpha diversity indices without specifying a group variable. ```R result4 <- generate_alpha_trend_test_long( data.obj = subset_T2D.obj, ``` -------------------------------- ### Example 2: Test trend with group and one adjustment covariate Source: https://github.com/cafferychen777/microbiomestat/blob/main/docs/reference/generate_alpha_trend_test_long.html This example tests trends for 'shannon' and 'observed_species' alpha diversity, including a group variable and adjusting for 'subject_gender'. ```R result2 <- generate_alpha_trend_test_long( data.obj = subset_T2D.obj, alpha.name = c("shannon", "observed_species"), time.var = "visit_number_num", subject.var = "subject_id", group.var = "subject_race", adj.vars = "subject_gender" ) ```