Last updated: 2023-01-27

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 b808030. 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:  code/binomial_mean/binomial_smooth_splitting.R
    Untracked:  code/binomial_mean/test_binomial.R
    Untracked:  output/droplet_iteration_results/
    Untracked:  output/ebpmf_pbmc3k_vga3_glmpca_init.rds
    Untracked:  output/pbmc3k_iteration_results/
    Untracked:  output/pbmc_no_constraint.rds

Unstaged changes:
    Modified:   code/binomial_mean/binomial_mean_splitting.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/binomial_mean_spliiting.Rmd) and HTML (docs/binomial_mean_spliiting.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 b808030 DongyueXie 2023-01-27 wflow_publish("analysis/binomial_mean_spliiting.Rmd")
html e08c844 Dongyue Xie 2022-12-16 Build site.
Rmd c4e08e5 Dongyue Xie 2022-12-16 wflow_publish("analysis/binomial_mean_spliiting.Rmd")
html b4d61ba DongyueXie 2022-11-17 Build site.
Rmd 8a7af8f DongyueXie 2022-11-17 wflow_publish("analysis/binomial_mean_spliiting.Rmd")

Introduction

Here we study if splitting method work for binomial and Bernoulli data.

The basic model is

\[x_i\sim Binomial(n_i,\sigma(\mu_i))\] \[\mu_i|b_i\sim N(b_i,\sigma^2)\] \[b_i\sim g(\cdot).\]

I generated \(\mu_i\sim \pi_0\delta_0 + \pi_1 N(0,1)\) where \(\pi_0 = 0.8\).

source("code/binomial_mean/binomial_mean_splitting.R")
Loading required package: Rcpp
Loading required package: RcppZiggurat

Binomial n = 100

set.seed(12345)
n = 500
nb = rep(100,n)
w = 0.8
mu = c(rep(0,n*w),rnorm(round(n*(1-w))))
p = sigmoid(mu)
x = rbinom(n,nb,p)
library(ashr)
fit_ash = ashr::ash(rep(0,n),1,lik=lik_binom(x,nb,link='identity'))
fit_split = binomial_mean_splitting(x,nb,printevery = 100,n_gh=10,
                                    b_pm_init = NULL,sigma2_init = NULL,
                                    ebnm_params = list(prior_family='normal_scale_mixture'))
Warning in binomial_mean_splitting(x, nb, printevery = 100, n_gh = 10, b_pm_init
= NULL, : An iteration decreases ELBO. This is likely due to numerical issues.
fit_GG = binomial_mean_GG(x,nb,printevery = 100,n_gh=10)
Warning in binomial_mean_GG(x, nb, printevery = 100, n_gh = 10): An iteration
decreases ELBO. This is likely due to numerical issues.
plot(x/nb,col='grey80',main='ash fit')
lines(p,col='grey80')
lines(fit_ash$result$PosteriorMean,col=2)

Version Author Date
e08c844 Dongyue Xie 2022-12-16
b4d61ba DongyueXie 2022-11-17
plot(x/nb,col='grey80',main='splitting fit latent m')
lines(p,col='grey80')
lines(fit_split$posterior$mean,col=4)

Version Author Date
e08c844 Dongyue Xie 2022-12-16
b4d61ba DongyueXie 2022-11-17
plot(x/nb,col='grey80',main='splitting fit latent b')
lines(p,col='grey80')
lines(sigmoid(fit_split$posterior$mean_b),col=4)

Version Author Date
e08c844 Dongyue Xie 2022-12-16
b4d61ba DongyueXie 2022-11-17
plot(x/nb,col='grey80',main='vga binom fit')
lines(p,col='grey80')
lines(fit_GG$posterior$mean,col=3)

Version Author Date
e08c844 Dongyue Xie 2022-12-16
b4d61ba DongyueXie 2022-11-17

Binomial n = 10

set.seed(12345)
n = 500
nb = rep(10,n)
w = 0.8
mu = c(rep(0,n*w),rnorm(round(n*(1-w))))
p = sigmoid(mu)
x = rbinom(n,nb,p)
library(ashr)
fit_ash = ashr::ash(rep(0,n),1,lik=lik_binom(x,nb,link='identity'))
fit_split = binomial_mean_splitting(x,nb,printevery = 100,n_gh=10,
                                    b_pm_init = NULL,sigma2_init = NULL,
                                    ebnm_params = list(prior_family='normal_scale_mixture'))
fit_GG = binomial_mean_GG(x,nb,printevery = 100,n_gh=10)
[1] "At iter 100 elbo= -881.405"
plot(x/nb,col='grey80',main='ash fit')
lines(p,col='grey80')
lines(fit_ash$result$PosteriorMean,col=2)

Version Author Date
e08c844 Dongyue Xie 2022-12-16
b4d61ba DongyueXie 2022-11-17
plot(x/nb,col='grey80',main='splitting fit latent m')
lines(p,col='grey80')
lines(fit_split$posterior$mean,col=4)

Version Author Date
e08c844 Dongyue Xie 2022-12-16
b4d61ba DongyueXie 2022-11-17
plot(x/nb,col='grey80',main='splitting fit latent b')
lines(p,col='grey80')
lines(sigmoid(fit_split$posterior$mean_b),col=4)

Version Author Date
e08c844 Dongyue Xie 2022-12-16
b4d61ba DongyueXie 2022-11-17
plot(x/nb,col='grey80',main='vga binom fit')
lines(p,col='grey80')
lines(fit_GG$posterior$mean,col=3)

Version Author Date
e08c844 Dongyue Xie 2022-12-16
b4d61ba DongyueXie 2022-11-17

Bernoulli

set.seed(12345)
n = 500
nb = rep(1,n)
w = 0.8
mu = c(rep(0,n*w),rnorm(round(n*(1-w))))
p = sigmoid(mu)
x = rbinom(n,nb,p)
library(ashr)
fit_ash = ashr::ash(rep(0,n),1,lik=lik_binom(x,nb,link='identity'))
fit_split = binomial_mean_splitting(x,nb,printevery = 100,n_gh=10,
                                    b_pm_init = NULL,sigma2_init = NULL,
                                    ebnm_params = list(prior_family='normal_scale_mixture'))
[1] "At iter 100 elbo= -846.413 sigma2= 2.447"
[1] "At iter 200 elbo= -846.208 sigma2= 1.847"
[1] "At iter 300 elbo= -846.133 sigma2= 1.555"
[1] "At iter 400 elbo= -846.095 sigma2= 1.376"
[1] "At iter 500 elbo= -846.073 sigma2= 1.253"
[1] "At iter 600 elbo= -846.059 sigma2= 1.161"
[1] "At iter 700 elbo= -846.049 sigma2= 1.09"
[1] "At iter 800 elbo= -846.041 sigma2= 1.032"
[1] "At iter 900 elbo= -846.036 sigma2= 0.985"
[1] "At iter 1000 elbo= -846.031 sigma2= 0.944"
fit_GG = binomial_mean_GG(x,nb,printevery = 100,n_gh=10)
[1] "At iter 100 elbo= -943.612"
plot(x/nb,col='grey80',main='ash fit')
lines(p,col='grey80')
lines(fit_ash$result$PosteriorMean,col=2)

plot(x/nb,col='grey80',main='splitting fit latent m')
lines(p,col='grey80')
lines(fit_split$posterior$mean,col=4)

plot(x/nb,col='grey80',main='splitting fit latent b')
lines(p,col='grey80')
lines(sigmoid(fit_split$posterior$mean_b),col=4)

plot(x/nb,col='grey80',main='vga binom fit')
lines(p,col='grey80')
lines(fit_GG$posterior$mean,col=3)


sessionInfo()
R version 4.2.2 Patched (2022-11-10 r83330)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 22.04.1 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3
LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.20.so

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

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

other attached packages:
[1] ashr_2.2-54        Rfast_2.0.6        RcppZiggurat_0.1.6 ebnm_1.0-11       
[5] fastGHQuad_1.0.1   Rcpp_1.0.9         vebpm_0.4.0        workflowr_1.7.0   

loaded via a namespace (and not attached):
 [1] horseshoe_0.2.0    invgamma_1.1       lattice_0.20-45    getPass_0.2-2     
 [5] ps_1.7.2           rprojroot_2.0.3    digest_0.6.31      utf8_1.2.2        
 [9] truncnorm_1.0-8    R6_2.5.1           evaluate_0.19      highr_0.9         
[13] httr_1.4.4         ggplot2_3.4.0      pillar_1.8.1       rlang_1.0.6       
[17] rstudioapi_0.14    irlba_2.3.5.1      whisker_0.4.1      callr_3.7.3       
[21] jquerylib_0.1.4    nloptr_2.0.3       Matrix_1.5-3       rmarkdown_2.19    
[25] splines_4.2.2      stringr_1.5.0      munsell_0.5.0      mixsqp_0.3-48     
[29] compiler_4.2.2     httpuv_1.6.7       xfun_0.35          pkgconfig_2.0.3   
[33] SQUAREM_2021.1     htmltools_0.5.4    tidyselect_1.2.0   tibble_3.1.8      
[37] matrixStats_0.63.0 fansi_1.0.3        dplyr_1.0.10       later_1.3.0       
[41] grid_4.2.2         jsonlite_1.8.4     gtable_0.3.1       lifecycle_1.0.3   
[45] git2r_0.30.1       magrittr_2.0.3     scales_1.2.1       ebpm_0.0.1.3      
[49] cli_3.4.1          stringi_1.7.8      cachem_1.0.6       fs_1.5.2          
[53] promises_1.2.0.1   bslib_0.4.2        generics_0.1.3     vctrs_0.5.1       
[57] trust_0.1-8        tools_4.2.2        glue_1.6.2         processx_3.8.0    
[61] parallel_4.2.2     fastmap_1.1.0      yaml_2.3.6         colorspace_2.0-3  
[65] deconvolveR_1.2-1  knitr_1.41         sass_0.4.4