Last updated: 2024-06-19

Checks: 6 1

Knit directory: zinck-website/

This reproducible R Markdown analysis was created with workflowr (version 1.7.1). The Checks tab describes the reproducibility checks that were applied when the results were created. The Past versions tab lists the development history.


The R Markdown file has unstaged changes. To know which version of the R Markdown file created these results, you’ll want to first commit it to the Git repo. If you’re still working on the analysis, you can ignore this warning. When you’re finished, you can run wflow_publish to commit the R Markdown file and build the HTML.

Great job! The global environment was empty. Objects defined in the global environment can affect the analysis in your R Markdown file in unknown ways. For reproduciblity it’s best to always run the code in an empty environment.

The command set.seed(20240617) was run prior to running the code in the R Markdown file. Setting a seed ensures that any results that rely on randomness, e.g. subsampling or permutations, are reproducible.

Great job! Recording the operating system, R version, and package versions is critical for reproducibility.

Nice! There were no cached chunks for this analysis, so you can be confident that you successfully produced the results during this run.

Great job! Using relative paths to the files within your workflowr project makes it easier to run your code on other machines.

Great! You are using Git for version control. Tracking code development and connecting the code version to the results is critical for reproducibility.

The results in this page were generated with repository version d404602. See the Past versions tab to see a history of the changes made to the R Markdown and HTML files.

Note that you need to be careful to ensure that all relevant files for the analysis have been committed to Git prior to generating the results (you can use wflow_publish or wflow_git_commit). workflowr only checks the R Markdown file, but you know if there are other scripts or data files that it depends on. Below is the status of the Git repository when the results were generated:


Ignored files:
    Ignored:    .DS_Store

Unstaged changes:
    Modified:   analysis/Heatmaps.Rmd

Note that any generated files, e.g. HTML, png, CSS, etc., are not included in this status report because it is ok for generated content to have uncommitted changes.


These are the previous versions of the repository in which changes were made to the R Markdown (analysis/Heatmaps.Rmd) and HTML (docs/Heatmaps.html) files. If you’ve configured a remote Git repository (see ?wflow_git_remote), click on the hyperlinks in the table below to view the files as they were in that past version.

File Version Author Date Message
html 51a584c Patron 2024-06-18 Changed Heatmaps
Rmd 65fc471 Patron 2024-06-18 Updated Heatmaps
html ab6400d Patron 2024-06-18 Build and publish the website
Rmd a6c38f8 Patron 2024-06-18 Add home, experiment, and simulation pages

Comparing the Heatmaps for Original and Knockoff Sample Taxa Matrices

We demonstrate the ability of zinck to capture the compositional and highly sparse nature of microbiome count data by comparing the heatmaps of the original sample taxa matrix \(\mathbf{X}\) with its high quality knockoff copy, \(\tilde{\mathbf{X}}\).

We consider a toy setting with \(20\) samples and \(30\) taxa with the library size between \(400\) and \(500\) for each sample, for a high zero-inflation level of \(0.8\). We use the simulateZINLDA() function from the zinLDA package to generate the original sample taxa matrix.

library(zinck)
library(zinLDA)
library(ggplot2)
library(reshape2)
library(gridExtra)
library(cowplot)

set.seed(1) 
N.d=zinLDA::rdu(n=20,min=400,max=500) # Drawing random library sizes between 400, 500
sim_data = zinLDA::simulateZINLDA(D=20,V=30,N=N.d,K=5,Alpha=0.1,Pi=0.8,a=0.5,b=10)
X_original <- sim_data$sampleTaxaMatrix ## The original sample taxa count matrix


model_zinck <- fit.zinck(X_original, num_clusters=5, method="Gibbs", seed=1)
Theta <- model_zinck$theta
Beta <- model_zinck$beta

X_zinck <- generateKnockoff(X_original,Theta,Beta,seed=1)
rownames(X_zinck) <- rownames(X_original)

We will now visualize the heatmaps of the original matrix and its corresponding knockoff copy. The function applies an arcsinh transformation to the data for normalization and better visualization of abundance patterns and zero inflation within the sample taxa matrix.

