Last updated: 2023-02-07

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 e9da031. 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/movielens.Rmd
    Untracked:  analysis/profiled_obj_for_b_splitting.Rmd
    Untracked:  data/ml-latest-small/
    Untracked:  output/droplet_iteration_results/
    Untracked:  output/ebpmf_pbmc3k_vga3_glmpca_init.rds
    Untracked:  output/pbmc3k_iteration_results/
    Untracked:  output/pbmc_no_constraint.rds

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/poisson_mean_split_local_optimum.Rmd) and HTML (docs/poisson_mean_split_local_optimum.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 e9da031 DongyueXie 2023-02-07 wflow_publish("analysis/poisson_mean_split_local_optimum.Rmd")
html 2919c38 DongyueXie 2023-02-07 Build site.
Rmd 05be5a7 DongyueXie 2023-02-07 wflow_publish("analysis/poisson_mean_split_local_optimum.Rmd")
html bdc3619 DongyueXie 2023-02-06 Build site.
Rmd 0a9bdef DongyueXie 2023-02-06 wflow_publish("analysis/poisson_mean_split_local_optimum.Rmd")

Introduction

\[y_i\sim Poisson(exp(\mu_j)),\mu_j|b_j\sim N(b_j,\sigma^2),b_j\sim g(\cdot).\]

We show in a simple POisson mean example, there are two local optimums - one where \(g_b\) is a point mass, one where \(g_b\) is the one we are interested in.

library(vebpm)
n = 1000
set.seed(12345)
mu = c(rep(4,100),rep(0,n-100))
x = rpois(n,exp(mu))

plot(x,col='grey80')
lines(exp(mu))

Version Author Date
bdc3619 DongyueXie 2023-02-06

In the first example we initialize \(\sigma^2=0.5\), ans we can see that the final \(sigma^2\) is around 0.2

fit0 = pois_mean_split(x,sigma2=0.5)
Warning in pois_mean_split(x, sigma2 = 0.5): An iteration decreases ELBO. This
is likely due to numerical issues.
plot(x,col='grey80')
lines(fit0$posterior$mean_exp_b)

Version Author Date
bdc3619 DongyueXie 2023-02-06
plot(fit0$fitted_g$sigma2_trace)

Version Author Date
bdc3619 DongyueXie 2023-02-06
fit0$fitted_g$g_b
$pi
[1] 0.8836418 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000
[8] 0.1163582 0.0000000

$mean
[1] -0.06950088 -0.06950088 -0.06950088 -0.06950088 -0.06950088 -0.06950088
[7] -0.06950088 -0.06950088 -0.06950088

$sd
[1] 0.0000000 0.4050770 0.6765755 0.9916300 1.3870662 1.8993115 2.5729789
[8] 3.4658753 4.6542967

attr(,"class")
[1] "normalmix"
attr(,"row.names")
[1] 1 2 3 4 5 6 7 8 9
fit0$elbo
[1] -3170.676

WE try to initialize \(\sigma^2=0.1\), and we can see that the final \(sigma^2\) is still around 0.14

fit0 = pois_mean_split(x,sigma2=0.1)
plot(x,col='grey80')
lines(fit0$posterior$mean_exp_b)

Version Author Date
bdc3619 DongyueXie 2023-02-06
plot(fit0$fitted_g$sigma2_trace)

Version Author Date
bdc3619 DongyueXie 2023-02-06
fit0$fitted_g$g_b
$pi
 [1] 0.8885623 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000
 [8] 0.0000000 0.1114377 0.0000000

$mean
 [1] -0.02641456 -0.02641456 -0.02641456 -0.02641456 -0.02641456 -0.02641456
 [7] -0.02641456 -0.02641456 -0.02641456 -0.02641456

$sd
 [1] 0.0000000 0.3227005 0.5389870 0.7899720 1.1049923 1.5130673 2.0497376
 [8] 2.7610545 3.7077984 4.9707654

attr(,"class")
[1] "normalmix"
attr(,"row.names")
 [1]  1  2  3  4  5  6  7  8  9 10
fit0$elbo
[1] -3168.611

So this is a local optimum and is the one that gives the results we’d love to see.

ON the other hand If we initialize \(\sigma^2\) to be bigger at \(\sigma^2 = 2\), then \(\sigma^2\) converges to 3 and \(g_b\) goes to a point mass.

fit0 = pois_mean_split(x,sigma2=2)
plot(x,col='grey80')
lines(fit0$posterior$mean_exp_b)

Version Author Date
bdc3619 DongyueXie 2023-02-06
fit0$fitted_g$sigma2_trace
[1] 2.476947 2.685522 2.843666 2.949401 3.013449 3.050891 3.072491 3.084879
[9] 3.091961
fit0$fitted_g$g_b
$pi
[1] 1 0 0 0 0

$mean
[1] -0.02755852 -0.02755852 -0.02755852 -0.02755852 -0.02755852

$sd
[1] 0.000000 1.560810 2.606926 3.820868 5.344530

attr(,"class")
[1] "normalmix"
attr(,"row.names")
[1] 1 2 3 4 5
fit0$elbo
[1] -3279.522

Try a larger init value of \(\sigma^2\) at 5, then same thing happens.

fit0 = pois_mean_split(x,sigma2=5)
plot(x,col='grey80')
lines(fit0$posterior$mean_exp_b)

Version Author Date
bdc3619 DongyueXie 2023-02-06
fit0$fitted_g$sigma2_trace
[1] 4.012418 3.401599 3.249432 3.183250 3.147588 3.127588 3.116270 3.109837
fit0$fitted_g$g_b
$pi
[1] 1 0 0 0 0

$mean
[1] -0.03821734 -0.03821734 -0.03821734 -0.03821734 -0.03821734

$sd
[1] 0.000000 1.568731 2.620156 3.840259 5.371654

attr(,"class")
[1] "normalmix"
attr(,"row.names")
[1] 1 2 3 4 5
fit0$elbo
[1] -3279.521

Maybe we should not start with a too large \(\sigma^2\) because \(g_b\) being a point mass is a local optimum and in most cases we are not very interested in. I find that the starting \(\sigma^2\) should not be greater than \(var(\bar\mu_i)\), and perhaps smaller.

Observations

Apparently if \(g_b\) goes to a pointmass, then \(\sigma^2\) is large. This converges to the problem of putting a Gaussian prior on the parameter \(\mu\).

On the other hand, if \(g_b\) goes to a non-pointmass, then \(\sigma^2\) can converge to a smaller value, but not 0. In this simulation we know that true \(\sigma^2\) is 0, and in this case the estimated \(\sigma^2\) converges to 0.2.


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] vebpm_0.4.0     workflowr_1.7.0

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