Last updated: 2023-02-22

Checks: 7 0

Knit directory: gsmash/

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


Great! Since the R Markdown file has been committed to the Git repository, you know the exact version of the code that produced these results.

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(20220606) 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 6fde94a. 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:    .Rhistory
    Ignored:    .Rproj.user/

Untracked files:
    Untracked:  analysis/compare_vga_iterations_pbmc_full.Rmd
    Untracked:  output/pbmc3k_k1.rds
    Untracked:  output/pbmc3k_k1_S1.rds

Unstaged changes:
    Modified:   analysis/index.Rmd
    Modified:   analysis/overdispersed_splitting.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/pbmc_infasttopics_init_vga_effect.Rmd) and HTML (docs/pbmc_infasttopics_init_vga_effect.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
Rmd 6fde94a DongyueXie 2023-02-22 wflow_publish("analysis/pbmc_infasttopics_init_vga_effect.Rmd")
html 14227f2 DongyueXie 2023-02-22 Build site.
Rmd 9b184cb DongyueXie 2023-02-22 wflow_publish("analysis/pbmc_infasttopics_init_vga_effect.Rmd")

Conclusion

At iter 20

x = cbind(c(-9020841,-8970580,-8941787,-8938047,-8907999,-8943078),
          c(0.1124,0.1951,0.4025,0.8480,1.5271,2.3999),
          c(7,7,8,8,10,10),
          c(20,20,20,20,20,20))
colnames(x) = c('elbo','var','K','iter')
knitr::kable(x)
elbo var K iter
-9020841 0.1124 7 20
-8970580 0.1951 7 20
-8941787 0.4025 8 20
-8938047 0.8480 8 20
-8907999 1.5271 10 20
-8943078 2.3999 10 20

At convergence.

x = cbind(c(-8900823,-8870821,-8846708,-8895574),
          c(0.3987,0.7643,1.3230,2.2076),
          c(8,11,10,10),
          c(60,60,60,35))
colnames(x) = c('elbo','var','K','iter')
knitr::kable(x)
elbo var K iter
-8900823 0.3987 8 60
-8870821 0.7643 11 60
-8846708 1.3230 10 60
-8895574 2.2076 10 35

Introduction

Recall the initialization of ebpmf is based on solving an poisson mean problem with normal prior. And when the prior mean is negative, and the data vector is very sparse, the estimated variance tends to be very small. Here I I study how the results differ for different init variance values.

source("code/poisson_STM/structure_plot.R")
library(fastTopics)
library(Matrix)
data("pbmc_facs")
counts = pbmc_facs$counts
counts = counts[,colSums(counts!=0)>10]

We start with smallest variances. The scale of \(\sigma^2\) is achieved by alternating the convergence tolerance in initialization. The smaller the tolerance, the smaller \(\sigma^2\) converges to.

1e-10

For the first case I set tol=\(1e-10\). I only have 20 iterations because an error occurred.

fit = readRDS('/project2/mstephens/dongyue/poisson_mf/pbmc_fasttopics/init_tol_effect/nonnegLF_pe_inittol1e10_iter20.rds')
fit$elbo
[1] -9020841
plot(fit$K_trace)

Version Author Date
14227f2 DongyueXie 2023-02-22
hist(fit$sigma2,breaks = 100)

Version Author Date
14227f2 DongyueXie 2023-02-22
summary(fit$sigma2)
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
 0.0113  0.0713  0.1124  0.1649  0.2050  2.0224 
p=structure_plot_general(fit$fit_flash$L.pm,fit$fit_flash$F.pm,pbmc_facs$samples$subpop,title='1e-10,iter20')
Running tsne on 417 x 5 matrix.
Running tsne on 91 x 5 matrix.
Running tsne on 358 x 5 matrix.
Running tsne on 359 x 5 matrix.
Running tsne on 775 x 5 matrix.

Version Author Date
14227f2 DongyueXie 2023-02-22
plot(fit$sigma2,colSums(counts/rowSums(counts)),pch=20,col='grey80')

Version Author Date
14227f2 DongyueXie 2023-02-22

1e-8

For the first case I set tol=\(1e-8\). I only have 20 iterations because an error occurred.

fit = readRDS('/project2/mstephens/dongyue/poisson_mf/pbmc_fasttopics/init_tol_effect/nonnegLF_pe_inittol1e8_iter20.rds')
fit$elbo
[1] -8970580
plot(fit$K_trace)

Version Author Date
14227f2 DongyueXie 2023-02-22
hist(fit$sigma2,breaks = 100)

Version Author Date
14227f2 DongyueXie 2023-02-22
summary(fit$sigma2)
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
0.01657 0.13547 0.19515 0.22596 0.27370 2.02912 
p=structure_plot_general(fit$fit_flash$L.pm,fit$fit_flash$F.pm,pbmc_facs$samples$subpop,title='1e-8,iter20')
Running tsne on 417 x 5 matrix.
Running tsne on 91 x 5 matrix.
Running tsne on 358 x 5 matrix.
Running tsne on 359 x 5 matrix.
Running tsne on 775 x 5 matrix.

Version Author Date
14227f2 DongyueXie 2023-02-22
plot(fit$sigma2,colSums(counts/rowSums(counts)),pch=20,col='grey80')

Version Author Date
14227f2 DongyueXie 2023-02-22

1e-6

I have 60 iterations. But for comparison, I also include iter=20 results here.

fit = readRDS('/project2/mstephens/dongyue/poisson_mf/pbmc_fasttopics/init_tol_effect/nonnegLF_pe_inittol1e6_iter20.rds')
fit$elbo
[1] -8941787
plot(fit$K_trace)

Version Author Date
14227f2 DongyueXie 2023-02-22
hist(fit$sigma2,breaks = 100)

Version Author Date
14227f2 DongyueXie 2023-02-22
summary(fit$sigma2)
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
0.01869 0.27130 0.40253 0.43056 0.56779 2.00395 
p=structure_plot_general(fit$fit_flash$L.pm,fit$fit_flash$F.pm,pbmc_facs$samples$subpop,title='1e-6,iter20')
Running tsne on 417 x 6 matrix.
Running tsne on 91 x 6 matrix.
Running tsne on 358 x 6 matrix.
Running tsne on 359 x 6 matrix.
Running tsne on 775 x 6 matrix.

Version Author Date
14227f2 DongyueXie 2023-02-22
plot(fit$sigma2,colSums(counts/rowSums(counts)),pch=20,col='grey80')

Version Author Date
14227f2 DongyueXie 2023-02-22
fit = readRDS('/project2/mstephens/dongyue/poisson_mf/pbmc_fasttopics/init_tol_effect/nonnegLF_pe_inittol1e6_iter60.rds')
fit$elbo
[1] -8900823
plot(fit$K_trace)

Version Author Date
14227f2 DongyueXie 2023-02-22
hist(fit$sigma2,breaks = 100)

Version Author Date
14227f2 DongyueXie 2023-02-22
summary(fit$sigma2)
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
0.01488 0.27523 0.39879 0.42636 0.55457 2.98685 
p=structure_plot_general(fit$fit_flash$L.pm,fit$fit_flash$F.pm,pbmc_facs$samples$subpop,title='1e-6,iter60')
Running tsne on 417 x 6 matrix.
Running tsne on 91 x 6 matrix.
Running tsne on 358 x 6 matrix.
Running tsne on 359 x 6 matrix.
Running tsne on 775 x 6 matrix.

Version Author Date
14227f2 DongyueXie 2023-02-22
plot(fit$sigma2,colSums(counts/rowSums(counts)),pch=20,col='grey80')

Version Author Date
14227f2 DongyueXie 2023-02-22

1e-4

I have 60 iterations. But for comparison, I also include iter=20 results here.

fit = readRDS('/project2/mstephens/dongyue/poisson_mf/pbmc_fasttopics/init_tol_effect/nonnegLF_pe_inittol1e4_iter20.rds')
fit$elbo
[1] -8938047
plot(fit$K_trace)

Version Author Date
14227f2 DongyueXie 2023-02-22
hist(fit$sigma2,breaks = 100)

Version Author Date
14227f2 DongyueXie 2023-02-22
summary(fit$sigma2)
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
0.02164 0.55605 0.84809 0.89912 1.21483 2.05869 
p=structure_plot_general(fit$fit_flash$L.pm,fit$fit_flash$F.pm,pbmc_facs$samples$subpop,title='1e-4,iter20')
Running tsne on 417 x 6 matrix.
Running tsne on 91 x 6 matrix.
Running tsne on 358 x 6 matrix.
Running tsne on 359 x 6 matrix.
Running tsne on 775 x 6 matrix.

Version Author Date
14227f2 DongyueXie 2023-02-22
plot(fit$sigma2,colSums(counts/rowSums(counts)),pch=20,col='grey80')

Version Author Date
14227f2 DongyueXie 2023-02-22
fit = readRDS('/project2/mstephens/dongyue/poisson_mf/pbmc_fasttopics/init_tol_effect/nonnegLF_pe_inittol1e4_iter60.rds')
fit$elbo
[1] -8870821
plot(fit$K_trace)

Version Author Date
14227f2 DongyueXie 2023-02-22
hist(fit$sigma2,breaks = 100)

Version Author Date
14227f2 DongyueXie 2023-02-22
summary(fit$sigma2)
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
0.01459 0.51538 0.76435 0.79266 1.05284 3.05459 
p=structure_plot_general(fit$fit_flash$L.pm,fit$fit_flash$F.pm,pbmc_facs$samples$subpop,title='1e-4,iter60')
Running tsne on 417 x 9 matrix.
Running tsne on 91 x 9 matrix.
Running tsne on 358 x 9 matrix.
Running tsne on 359 x 9 matrix.
Running tsne on 775 x 9 matrix.

Version Author Date
14227f2 DongyueXie 2023-02-22
plot(fit$sigma2,colSums(counts/rowSums(counts)),pch=20,col='grey80')

Version Author Date
14227f2 DongyueXie 2023-02-22

1e-2

I have 60 iterations. But for comparison, I also include iter=20 results here.

fit = readRDS('/project2/mstephens/dongyue/poisson_mf/pbmc_fasttopics/init_tol_effect/nonnegLF_pe_inittol1e2_iter20.rds')
fit$elbo
[1] -8907999
plot(fit$K_trace)

Version Author Date
14227f2 DongyueXie 2023-02-22
hist(fit$sigma2,breaks = 100)

Version Author Date
14227f2 DongyueXie 2023-02-22
summary(fit$sigma2)
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
0.01852 1.07197 1.52718 1.53082 1.97999 2.90007 
p=structure_plot_general(fit$fit_flash$L.pm,fit$fit_flash$F.pm,pbmc_facs$samples$subpop,title='1e-2,iter20')
Running tsne on 417 x 8 matrix.
Running tsne on 91 x 8 matrix.
Running tsne on 358 x 8 matrix.
Running tsne on 359 x 8 matrix.
Running tsne on 775 x 8 matrix.

Version Author Date
14227f2 DongyueXie 2023-02-22
plot(fit$sigma2,colSums(counts/rowSums(counts)),pch=20,col='grey80')

Version Author Date
14227f2 DongyueXie 2023-02-22
fit = readRDS('/project2/mstephens/dongyue/poisson_mf/pbmc_fasttopics/init_tol_effect/nonnegLF_pe_inittol1e2_iter60.rds')
fit$elbo
[1] -8846708
plot(fit$K_trace)

Version Author Date
14227f2 DongyueXie 2023-02-22
hist(fit$sigma2,breaks = 100)

Version Author Date
14227f2 DongyueXie 2023-02-22
summary(fit$sigma2)
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
 0.0141  0.8932  1.3230  1.2782  1.6644  3.0520 
p=structure_plot_general(fit$fit_flash$L.pm,fit$fit_flash$F.pm,pbmc_facs$samples$subpop,title='1e-2,iter60')
Running tsne on 417 x 8 matrix.
Running tsne on 91 x 8 matrix.
Running tsne on 358 x 8 matrix.
Running tsne on 359 x 8 matrix.
Running tsne on 775 x 8 matrix.

Version Author Date
14227f2 DongyueXie 2023-02-22
plot(fit$sigma2,colSums(counts/rowSums(counts)),pch=20,col='grey80')

Version Author Date
14227f2 DongyueXie 2023-02-22

1e-1

I have 35 iterations. But for comparison, I also include iter=20 results here.

fit = readRDS('/project2/mstephens/dongyue/poisson_mf/pbmc_fasttopics/init_tol_effect/nonnegLF_pe_inittol1e1_iter20.rds')
fit$elbo
[1] -8943078
plot(fit$K_trace)

hist(fit$sigma2,breaks = 100)

summary(fit$sigma2)
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
0.01857 1.74882 2.39991 2.19174 2.72651 3.46886 
p=structure_plot_general(fit$fit_flash$L.pm,fit$fit_flash$F.pm,pbmc_facs$samples$subpop,title='1e-1,iter20')
Running tsne on 417 x 8 matrix.
Running tsne on 91 x 8 matrix.
Running tsne on 358 x 8 matrix.
Running tsne on 359 x 8 matrix.
Running tsne on 775 x 8 matrix.

plot(fit$sigma2,colSums(counts/rowSums(counts)),pch=20,col='grey80')

fit = readRDS('/project2/mstephens/dongyue/poisson_mf/pbmc_fasttopics/init_tol_effect/nonnegLF_pe_inittol1e1_iter35.rds')
fit$elbo
[1] -8895574
plot(fit$K_trace)

hist(fit$sigma2,breaks = 100)

summary(fit$sigma2)
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
0.01549 1.51677 2.20763 1.97791 2.51471 3.24850 
p=structure_plot_general(fit$fit_flash$L.pm,fit$fit_flash$F.pm,pbmc_facs$samples$subpop,title='1e-1,iter35')
Running tsne on 417 x 8 matrix.
Running tsne on 91 x 8 matrix.
Running tsne on 358 x 8 matrix.
Running tsne on 359 x 8 matrix.
Running tsne on 775 x 8 matrix.

plot(fit$sigma2,colSums(counts/rowSums(counts)),pch=20,col='grey80')


sessionInfo()
R version 4.1.0 (2021-05-18)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: CentOS Linux 7 (Core)

Matrix products: default
BLAS:   /software/R-4.1.0-no-openblas-el7-x86_64/lib64/R/lib/libRblas.so
LAPACK: /software/R-4.1.0-no-openblas-el7-x86_64/lib64/R/lib/libRlapack.so

locale:
 [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C         LC_TIME=C           
 [4] LC_COLLATE=C         LC_MONETARY=C        LC_MESSAGES=C       
 [7] LC_PAPER=C           LC_NAME=C            LC_ADDRESS=C        
[10] LC_TELEPHONE=C       LC_MEASUREMENT=C     LC_IDENTIFICATION=C 

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

other attached packages:
[1] Matrix_1.5-3       ggplot2_3.4.0      fastTopics_0.6-142 workflowr_1.6.2   

loaded via a namespace (and not attached):
 [1] mcmc_0.9-7         fs_1.5.0           progress_1.2.2     httr_1.4.4        
 [5] rprojroot_2.0.2    tools_4.1.0        bslib_0.2.5.1      utf8_1.2.2        
 [9] R6_2.5.1           irlba_2.3.5.1      uwot_0.1.14        DBI_1.1.1         
[13] lazyeval_0.2.2     colorspace_2.0-3   withr_2.5.0        tidyselect_1.2.0  
[17] prettyunits_1.1.1  compiler_4.1.0     git2r_0.28.0       cli_3.5.0         
[21] quantreg_5.94      SparseM_1.81       plotly_4.10.1      labeling_0.4.2    
[25] sass_0.4.0         scales_1.2.1       SQUAREM_2021.1     quadprog_1.5-8    
[29] pbapply_1.6-0      mixsqp_0.3-48      stringr_1.4.0      digest_0.6.30     
[33] rmarkdown_2.9      MCMCpack_1.6-3     pkgconfig_2.0.3    htmltools_0.5.3   
[37] fastmap_1.1.0      invgamma_1.1       highr_0.9          htmlwidgets_1.5.4 
[41] rlang_1.0.6        rstudioapi_0.13    jquerylib_0.1.4    generics_0.1.3    
[45] farver_2.1.1       jsonlite_1.8.3     dplyr_1.0.10       magrittr_2.0.3    
[49] Rcpp_1.0.9         munsell_0.5.0      fansi_1.0.3        lifecycle_1.0.3   
[53] stringi_1.6.2      whisker_0.4        yaml_2.3.6         MASS_7.3-54       
[57] Rtsne_0.16         grid_4.1.0         parallel_4.1.0     promises_1.2.0.1  
[61] ggrepel_0.9.2      crayon_1.5.2       lattice_0.20-44    cowplot_1.1.1     
[65] splines_4.1.0      hms_1.1.2          knitr_1.33         pillar_1.8.1      
[69] glue_1.6.2         evaluate_0.14      data.table_1.14.6  RcppParallel_5.1.5
[73] vctrs_0.5.1        httpuv_1.6.1       MatrixModels_0.5-1 gtable_0.3.1      
[77] purrr_0.3.5        tidyr_1.2.1        assertthat_0.2.1   ashr_2.2-54       
[81] xfun_0.24          coda_0.19-4        later_1.3.0        survival_3.2-11   
[85] viridisLite_0.4.1  truncnorm_1.0-8    tibble_3.1.8       ellipsis_0.3.2