Last updated: 2018-07-20

workflowr checks: (Click a bullet for more information)
  • R Markdown file: up-to-date

    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.

  • Environment: empty

    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.

  • Seed: set.seed(20180714)

    The command set.seed(20180714) 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.

  • Session information: recorded

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

  • Repository version: 2761284

    Great! You are using Git for version control. Tracking code development and connecting the code version to the results is critical for reproducibility. The version displayed above was the version of the Git repository at the time these results were generated.

    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
        Ignored:    .Rhistory
        Ignored:    .Rproj.user/
        Ignored:    docs/.DS_Store
        Ignored:    docs/figure/.DS_Store
    
    Unstaged changes:
        Modified:   analysis/flash_em.Rmd
        Modified:   analysis/index.Rmd
        Modified:   analysis/obj_notes.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.
Expand here to see past versions:
    File Version Author Date Message
    Rmd 2761284 Jason Willwerscheid 2018-07-20 wflow_publish(c(“analysis/objective3.Rmd”,
    html 793c8a1 Jason Willwerscheid 2018-07-16 Build site.
    Rmd e11ca44 Jason Willwerscheid 2018-07-16 wflow_publish(“analysis/objective3.Rmd”)


Introduction

Here I look into the bad loadings updates some more.

First I load the flash object from just before the “bad” update discussed in the first investigation. Next, I alternately update the precision and the loadings (I do not update the factors). I do so for 20 iterations.

# devtools::install_github("stephenslab/flashr", ref="trackObj")
devtools::load_all("/Users/willwerscheid/GitHub/flashr")
Loading flashr
# devtools::install_github("stephenslab/ebnm")
devtools::load_all("/Users/willwerscheid/GitHub/ebnm")
Loading ebnm
load("data/before_bad.Rdata")

init_fl <- res2$f
data <- flash_set_data(strong)
k <- 4

fl = init_fl
all_fls = list()
niters = 20
for (i in 1:niters) {
  # update precision
  R2 = flashr:::flash_get_R2(data, fl)
  fl$tau = flashr:::compute_precision(R2, data$missing,
                                      "by_column", data$S)
  # update loadings
  s2 = 1/(fl$EF2[, k] %*% t(fl$tau))
  s = sqrt(s2)
  Rk = flashr:::flash_get_Rk(data, fl, k)
  x = fl$EF[, k] %*% t(Rk * fl$tau) * s2
  ebnm_l = flashr:::ebnm_pn(x, s, list())
  KL_l = (ebnm_l$penloglik
          - flashr:::NM_posterior_e_loglik(x, s, ebnm_l$postmean,
                                           ebnm_l$postmean2))
  fl$EL[, k] = ebnm_l$postmean
  fl$EL2[, k] = ebnm_l$postmean2
  fl$gl[[k]] = ebnm_l$fitted_g
  fl$KL_l[[k]] = KL_l

  all_fls[[i]] = fl
}

Convergence of objective

Interestingly, the objective function gets worse every iteration. Nonetheless, it is apparently converging to something.

for (i in 1:niters) {
  message(flash_get_objective(data, all_fls[[i]])
          - flash_get_objective(data, init_fl))
}
-0.115442661102861
-0.215697337407619
-0.294866794254631
-0.35520419664681
-0.400229783495888
-0.43337183073163
-0.457542995689437
-0.475060580996796
-0.487700638826936
-0.496793346246704
-0.503320154268295
-0.507998006418347
-0.511347066378221
-0.51374295167625
-0.51545600919053
-0.516680368920788
-0.517555203288794
-0.518180169630796
-0.518626571865752
-0.518945396877825

Convergence of prior

To confirm that convergence is taking place, I check the estimated prior \(g_l\) after each iteration. The first list gives the values of \(\pi_0\); the second, the values of \(a\):

for (i in 1:niters) {
  message(all_fls[[i]]$gl[[4]]$pi0)
}
0.725369968917067
0.725667291395093
0.725879906389941
0.726031747043764
0.726140171228166
0.726217591908512
0.726272874154216
0.726312348284179
0.726340534554095
0.726360660713668
0.726375031572563
0.726385292894894
0.726392619840946
0.726397851530249
0.726401587130227
0.726404254470323
0.72640615903681
0.726407518957799
0.726408489984264
0.726409183327606
for (i in 1:niters) {
  message(all_fls[[i]]$gl[[4]]$a)
}
0.0516088117170904
0.0515789373518519
0.05155757657634
0.0515423298574009
0.0515314481621149
0.0515236810522557
0.0515181364728055
0.0515141781288619
0.0515113520575102
0.0515093343000696
0.0515078936274401
0.051506864975469
0.051506130502068
0.0515056060731487
0.051505231618544
0.0515049642483025
0.0515047733386485
0.0515046370237395
0.0515045396909259
0.0515044701924125

Session information

sessionInfo()
R version 3.4.3 (2017-11-30)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Sierra 10.12.6

Matrix products: default
BLAS: /Library/Frameworks/R.framework/Versions/3.4/Resources/lib/libRblas.0.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.4/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] ebnm_0.1-12   flashr_0.5-12

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.17        pillar_1.2.1        plyr_1.8.4
 [4] compiler_3.4.3      git2r_0.21.0        workflowr_1.0.1
 [7] R.methodsS3_1.7.1   R.utils_2.6.0       iterators_1.0.9
[10] tools_3.4.3         testthat_2.0.0      digest_0.6.15
[13] tibble_1.4.2        evaluate_0.10.1     memoise_1.1.0
[16] gtable_0.2.0        lattice_0.20-35     rlang_0.2.0
[19] Matrix_1.2-12       foreach_1.4.4       commonmark_1.4
[22] yaml_2.1.17         parallel_3.4.3      withr_2.1.1.9000
[25] stringr_1.3.0       roxygen2_6.0.1.9000 xml2_1.2.0
[28] knitr_1.20          devtools_1.13.4     rprojroot_1.3-2
[31] grid_3.4.3          R6_2.2.2            rmarkdown_1.8
[34] ggplot2_2.2.1       ashr_2.2-10         magrittr_1.5
[37] whisker_0.3-2       backports_1.1.2     scales_0.5.0
[40] codetools_0.2-15    htmltools_0.3.6     MASS_7.3-48
[43] assertthat_0.2.0    softImpute_1.4      colorspace_1.3-2
[46] stringi_1.1.6       lazyeval_0.2.1      munsell_0.4.3
[49] doParallel_1.0.11   pscl_1.5.2          truncnorm_1.0-8
[52] SQUAREM_2017.10-1   R.oo_1.21.0        

This reproducible R Markdown analysis was created with workflowr 1.0.1