Last updated: 2018-07-16
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: e11ca44 
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
| File | Version | Author | Date | Message | 
|---|---|---|---|---|
| Rmd | e11ca44 | Jason Willwerscheid | 2018-07-16 | wflow_publish(“analysis/objective3.Rmd”) | 
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.
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
}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.518945396877825To 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.7253699689170670.7256672913950930.7258799063899410.7260317470437640.7261401712281660.7262175919085120.7262728741542160.7263123482841790.7263405345540950.7263606607136680.7263750315725630.7263852928948940.7263926198409460.7263978515302490.7264015871302270.7264042544703230.726406159036810.7264075189577990.7264084899842640.726409183327606for (i in 1:niters) {
  message(all_fls[[i]]$gl[[4]]$a)
}0.05160881171709040.05157893735185190.051557576576340.05154232985740090.05153144816211490.05152368105225570.05151813647280550.05151417812886190.05151135205751020.05150933430006960.05150789362744010.0515068649754690.0515061305020680.05150560607314870.0515052316185440.05150496424830250.05150477333864850.05150463702373950.05150453969092590.0515044701924125sessionInfo()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