Last updated: 2022-12-08

Checks: 7 0

Knit directory: gsmash/

This reproducible R Markdown analysis was created with workflowr (version 1.7.0). 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 0407c0b. 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/
    Ignored:    data/poisson_mean_simulation/

Untracked files:
    Untracked:  Rplot.png
    Untracked:  data/real_data_singlecell/
    Untracked:  figure/
    Untracked:  output/poisson_MF_simulation/
    Untracked:  output/poisson_mean_simulation/
    Untracked:  output/poisson_smooth_simulation/

Unstaged changes:
    Modified:   analysis/index.Rmd
    Modified:   analysis/run_PMF_on_pbmc.Rmd
    Modified:   code/poisson_STM/real_PMF.R

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/mean_var_relationship_in_real_sc_data.Rmd) and HTML (docs/mean_var_relationship_in_real_sc_data.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 0407c0b DongyueXie 2022-12-08 wflow_publish("analysis/mean_var_relationship_in_real_sc_data.Rmd")

Introduction

Previously I looked at the mean variance relationship in PLN model. Here I look at what the retio of variance to mean in real dataset.

Load the fitted model on pbmc data.

fit = readRDS('output/poisson_MF_simulation/pbmc_iter270.rds')
library(fastTopics)
library(Matrix)
library(stm)

Attaching package: 'stm'
The following object is masked from 'package:fastTopics':

    poisson2multinom
data(pbmc_facs)
counts <- pbmc_facs$counts
S = tcrossprod(c(rowSums(counts)),c(colSums(counts)))/sum(counts)

We take the ratio of variance and mean,

n = dim(counts)[1]
p = dim(counts)[2]
Sigma2 = matrix(fit$sigma2,nrow=n,ncol=p,byrow=TRUE)
Phi = 1 + (exp(Sigma2)-1)*S*exp(fitted(fit$fit_flash)+Sigma2/2)
mean(Phi)
[1] 1.010947
median(Phi)
[1] 1.000042
quantile(Phi,0.25)
     25% 
1.000001 
quantile(Phi,0.75)
     75% 
1.000638 
range(Phi)
[1]   1.0000 286.5065
which(Phi==max(Phi),arr.ind=T)
      row   col
[1,] 2281 16240
counts[2281,16240]
[1] 18
Sigma2[2281,16240]
[1] 3.589018
fitted(fit$fit_flash)[2281,16240]
[1] 1.25305
S[2281,16240]
[1] 0.3850828
plot(counts[2281,])

plot(counts[,16240])

droplet data

fit = readRDS('output/poisson_MF_simulation/droplet.rds')
load('data/real_data_singlecell/droplet.RData')
genes = (colSums(counts>0) > (dim(counts)[1]*0.03))
counts = counts[,genes]
S = tcrossprod(c(rowSums(counts)),c(colSums(counts)))/sum(counts)

We take the ratio of variance and mean,

n = dim(counts)[1]
p = dim(counts)[2]
Sigma2 = matrix(fit$sigma2,nrow=n,ncol=p,byrow=TRUE)
Phi = 1 + (exp(Sigma2)-1)*S*exp(fitted(fit$fit_flash)+Sigma2/2)
mean(Phi)
[1] 1.350863
median(Phi)
[1] 1.076148
quantile(Phi,0.25)
     25% 
1.006607 
quantile(Phi,0.75)
     75% 
1.161632 
range(Phi)
[1]     1.000128 25508.483750
which(Phi==max(Phi),arr.ind=T)
     row  col
[1,] 420 8506
counts[420,8506]
[1] 11291
Sigma2[420,8506]
[1] 0.4221456
fitted(fit$fit_flash)[420,8506]
[1] 2.900109
S[420,8506]
[1] 2163.458
plot(counts[420,])

plot(counts[,8506])


sessionInfo()
R version 4.2.1 (2022-06-23)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 20.04.5 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.9.0
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.9.0

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

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

other attached packages:
[1] stm_1.1.0          Matrix_1.5-1       fastTopics_0.6-142 workflowr_1.7.0   

loaded via a namespace (and not attached):
  [1] mcmc_0.9-7         bitops_1.0-7       matrixStats_0.62.0
  [4] fs_1.5.2           progress_1.2.2     httr_1.4.4        
  [7] rprojroot_2.0.3    tools_4.2.1        bslib_0.4.0       
 [10] utf8_1.2.2         R6_2.5.1           irlba_2.3.5.1     
 [13] uwot_0.1.14        DBI_1.1.3          lazyeval_0.2.2    
 [16] colorspace_2.0-3   wavethresh_4.7.2   prettyunits_1.1.1 
 [19] tidyselect_1.2.0   processx_3.7.0     ebpm_0.0.1.3      
 [22] compiler_4.2.1     git2r_0.30.1       cli_3.4.1         
 [25] quantreg_5.94      SparseM_1.81       plotly_4.10.1     
 [28] horseshoe_0.2.0    sass_0.4.2         caTools_1.18.2    
 [31] flashier_0.2.34    scales_1.2.1       SQUAREM_2021.1    
 [34] quadprog_1.5-8     callr_3.7.2        pbapply_1.6-0     
 [37] mixsqp_0.3-48      stringr_1.4.1      digest_0.6.29     
 [40] rmarkdown_2.17     MCMCpack_1.6-3     deconvolveR_1.2-1 
 [43] vebpm_0.3.3        pkgconfig_2.0.3    htmltools_0.5.3   
 [46] highr_0.9          fastmap_1.1.0      invgamma_1.1      
 [49] htmlwidgets_1.5.4  rlang_1.0.6        rstudioapi_0.14   
 [52] jquerylib_0.1.4    generics_0.1.3     jsonlite_1.8.2    
 [55] dplyr_1.0.10       magrittr_2.0.3     smashr_1.3-6      
 [58] Rcpp_1.0.9         munsell_0.5.0      fansi_1.0.3       
 [61] lifecycle_1.0.3    stringi_1.7.8      whisker_0.4       
 [64] yaml_2.3.5         nleqslv_3.3.3      rootSolve_1.8.2.3 
 [67] MASS_7.3-58        Rtsne_0.16         grid_4.2.1        
 [70] parallel_4.2.1     promises_1.2.0.1   ggrepel_0.9.2     
 [73] crayon_1.5.2       lattice_0.20-45    cowplot_1.1.1     
 [76] splines_4.2.1      hms_1.1.2          knitr_1.40        
 [79] ps_1.7.1           pillar_1.8.1       softImpute_1.4-1  
 [82] glue_1.6.2         evaluate_0.17      trust_0.1-8       
 [85] getPass_0.2-2      data.table_1.14.6  RcppParallel_5.1.5
 [88] nloptr_2.0.3       vctrs_0.4.2        httpuv_1.6.6      
 [91] MatrixModels_0.5-1 gtable_0.3.1       purrr_0.3.5       
 [94] ebnm_1.0-9         tidyr_1.2.1        assertthat_0.2.1  
 [97] ashr_2.2-54        cachem_1.0.6       ggplot2_3.3.6     
[100] xfun_0.33          NNLM_0.4.4         coda_0.19-4       
[103] later_1.3.0        survival_3.4-0     viridisLite_0.4.1 
[106] truncnorm_1.0-8    tibble_3.1.8       ellipsis_0.3.2