Last updated: 2019-11-08
Checks: 7 0
Knit directory: ebpmf_demo/
This reproducible R Markdown analysis was created with workflowr (version 1.5.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(20190923)
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 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: .Rhistory
Ignored: .Rproj.user/
Untracked files:
Untracked: Untitled.Rmd
Untracked: Untitled.html
Untracked: analysis/.ipynb_checkpoints/
Untracked: analysis/Experiment_ebpmf_simple.Rmd
Untracked: analysis/draft.Rmd
Untracked: analysis/ebpm_gamma_mixture_experiment.Rmd
Untracked: analysis/ebpmf_demo.Rmd
Untracked: analysis/ebpmf_rank1_demo2.Rmd
Untracked: analysis/plot_g.Rmd
Untracked: analysis/softmax_experiments.ipynb
Untracked: code/misc.R
Untracked: data/Compare_ebpmf_nmf2_out
Untracked: data/Compare_ebpmf_nmf2_out_ver2.Rds
Untracked: data/ebpm_fail.Rds
Untracked: data/nmf_sparse3_elbo.Rds
Untracked: data/nmf_sparse3_loadings.Rds
Untracked: data/nmf_sparse3_summary.Rds
Untracked: data/nmf_sparse6_fit_ebpmf_re_nsnmf.Rds
Untracked: data/nmf_sparse6_fit_pg_from_truth.Rds
Untracked: data/nmf_sparse7_data.rds
Untracked: data/nmf_sparse7_fit_em.Rds
Untracked: data/nmf_sparse7_fit_gamma_mix.Rds
Untracked: data/nmf_sparse7_fit_gamma_mix_random.Rds
Untracked: data/nmf_sparse7_fit_gamma_mix_uniform_weight.Rds
Untracked: data/trash/
Untracked: verbose_log_1571583163.21966.txt
Untracked: verbose_log_1571583324.71036.txt
Untracked: verbose_log_1571583741.94199.txt
Untracked: verbose_log_1571588102.40356.txt
Unstaged changes:
Modified: analysis/Compare_ebpmf_nmf.Rmd
Modified: analysis/Compare_ebvaepm_ebpm.Rmd
Modified: analysis/Experiment_ebpmf_rank1.Rmd
Modified: analysis/ebpm_demo.Rmd
Modified: analysis/nmf_sparse.Rmd
Modified: analysis/nmf_sparse2.Rmd
Modified: analysis/nmf_sparse3.Rmd
Modified: analysis/nmf_sparse6.Rmd
Modified: analysis/softmax_experiments.Rmd
Modified: data/Compare_ebpmf_nmf2_out.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 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 | 884360c | zihao12 | 2019-11-08 | update vignette ebpm |
html | 3814bfb | zihao12 | 2019-10-22 | Build site. |
Rmd | 08b9948 | zihao12 | 2019-10-22 | add vignette for ebpm point gamma |
html | 8abb684 | zihao12 | 2019-10-20 | Build site. |
Rmd | 0ac2637 | zihao12 | 2019-10-20 | vignette for ebpm |
\[ \begin{align} & x_i \sim Pois(s_i \lambda_i)\\ & \lambda_i \sim g(.)\\ & g \in \mathcal{G} \end{align} \] Our goal is to estimate \(\hat{g}\) (MLE), then compute posterior \(p(\lambda_i | x_i, \hat{g})\). Here I use mixture of exponential as prior family.
See model details and derivations in https://github.com/stephenslab/ebpm/blob/master/derivations/ebpm.pdf
library(ebpm)
set.seed(123)
library(ebpm)
library(ggplot2)
library(gtools)
require(gridExtra)
Loading required package: gridExtra
I simulate data from the mixture of exponential, and compare fitting the poisson mean problem with MLE (\(\hat{\lambda}^{mle}_i = \frac{x_i}{s_i}\)), and ebpm_exponential_mixture
with different options.
For ebpm
, the options are:
* fit_true_g
: use the true \(g\)
* fit_true_scale
: use the true mixture components to estimate \(\hat{g}\)
* fit_est_scale
: estimate mixture components from data, then estimate \(\hat{g}\)
## simulate data
n = 2000
sim = ebpm::simulate_pois_expmix(n, seed = 123)
hist(sim$x, breaks = 100, xlab = "x", main = "hist for data x")
rmse <- function(x,y){
return(sqrt(mean((x-y)^2)))
}
methods = c()
ll_gs = c()
rmses = c()
## true
methods = c(methods, "true")
ll_gs = c(ll_gs, sim$ll)
rmses = c(rmses, 0)
## MLE
methods = c(methods, "mle")
ll_gs = c(ll_gs, NA)
rmses = c(rmses, rmse(sim$x/sim$s, sim$lam))
## fit (with known g)
fit = ebpm::ebpm_exponential_mixture(x = sim$x, s = sim$s, g_init = sim$g, fix_g = T)
methods = c(methods, "fit_true_g")
ll_gs = c(ll_gs, fit$log_likelihood)
rmses = c(rmses, rmse(fit$posterior$mean, sim$lam))
rm(fit)
## fit (with known true scale (mixture components))
fit = ebpm::ebpm_exponential_mixture(x = sim$x, s = sim$s, scale = list(shape = sim$g$shape, scale = sim$g$scale))
methods = c(methods, "fit_true_scale")
ll_gs = c(ll_gs, fit$log_likelihood)
rmses = c(rmses, rmse(fit$posterior$mean, sim$lam))
rm(fit)
## fit (estimate scale)
fit = ebpm::ebpm_exponential_mixture(x = sim$x, s = sim$s, scale = "estimate")
methods = c(methods, "fit_est_scale")
ll_gs = c(ll_gs, fit$log_likelihood)
rmses = c(rmses, rmse(fit$posterior$mean, sim$lam))
rm(fit)
data.frame(method = methods, ll_g = ll_gs, rmse = rmses)
method ll_g rmse
1 true -2909.614 0.0000000
2 mle NA 1.0556360
3 fit_true_g -2909.614 0.7873792
4 fit_true_scale -2909.307 0.7870354
5 fit_est_scale -2911.056 0.7900987
fit = ebpm::ebpm_exponential_mixture(x = sim$x, s = sim$s, scale = "estimate")
df = data.frame(lam_true = sim$lam,lam_hat_mle = sim$x/sim$s, lam_hat_ebpm = fit$posterior$mean)
ggplot(df)+
geom_point(aes(x = log(lam_true + 1), y = log(lam_hat_ebpm +1)), color = "blue")+
geom_abline(slope = 1, intercept = 0)+
guides(fill = "color")+
ggtitle("lam_true vs lam_hat_ebpm")
ggplot(df)+
geom_point(aes(x = log(lam_true + 1), y = log(lam_hat_mle + 1)), color = "blue")+
geom_abline(slope = 1, intercept = 0)+
guides(fill = "color")+
ggtitle("lam_true vs lam_hat_mle")
ggplot(df)+
geom_point(aes(x = log(lam_hat_mle + 1), y = log(lam_hat_ebpm + 1)), color = "blue")+
geom_abline(slope = 1, intercept = 0)+
guides(fill = "color")+
ggtitle("lam_hat_mle vs lam_hat_ebpm")
sessionInfo()
R version 3.5.1 (2018-07-02)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS 10.14
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] gridExtra_2.3 gtools_3.8.1 ggplot2_3.2.1 ebpm_0.0.0.9002
loaded via a namespace (and not attached):
[1] Rcpp_1.0.2 compiler_3.5.1 pillar_1.4.2 later_0.8.0
[5] git2r_0.26.1 workflowr_1.5.0 tools_3.5.1 digest_0.6.22
[9] evaluate_0.14 tibble_2.1.3 gtable_0.3.0 pkgconfig_2.0.3
[13] rlang_0.4.1 yaml_2.2.0 xfun_0.8 withr_2.1.2
[17] stringr_1.4.0 dplyr_0.8.1 knitr_1.25 fs_1.3.1
[21] rprojroot_1.3-2 grid_3.5.1 tidyselect_0.2.5 glue_1.3.1
[25] R6_2.4.0 rmarkdown_1.13 mixsqp_0.2-3 purrr_0.3.2
[29] magrittr_1.5 whisker_0.3-2 backports_1.1.5 scales_1.0.0
[33] promises_1.0.1 htmltools_0.3.6 assertthat_0.2.1 colorspace_1.4-1
[37] httpuv_1.5.1 labeling_0.3 stringi_1.4.3 lazyeval_0.2.2
[41] munsell_0.5.0 crayon_1.3.4