draw.heatmap <- function(X, title="") {
  reshape2::melt(asinh(X)) %>%
    dplyr::rename(sample = Var1, taxa = Var2, asinh.abun = value) %>%
    ggplot2::ggplot(., aes (x = taxa, y = sample, fill = asinh.abun)) +
    ggplot2::geom_tile() + ggplot2::theme_bw() + ggplot2::ggtitle(title) +
    ggplot2::labs(fill = "arcsinh\nabundance") +
    ggplot2::theme(plot.title = element_text(hjust = 0.5),
                   axis.title.x=element_blank(), axis.title.y=element_blank(),
                   axis.text.x = element_text(size=3, angle=90), axis.text.y = element_text(size=4)) +
   viridis::scale_fill_viridis(discrete = FALSE, direction = -1, na.value = "grey") +
    theme(axis.title.x = element_blank(),axis.text.x = element_blank(),axis.ticks.x=element_blank(),
          axis.title.y = element_blank(),axis.text.y=element_blank(),axis.ticks.y=element_blank())+
    theme(panel.grid.major=element_blank(),panel.grid.minor = element_blank(),
          panel.background = element_blank(),panel.border = element_blank())+
    theme(legend.position="none") +
    ggplot2::coord_fixed(ratio = 1)  # Fixing the aspect ratio
}


heat1 <- draw.heatmap(X_original, "Original")
heat2 <- draw.heatmap(X_zinck, "Knockoff")
plot_grid(heat1, heat2, ncol = 2, align="v")

Version Author Date
51a584c Patron 2024-06-18

It is evident from the above heatmaps that the knockoff copy is almost indistinguishable from the original matrix! This underscores the fact that the knockoff copy preserves the underlying structure of the observed sample taxa count matrix.


sessionInfo()
R version 4.1.3 (2022-03-10)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Big Sur/Monterey 10.16

Matrix products: default
BLAS:   /Library/Frameworks/R.framework/Versions/4.1/Resources/lib/libRblas.0.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.1/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] cowplot_1.1.1     gridExtra_2.3     reshape2_1.4.4    ggplot2_3.4.2    
[5] zinLDA_0.0.0.9000 zinck_0.0.0.9000  workflowr_1.7.1  

loaded via a namespace (and not attached):
 [1] mcmc_0.9-7           matrixStats_0.63.0   fs_1.6.2            
 [4] httr_1.4.6           rprojroot_2.0.3      rstan_2.21.8        
 [7] tools_4.1.3          bslib_0.5.0          utf8_1.2.3          
[10] R6_2.5.1             DBI_1.1.3            colorspace_2.1-0    
[13] withr_2.5.0          tidyselect_1.2.0     prettyunits_1.1.1   
[16] processx_3.8.1       compiler_4.1.3       git2r_0.32.0        
[19] glmnet_4.1-7         cli_3.6.1            quantreg_5.95       
[22] SparseM_1.81         xml2_1.3.4           NLP_0.2-1           
[25] slam_0.1-50          sass_0.4.6           scales_1.2.1        
[28] tm_0.7-8             randomForest_4.7-1.1 callr_3.7.3         
[31] pbapply_1.7-2        stringr_1.5.0        digest_0.6.31       
[34] StanHeaders_2.21.0-7 rmarkdown_2.22       MCMCpack_1.6-3      
[37] pkgconfig_2.0.3      htmltools_0.5.5      highr_0.10          
[40] fastmap_1.1.1        rlang_1.1.1          rstudioapi_0.14     
[43] farver_2.1.1         shape_1.4.6          jquerylib_0.1.4     
[46] generics_0.1.3       jsonlite_1.8.5       dplyr_1.1.2         
[49] inline_0.3.19        magrittr_2.0.3       modeltools_0.2-23   
[52] loo_2.6.0            Matrix_1.5-1         Rcpp_1.0.10         
[55] munsell_0.5.0        fansi_1.0.4          viridis_0.6.5       
[58] lifecycle_1.0.3      stringi_1.7.12       whisker_0.4.1       
[61] yaml_2.3.7           MASS_7.3-60          pkgbuild_1.4.2      
[64] plyr_1.8.8           grid_4.1.3           parallel_4.1.3      
[67] promises_1.2.0.1     crayon_1.5.2         lattice_0.21-8      
[70] splines_4.1.3        knockoff_0.3.6       knitr_1.43          
[73] ps_1.7.5             pillar_1.9.0         topicmodels_0.2-14  
[76] codetools_0.2-19     stats4_4.1.3         glue_1.6.2          
[79] evaluate_0.21        getPass_0.2-2        RcppParallel_5.1.7  
[82] vctrs_0.6.5          httpuv_1.6.11        foreach_1.5.2       
[85] MatrixModels_0.5-1   gtable_0.3.3         cachem_1.0.8        
[88] xfun_0.39            coda_0.19-4          later_1.3.1         
[91] viridisLite_0.4.2    survival_3.5-5       tibble_3.2.1        
[94] iterators_1.0.14