Last updated: 2020-01-17
Checks: 6 0
Knit directory: drift-workflow/analysis/
This reproducible R Markdown analysis was created with workflowr (version 1.2.0). The Report 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(20190211)
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! 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/assets/.DS_Store
Unstaged changes:
Modified: drift-workflow.Rproj
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 R Markdown and HTML files. If you’ve configured a remote Git repository (see ?wflow_git_remote
), click on the hyperlinks in the table below to view them.
File | Version | Author | Date | Message |
---|---|---|---|---|
Rmd | 37e8139 | Jason Willwerscheid | 2020-01-17 | wflow_publish(“analysis/admix_sim_full.Rmd”) |
html | e9d8a29 | Jason Willwerscheid | 2020-01-17 | Build site. |
Rmd | 3715e43 | Jason Willwerscheid | 2020-01-17 | wflow_publish(“analysis/admix_sim_full.Rmd”) |
html | f73773f | Jason Willwerscheid | 2020-01-16 | Build site. |
Rmd | 3da801d | Jason Willwerscheid | 2020-01-16 | wflow_publish(“analysis/admix_sim_full.Rmd”) |
suppressMessages({
library(flashier)
library(drift.alpha)
library(ggplot2)
library(reshape2)
library(tidyverse)
})
Time to try out drift
on the full admixture graph from Pickrell and Pritchard (Figure 1, Example Graph C). To make the problem easier, I set \(p\) large and \(\sigma_e\) small.
set.seed(666)
simple.admix <- admix_graph_sim(n_per_pop = 20, p = 20000,
c1 = 1, c2 = 1, c3 = 1, c4 = 1,
c5 = 0.5, c6 = 1, c7 = 0.5,
w = 0.25, sigma_e = sqrt(0.1))
plot_cov(simple.admix$covmat, as.is = TRUE)
Version | Author | Date |
---|---|---|
f73773f | Jason Willwerscheid | 2020-01-16 |
fl <- flash(simple.admix$Y, prior.family = c(prior.bimodal(), prior.normal()))
#> Adding factor 1 to flash object...
#> Adding factor 2 to flash object...
#> Adding factor 3 to flash object...
#> Adding factor 4 to flash object...
#> Adding factor 5 to flash object...
#> Warning in estimate_mixprop(data, g, prior, optmethod = optmethod, control
#> = control, : Optimization failed to converge. Results may be unreliable.
#> Try increasing maxiter and rerunning.
#> Warning in estimate_mixprop(data, g, prior, optmethod = optmethod, control
#> = control, : Optimization failed to converge. Results may be unreliable.
#> Try increasing maxiter and rerunning.
#> Adding factor 6 to flash object...
#> Adding factor 7 to flash object...
#> Factor doesn't significantly increase objective and won't be added.
#> Wrapping up...
#> Done.
#> Nullchecking 6 factors...
#> Done.
labs <- rep(c("A", "B", "C", "D"), each = 20)
plot_loadings(fl$flash.fit$EF[[1]], labs)
Version | Author | Date |
---|---|---|
f73773f | Jason Willwerscheid | 2020-01-16 |
drift.flg <- drift(init_from_flash(fl), miniter = 1750, maxiter = 2000, tol = 0.001, verbose = FALSE)
ggplot(drift.flg$iterations, aes(x = iter, y = elbo)) + geom_line()
drift.flg[c("elbo", "KL_l", "KL_f")]
#> $elbo
#> [1] -657041.9
#>
#> $KL_l
#> [1] -154.41924 -166.45078 -139.16191 -65.79745 -171.93078 -45.12987
#>
#> $KL_f
#> [1] -228345.1
plot_loadings(drift.flg$EL, labs, paste("s2:", round(drift.flg$prior_s2, 2)))
plot_cov(drift.flg)
fl <- fl %>% flash.backfit() %>% flash.nullcheck(remove = TRUE)
#> Backfitting 6 factors (tolerance: 2.38e-02)...
#> Difference between iterations is within 1.0e+05...
#> Difference between iterations is within 1.0e+04...
#> Difference between iterations is within 1.0e+03...
#> Warning in estimate_mixprop(data, g, prior, optmethod = optmethod, control
#> = control, : Optimization failed to converge. Results may be unreliable.
#> Try increasing maxiter and rerunning.
#> Warning in estimate_mixprop(data, g, prior, optmethod = optmethod, control
#> = control, : Optimization failed to converge. Results may be unreliable.
#> Try increasing maxiter and rerunning.
#> Warning in estimate_mixprop(data, g, prior, optmethod = optmethod, control
#> = control, : Optimization failed to converge. Results may be unreliable.
#> Try increasing maxiter and rerunning.
#> Warning in estimate_mixprop(data, g, prior, optmethod = optmethod, control
#> = control, : Optimization failed to converge. Results may be unreliable.
#> Try increasing maxiter and rerunning.
#> Warning in estimate_mixprop(data, g, prior, optmethod = optmethod, control
#> = control, : Optimization failed to converge. Results may be unreliable.
#> Try increasing maxiter and rerunning.
#> Warning in estimate_mixprop(data, g, prior, optmethod = optmethod, control
#> = control, : Optimization failed to converge. Results may be unreliable.
#> Try increasing maxiter and rerunning.
#> Warning in estimate_mixprop(data, g, prior, optmethod = optmethod, control
#> = control, : Optimization failed to converge. Results may be unreliable.
#> Try increasing maxiter and rerunning.
#> Difference between iterations is within 1.0e+02...
#> Warning in estimate_mixprop(data, g, prior, optmethod = optmethod, control
#> = control, : Optimization failed to converge. Results may be unreliable.
#> Try increasing maxiter and rerunning.
#> Warning in estimate_mixprop(data, g, prior, optmethod = optmethod, control
#> = control, : Optimization failed to converge. Results may be unreliable.
#> Try increasing maxiter and rerunning.
#> Warning in estimate_mixprop(data, g, prior, optmethod = optmethod, control
#> = control, : Optimization failed to converge. Results may be unreliable.
#> Try increasing maxiter and rerunning.
#> Warning in estimate_mixprop(data, g, prior, optmethod = optmethod, control
#> = control, : Optimization failed to converge. Results may be unreliable.
#> Try increasing maxiter and rerunning.
#> Warning in estimate_mixprop(data, g, prior, optmethod = optmethod, control
#> = control, : Optimization failed to converge. Results may be unreliable.
#> Try increasing maxiter and rerunning.
#> Warning in estimate_mixprop(data, g, prior, optmethod = optmethod, control
#> = control, : Optimization failed to converge. Results may be unreliable.
#> Try increasing maxiter and rerunning.
#> Warning in estimate_mixprop(data, g, prior, optmethod = optmethod, control
#> = control, : Optimization failed to converge. Results may be unreliable.
#> Try increasing maxiter and rerunning.
#> Warning in estimate_mixprop(data, g, prior, optmethod = optmethod, control
#> = control, : Optimization failed to converge. Results may be unreliable.
#> Try increasing maxiter and rerunning.
#> Warning in estimate_mixprop(data, g, prior, optmethod = optmethod, control
#> = control, : Optimization failed to converge. Results may be unreliable.
#> Try increasing maxiter and rerunning.
#> Difference between iterations is within 1.0e+01...
#> Warning in estimate_mixprop(data, g, prior, optmethod = optmethod, control
#> = control, : Optimization failed to converge. Results may be unreliable.
#> Try increasing maxiter and rerunning.
#> Warning in estimate_mixprop(data, g, prior, optmethod = optmethod, control
#> = control, : Optimization failed to converge. Results may be unreliable.
#> Try increasing maxiter and rerunning.
#> Warning in estimate_mixprop(data, g, prior, optmethod = optmethod, control
#> = control, : Optimization failed to converge. Results may be unreliable.
#> Try increasing maxiter and rerunning.
#> Warning in estimate_mixprop(data, g, prior, optmethod = optmethod, control
#> = control, : Optimization failed to converge. Results may be unreliable.
#> Try increasing maxiter and rerunning.
#> Difference between iterations is within 1.0e+00...
#> Difference between iterations is within 1.0e-01...
#> Warning in estimate_mixprop(data, g, prior, optmethod = optmethod, control
#> = control, : Optimization failed to converge. Results may be unreliable.
#> Try increasing maxiter and rerunning.
#> Warning in estimate_mixprop(data, g, prior, optmethod = optmethod, control
#> = control, : Optimization failed to converge. Results may be unreliable.
#> Try increasing maxiter and rerunning.
#> Difference between iterations is within 1.0e-02...
#> Wrapping up...
#> Done.
#> Nullchecking 6 factors...
#> Wrapping up...
#> Done.
plot_loadings(fl$flash.fit$EF[[1]], labs)
drift.flb <- drift(init_from_flash(fl), miniter = 750, maxiter = 1000, tol = 0.001, verbose = FALSE)
ggplot(drift.flb$iterations, aes(x = iter, y = elbo)) + geom_line()
drift.flb[c("elbo", "KL_l", "KL_f")]
#> $elbo
#> [1] -656960.3
#>
#> $KL_l
#> [1] -254.19492 -164.70741 -105.11501 -45.12987
#>
#> $KL_f
#> [1] -228419.6
plot_loadings(drift.flb$EL, labs, paste("s2:", round(drift.flb$prior_s2, 2)))
plot_cov(drift.flb)
all.drift <- list(drift.flg, drift.flb)
res.df <- data.frame(
Name = c("flash.greedy", "flash.backfit"),
InitialELBO = sapply(all.drift, function(x) x$iterations$elbo[1]),
FinalELBO = sapply(all.drift, function(x) x$elbo),
ELBOdiff = sapply(all.drift, function(x) x$elbo - x$iterations$elbo[1]),
n_iter = sapply(all.drift, function(x) max(x$iterations$iter)),
KL_l = sapply(all.drift, function(x) sum(x$KL_l)),
KL_f = sapply(all.drift, function(x) x$KL_f),
ResidS2 = sapply(all.drift, function(x) x$resid_s2)
)
knitr::kable(res.df, digits = 3)
Name | InitialELBO | FinalELBO | ELBOdiff | n_iter | KL_l | KL_f | ResidS2 |
---|---|---|---|---|---|---|---|
flash.greedy | -660071.7 | -657041.9 | 3029.805 | 1769 | -742.890 | -228345.1 | 0.1 |
flash.backfit | -657762.9 | -656960.3 | 802.553 | 750 | -569.147 | -228419.6 | 0.1 |
sessionInfo()
#> R version 3.5.3 (2019-03-11)
#> Platform: x86_64-apple-darwin15.6.0 (64-bit)
#> Running under: macOS Mojave 10.14.6
#>
#> Matrix products: default
#> BLAS: /Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libRblas.0.dylib
#> LAPACK: /Library/Frameworks/R.framework/Versions/3.5/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] forcats_0.4.0 stringr_1.4.0 dplyr_0.8.0.1
#> [4] purrr_0.3.2 readr_1.3.1 tidyr_0.8.3
#> [7] tibble_2.1.1 tidyverse_1.2.1 reshape2_1.4.3
#> [10] ggplot2_3.2.0 drift.alpha_0.0.6 flashier_0.2.2
#>
#> loaded via a namespace (and not attached):
#> [1] Rcpp_1.0.1 lubridate_1.7.4 lattice_0.20-38
#> [4] assertthat_0.2.1 rprojroot_1.3-2 digest_0.6.18
#> [7] foreach_1.4.4 truncnorm_1.0-8 R6_2.4.0
#> [10] cellranger_1.1.0 plyr_1.8.4 backports_1.1.3
#> [13] evaluate_0.13 highr_0.8 httr_1.4.0
#> [16] pillar_1.3.1 rlang_0.4.2 lazyeval_0.2.2
#> [19] pscl_1.5.2 readxl_1.3.1 rstudioapi_0.10
#> [22] ebnm_0.1-24 irlba_2.3.3 whisker_0.3-2
#> [25] Matrix_1.2-15 rmarkdown_1.12 labeling_0.3
#> [28] munsell_0.5.0 mixsqp_0.3-15 broom_0.5.1
#> [31] compiler_3.5.3 modelr_0.1.5 xfun_0.6
#> [34] pkgconfig_2.0.2 SQUAREM_2017.10-1 htmltools_0.3.6
#> [37] tidyselect_0.2.5 workflowr_1.2.0 codetools_0.2-16
#> [40] crayon_1.3.4 withr_2.1.2 MASS_7.3-51.1
#> [43] grid_3.5.3 nlme_3.1-137 jsonlite_1.6
#> [46] gtable_0.3.0 git2r_0.25.2 magrittr_1.5
#> [49] scales_1.0.0 cli_1.1.0 stringi_1.4.3
#> [52] fs_1.2.7 doParallel_1.0.14 xml2_1.2.0
#> [55] generics_0.0.2 iterators_1.0.10 tools_3.5.3
#> [58] glue_1.3.1 hms_0.4.2 parallel_3.5.3
#> [61] yaml_2.2.0 colorspace_1.4-1 ashr_2.2-38
#> [64] rvest_0.3.4 knitr_1.22 haven_2.1.1