Last updated: 2020-05-08
Checks: 6 0
Knit directory: FLASHvestigations/
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(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.
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: analysis/.DS_Store
Ignored: code/.DS_Store
Ignored: code/flashier_bench/.DS_Store
Ignored: data/.DS_Store
Ignored: data/flashier_bench/
Ignored: data/metabo3_gwas_mats.RDS
Ignored: output/jean/
Untracked files:
Untracked: analysis/batting_order.Rmd
Untracked: code/fasfunction.R
Untracked: code/nnmf.R
Untracked: code/wals.R
Untracked: data/BR_teams_2019.csv
Untracked: data/FG_teams_2019.csv
Untracked: data/batting_order.rds
Untracked: data/cole.rds
Untracked: data/odorizzi.rds
Untracked: data/pitcher.rds
Untracked: data/pitcher2.rds
Untracked: data/pitcher_all.rds
Untracked: mlb2.R
Untracked: mlb_standings.txt
Untracked: ottoneu.R
Untracked: phoible.R
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 | 4afebf9 | Jason Willwerscheid | 2020-05-08 | wflow_publish(“analysis/ebnm_npmle.Rmd”) |
html | 93fda13 | Jason Willwerscheid | 2020-04-29 | Build site. |
Rmd | 8420f5d | Jason Willwerscheid | 2020-04-29 | wflow_publish(“analysis/ebnm_npmle.Rmd”) |
I want to test out approximations of NPMLEs using a dense ashr
grid. Let \(x_1, \ldots, x_n\) be \(n\) observations with standard errors equal to 1. Dicker and Zhao show that when the true NPMLE has compact support, then a good approximation can be obtained by optimizing over the family of distributions that’s supported on \(\sqrt{n}\) equally spaced points between \(\min (x)\) and \(\max (x)\). Instead of using point masses, I use an ashr
grid with \(\sqrt{n}\) uniform components of equal width. Let’s see how it works in practice.
Here’s the true distribution which I’ll be sampling from. It’s bimodal with peaks at -5 and 5, so a unimodal prior family wouldn’t work very well.
suppressMessages(library(tidyverse))
true_g <- ashr::normalmix(pi = rep(0.1, 10),
mean = c(rep(-5, 5), rep(5, 5)),
sd = c(0:4, 0:4))
cdf_grid <- seq(-20, 20, by = 0.1)
true_cdf <- drop(ashr::mixcdf(true_g, cdf_grid))
ggplot(tibble(x = cdf_grid, y = true_cdf), aes(x = x, y = y)) + geom_line()
Version | Author | Date |
---|---|---|
93fda13 | Jason Willwerscheid | 2020-04-29 |
I start by sampling 1000 observations and adding normally distributed noise.
samp_from_g <- function(g, n) {
comp <- sample(1:length(g$pi), n, replace = TRUE, prob = g$pi)
mean <- g$mean[comp]
sd <- g$sd[comp]
return(rnorm(n, mean = mean, sd = sd))
}
set.seed(666)
n <- 1000
samp <- samp_from_g(true_g, n) + rnorm(n)
ggplot(tibble(x = samp), aes(x = x)) + geom_histogram(binwidth = 1)
Version | Author | Date |
---|---|---|
93fda13 | Jason Willwerscheid | 2020-04-29 |
I want to see how grid density affects convergence properties and the quality of the solution. From a log likelihood perspective, using a grid of points spaced at a distance equal to half the standard deviation of the noise gives a solution that is pretty much just as good as a very fine grid:
mixsqp_control = list(verbose = TRUE)
scale_vec <- exp(seq(-2.5, 0, by = 0.5))
res_list <- list()
for (scale in scale_vec) {
ebnm_res <- ebnm::ebnm_npmle(samp, scale = scale, control = mixsqp_control)
res_list <- c(res_list, list(ebnm_res))
}
#> Running mix-SQP algorithm 0.3-39 on 1000 x 333 matrix
#> convergence tol. (SQP): 1.0e-08
#> conv. tol. (active-set): 1.0e-10
#> zero threshold (solution): 1.0e-08
#> zero thresh. (search dir.): 1.0e-14
#> l.s. sufficient decrease: 1.0e-02
#> step size reduction factor: 7.5e-01
#> minimum step size: 1.0e-08
#> max. iter (SQP): 1000
#> max. iter (active-set): 20
#> number of EM iterations: 20
#> Computing SVD of 1000 x 333 matrix.
#> SVD computation took 0.21 seconds.
#> Rank of matrix is estimated to be 54.
#> iter objective max(rdual) nnz stepsize max.diff nqp nls
#> 1 +2.011796452e+00 -- EM -- 333 1.00e+00 4.41e-03 -- --
#> 2 +1.992414270e+00 -- EM -- 333 1.00e+00 1.60e-03 -- --
#> 3 +1.988522596e+00 -- EM -- 333 1.00e+00 8.49e-04 -- --
#> 4 +1.986781647e+00 -- EM -- 333 1.00e+00 5.72e-04 -- --
#> 5 +1.985687545e+00 -- EM -- 333 1.00e+00 4.51e-04 -- --
#> 6 +1.984913363e+00 -- EM -- 333 1.00e+00 3.85e-04 -- --
#> 7 +1.984332567e+00 -- EM -- 333 1.00e+00 3.41e-04 -- --
#> 8 +1.983879139e+00 -- EM -- 333 1.00e+00 3.08e-04 -- --
#> 9 +1.983514156e+00 -- EM -- 333 1.00e+00 2.81e-04 -- --
#> 10 +1.983213153e+00 -- EM -- 333 1.00e+00 2.58e-04 -- --
#> 11 +1.982960026e+00 -- EM -- 333 1.00e+00 2.37e-04 -- --
#> 12 +1.982743762e+00 -- EM -- 333 1.00e+00 2.20e-04 -- --
#> 13 +1.982556580e+00 -- EM -- 333 1.00e+00 2.04e-04 -- --
#> 14 +1.982392820e+00 -- EM -- 333 1.00e+00 1.89e-04 -- --
#> 15 +1.982248263e+00 -- EM -- 333 1.00e+00 1.77e-04 -- --
#> 16 +1.982119692e+00 -- EM -- 333 1.00e+00 1.65e-04 -- --
#> 17 +1.982004604e+00 -- EM -- 333 1.00e+00 1.55e-04 -- --
#> 18 +1.981901017e+00 -- EM -- 333 1.00e+00 1.46e-04 -- --
#> 19 +1.981807336e+00 -- EM -- 333 1.00e+00 1.38e-04 -- --
#> 20 +1.981722260e+00 -- EM -- 333 1.00e+00 1.30e-04 -- --
#> 1 +1.981644714e+00 +2.724e-02 333 ------ ------ -- --
#> 2 +1.981574057e+00 +2.612e-02 313 1.00e+00 4.18e-04 20 1
#> 3 +1.981509579e+00 +2.510e-02 293 1.00e+00 4.64e-04 20 1
#> 4 +1.981450312e+00 +2.411e-02 273 1.00e+00 6.43e-04 20 1
#> 5 +1.981395713e+00 +2.316e-02 253 1.00e+00 1.76e-03 20 1
#> 6 +1.981345333e+00 +2.227e-02 233 1.00e+00 4.64e-03 20 1
#> 7 +1.981298555e+00 +2.141e-02 213 1.00e+00 2.62e-03 20 1
#> 8 +1.981254964e+00 +2.056e-02 193 1.00e+00 4.51e-03 20 1
#> 9 +1.981214243e+00 +1.974e-02 173 1.00e+00 6.99e-03 20 1
#> 10 +1.981176158e+00 +1.894e-02 153 1.00e+00 1.58e-02 20 1
#> 11 +1.981140518e+00 +1.815e-02 133 1.00e+00 1.61e-02 20 1
#> 12 +1.981107313e+00 +1.738e-02 113 1.00e+00 1.10e-02 20 1
#> 13 +1.981076238e+00 +1.662e-02 93 1.00e+00 1.84e-02 20 1
#> 14 +1.981046794e+00 +1.588e-02 73 1.00e+00 2.94e-02 20 1
#> 15 +1.981018759e+00 +1.515e-02 53 1.00e+00 3.05e-02 20 1
#> 16 +1.980963406e+00 +1.318e-02 33 1.00e+00 1.16e-01 20 1
#> 17 +1.979931743e+00 +2.785e-03 21 1.00e+00 1.37e-01 20 1
#> 18 +1.979774527e+00 +1.645e-04 19 1.00e+00 4.00e-02 20 1
#> 19 +1.979588348e+00 +1.284e-05 19 1.00e+00 2.49e-01 20 1
#> 20 +1.979566452e+00 +7.207e-05 20 1.00e+00 8.14e-02 20 1
#> 21 +1.979556652e+00 -5.155e-06 21 1.00e+00 6.55e-02 20 1
#> Optimization took 5.88 seconds.
#> Convergence criteria met---optimal solution found.
#> Running mix-SQP algorithm 0.3-39 on 1000 x 202 matrix
#> convergence tol. (SQP): 1.0e-08
#> conv. tol. (active-set): 1.0e-10
#> zero threshold (solution): 1.0e-08
#> zero thresh. (search dir.): 1.0e-14
#> l.s. sufficient decrease: 1.0e-02
#> step size reduction factor: 7.5e-01
#> minimum step size: 1.0e-08
#> max. iter (SQP): 1000
#> max. iter (active-set): 20
#> number of EM iterations: 20
#> Computing SVD of 1000 x 202 matrix.
#> SVD computation took 0.12 seconds.
#> Rank of matrix is estimated to be 54.
#> iter objective max(rdual) nnz stepsize max.diff nqp nls
#> 1 +2.010871416e+00 -- EM -- 202 1.00e+00 7.27e-03 -- --
#> 2 +1.991469270e+00 -- EM -- 202 1.00e+00 2.64e-03 -- --
#> 3 +1.987573534e+00 -- EM -- 202 1.00e+00 1.40e-03 -- --
#> 4 +1.985831384e+00 -- EM -- 202 1.00e+00 9.43e-04 -- --
#> 5 +1.984736562e+00 -- EM -- 202 1.00e+00 7.43e-04 -- --
#> 6 +1.983961793e+00 -- EM -- 202 1.00e+00 6.34e-04 -- --
#> 7 +1.983380490e+00 -- EM -- 202 1.00e+00 5.63e-04 -- --
#> 8 +1.982926620e+00 -- EM -- 202 1.00e+00 5.08e-04 -- --
#> 9 +1.982561245e+00 -- EM -- 202 1.00e+00 4.62e-04 -- --
#> 10 +1.982259891e+00 -- EM -- 202 1.00e+00 4.24e-04 -- --
#> 11 +1.982006442e+00 -- EM -- 202 1.00e+00 3.90e-04 -- --
#> 12 +1.981789882e+00 -- EM -- 202 1.00e+00 3.60e-04 -- --
#> 13 +1.981602423e+00 -- EM -- 202 1.00e+00 3.34e-04 -- --
#> 14 +1.981438405e+00 -- EM -- 202 1.00e+00 3.11e-04 -- --
#> 15 +1.981293605e+00 -- EM -- 202 1.00e+00 2.90e-04 -- --
#> 16 +1.981164803e+00 -- EM -- 202 1.00e+00 2.72e-04 -- --
#> 17 +1.981049497e+00 -- EM -- 202 1.00e+00 2.55e-04 -- --
#> 18 +1.980945702e+00 -- EM -- 202 1.00e+00 2.40e-04 -- --
#> 19 +1.980851823e+00 -- EM -- 202 1.00e+00 2.27e-04 -- --
#> 20 +1.980766560e+00 -- EM -- 202 1.00e+00 2.15e-04 -- --
#> 1 +1.980688834e+00 +2.705e-02 202 ------ ------ -- --
#> 2 +1.980618066e+00 +2.600e-02 182 1.00e+00 7.53e-04 20 1
#> 3 +1.980553569e+00 +2.161e-02 162 1.00e+00 2.63e-03 20 1
#> 4 +1.980494559e+00 +2.099e-02 142 1.00e+00 6.88e-03 20 1
#> 5 +1.980440360e+00 +2.043e-02 122 1.00e+00 7.47e-03 20 1
#> 6 +1.980390185e+00 +1.992e-02 102 1.00e+00 1.77e-02 20 1
#> 7 +1.980343849e+00 +1.942e-02 82 1.00e+00 2.86e-02 20 1
#> 8 +1.980300923e+00 +1.896e-02 62 1.00e+00 2.33e-02 20 1
#> 9 +1.980260466e+00 +1.849e-02 42 1.00e+00 6.00e-02 20 1
#> 10 +1.979173236e+00 +3.470e-03 22 1.00e+00 9.13e-02 20 1
#> 11 +1.978795443e+00 +1.148e-03 20 1.00e+00 6.14e-02 20 1
#> 12 +1.978702181e+00 +2.210e-04 21 1.00e+00 9.53e-02 20 1
#> 13 +1.978617979e+00 +6.352e-05 21 1.00e+00 1.39e-01 20 1
#> 14 +1.978593621e+00 -5.711e-06 21 1.00e+00 2.41e-01 20 1
#> Optimization took 1.08 seconds.
#> Convergence criteria met---optimal solution found.
#> Running mix-SQP algorithm 0.3-39 on 1000 x 123 matrix
#> convergence tol. (SQP): 1.0e-08
#> conv. tol. (active-set): 1.0e-10
#> zero threshold (solution): 1.0e-08
#> zero thresh. (search dir.): 1.0e-14
#> l.s. sufficient decrease: 1.0e-02
#> step size reduction factor: 7.5e-01
#> minimum step size: 1.0e-08
#> max. iter (SQP): 1000
#> max. iter (active-set): 20
#> number of EM iterations: 20
#> Computing SVD of 1000 x 123 matrix.
#> Matrix is not low-rank; falling back to full matrix.
#> iter objective max(rdual) nnz stepsize max.diff nqp nls
#> 1 +2.008470006e+00 -- EM -- 123 1.00e+00 1.19e-02 -- --
#> 2 +1.989014265e+00 -- EM -- 123 1.00e+00 4.35e-03 -- --
#> 3 +1.985107611e+00 -- EM -- 123 1.00e+00 2.30e-03 -- --
#> 4 +1.983362239e+00 -- EM -- 123 1.00e+00 1.55e-03 -- --
#> 5 +1.982265495e+00 -- EM -- 123 1.00e+00 1.22e-03 -- --
#> 6 +1.981489155e+00 -- EM -- 123 1.00e+00 1.04e-03 -- --
#> 7 +1.980906498e+00 -- EM -- 123 1.00e+00 9.19e-04 -- --
#> 8 +1.980451444e+00 -- EM -- 123 1.00e+00 8.28e-04 -- --
#> 9 +1.980085021e+00 -- EM -- 123 1.00e+00 7.54e-04 -- --
#> 10 +1.979782722e+00 -- EM -- 123 1.00e+00 6.90e-04 -- --
#> 11 +1.979528412e+00 -- EM -- 123 1.00e+00 6.35e-04 -- --
#> 12 +1.979311056e+00 -- EM -- 123 1.00e+00 5.87e-04 -- --
#> 13 +1.979122857e+00 -- EM -- 123 1.00e+00 5.44e-04 -- --
#> 14 +1.978958144e+00 -- EM -- 123 1.00e+00 5.07e-04 -- --
#> 15 +1.978812689e+00 -- EM -- 123 1.00e+00 4.73e-04 -- --
#> 16 +1.978683269e+00 -- EM -- 123 1.00e+00 4.44e-04 -- --
#> 17 +1.978567376e+00 -- EM -- 123 1.00e+00 4.17e-04 -- --
#> 18 +1.978463025e+00 -- EM -- 123 1.00e+00 3.93e-04 -- --
#> 19 +1.978368616e+00 -- EM -- 123 1.00e+00 3.71e-04 -- --
#> 20 +1.978282848e+00 -- EM -- 123 1.00e+00 3.51e-04 -- --
#> 1 +1.978204641e+00 +2.750e-02 123 ------ ------ -- --
#> 2 +1.978133583e+00 +2.630e-02 103 1.00e+00 4.17e-03 20 1
#> 3 +1.978069312e+00 +2.524e-02 83 1.00e+00 2.53e-02 20 1
#> 4 +1.978010859e+00 +2.031e-02 63 1.00e+00 4.38e-02 20 1
#> 5 +1.977956319e+00 +1.991e-02 43 1.00e+00 5.01e-02 20 1
#> 6 +1.977440097e+00 +1.181e-02 23 1.00e+00 1.07e-01 20 1
#> 7 +1.976253978e+00 +3.962e-03 19 1.00e+00 8.34e-02 20 1
#> 8 +1.976171392e+00 +2.572e-04 20 1.00e+00 4.88e-02 20 1
#> 9 +1.976125135e+00 +1.732e-05 20 1.00e+00 8.51e-02 20 1
#> 10 +1.976113864e+00 -5.881e-06 22 1.00e+00 1.36e-01 20 1
#> Optimization took 0.37 seconds.
#> Convergence criteria met---optimal solution found.
#> Running mix-SQP algorithm 0.3-39 on 1000 x 75 matrix
#> convergence tol. (SQP): 1.0e-08
#> conv. tol. (active-set): 1.0e-10
#> zero threshold (solution): 1.0e-08
#> zero thresh. (search dir.): 1.0e-14
#> l.s. sufficient decrease: 1.0e-02
#> step size reduction factor: 7.5e-01
#> minimum step size: 1.0e-08
#> max. iter (SQP): 1000
#> max. iter (active-set): 20
#> number of EM iterations: 20
#> Computing SVD of 1000 x 75 matrix.
#> Matrix is not low-rank; falling back to full matrix.
#> iter objective max(rdual) nnz stepsize max.diff nqp nls
#> 1 +2.001920062e+00 -- EM -- 75 1.00e+00 1.95e-02 -- --
#> 2 +1.982320355e+00 -- EM -- 75 1.00e+00 7.13e-03 -- --
#> 3 +1.978384270e+00 -- EM -- 75 1.00e+00 3.76e-03 -- --
#> 4 +1.976630282e+00 -- EM -- 75 1.00e+00 2.52e-03 -- --
#> 5 +1.975528440e+00 -- EM -- 75 1.00e+00 1.97e-03 -- --
#> 6 +1.974747940e+00 -- EM -- 75 1.00e+00 1.67e-03 -- --
#> 7 +1.974161688e+00 -- EM -- 75 1.00e+00 1.48e-03 -- --
#> 8 +1.973703484e+00 -- EM -- 75 1.00e+00 1.33e-03 -- --
#> 9 +1.973334262e+00 -- EM -- 75 1.00e+00 1.21e-03 -- --
#> 10 +1.973029439e+00 -- EM -- 75 1.00e+00 1.10e-03 -- --
#> 11 +1.972772820e+00 -- EM -- 75 1.00e+00 1.01e-03 -- --
#> 12 +1.972553329e+00 -- EM -- 75 1.00e+00 9.36e-04 -- --
#> 13 +1.972363139e+00 -- EM -- 75 1.00e+00 8.68e-04 -- --
#> 14 +1.972196558e+00 -- EM -- 75 1.00e+00 8.08e-04 -- --
#> 15 +1.972049344e+00 -- EM -- 75 1.00e+00 7.55e-04 -- --
#> 16 +1.971918262e+00 -- EM -- 75 1.00e+00 7.08e-04 -- --
#> 17 +1.971800794e+00 -- EM -- 75 1.00e+00 6.66e-04 -- --
#> 18 +1.971694948e+00 -- EM -- 75 1.00e+00 6.28e-04 -- --
#> 19 +1.971599119e+00 -- EM -- 75 1.00e+00 5.94e-04 -- --
#> 20 +1.971511999e+00 -- EM -- 75 1.00e+00 5.63e-04 -- --
#> 1 +1.971432506e+00 +2.732e-02 75 ------ ------ -- --
#> 2 +1.971360224e+00 +2.629e-02 55 1.00e+00 2.41e-02 20 1
#> 3 +1.971270477e+00 +1.264e-02 35 1.00e+00 6.28e-02 20 1
#> 4 +1.969803909e+00 +4.659e-03 21 1.00e+00 1.23e-01 20 1
#> 5 +1.969590351e+00 +3.901e-04 23 1.00e+00 1.39e-01 20 1
#> 6 +1.969426720e+00 +3.357e-05 21 1.00e+00 8.78e-02 20 1
#> 7 +1.969394886e+00 -5.299e-06 22 1.00e+00 7.51e-02 13 1
#> Optimization took 0.09 seconds.
#> Convergence criteria met---optimal solution found.
#> Running mix-SQP algorithm 0.3-39 on 1000 x 45 matrix
#> convergence tol. (SQP): 1.0e-08
#> conv. tol. (active-set): 1.0e-10
#> zero threshold (solution): 1.0e-08
#> zero thresh. (search dir.): 1.0e-14
#> l.s. sufficient decrease: 1.0e-02
#> step size reduction factor: 7.5e-01
#> minimum step size: 1.0e-08
#> max. iter (SQP): 1000
#> max. iter (active-set): 20
#> number of EM iterations: 20
#> Computing SVD of 1000 x 45 matrix.
#> Matrix is not low-rank; falling back to full matrix.
#> iter objective max(rdual) nnz stepsize max.diff nqp nls
#> 1 +1.983903994e+00 -- EM -- 45 1.00e+00 3.24e-02 -- --
#> 2 +1.963896819e+00 -- EM -- 45 1.00e+00 1.20e-02 -- --
#> 3 +1.959876618e+00 -- EM -- 45 1.00e+00 6.09e-03 -- --
#> 4 +1.958098559e+00 -- EM -- 45 1.00e+00 3.75e-03 -- --
#> 5 +1.956982863e+00 -- EM -- 45 1.00e+00 2.92e-03 -- --
#> 6 +1.956191091e+00 -- EM -- 45 1.00e+00 2.50e-03 -- --
#> 7 +1.955595037e+00 -- EM -- 45 1.00e+00 2.23e-03 -- --
#> 8 +1.955128155e+00 -- EM -- 45 1.00e+00 2.02e-03 -- --
#> 9 +1.954751115e+00 -- EM -- 45 1.00e+00 1.85e-03 -- --
#> 10 +1.954439114e+00 -- EM -- 45 1.00e+00 1.71e-03 -- --
#> 11 +1.954175804e+00 -- EM -- 45 1.00e+00 1.58e-03 -- --
#> 12 +1.953950010e+00 -- EM -- 45 1.00e+00 1.46e-03 -- --
#> 13 +1.953753851e+00 -- EM -- 45 1.00e+00 1.35e-03 -- --
#> 14 +1.953581608e+00 -- EM -- 45 1.00e+00 1.26e-03 -- --
#> 15 +1.953429033e+00 -- EM -- 45 1.00e+00 1.17e-03 -- --
#> 16 +1.953292893e+00 -- EM -- 45 1.00e+00 1.09e-03 -- --
#> 17 +1.953170675e+00 -- EM -- 45 1.00e+00 1.02e-03 -- --
#> 18 +1.953060393e+00 -- EM -- 45 1.00e+00 9.53e-04 -- --
#> 19 +1.952960444e+00 -- EM -- 45 1.00e+00 8.92e-04 -- --
#> 20 +1.952869515e+00 -- EM -- 45 1.00e+00 8.37e-04 -- --
#> 1 +1.952786518e+00 +1.799e-02 45 ------ ------ -- --
#> 2 +1.952210633e+00 +1.414e-02 25 1.00e+00 5.85e-02 20 1
#> 3 +1.950781554e+00 +6.206e-03 19 1.00e+00 1.08e-01 20 1
#> 4 +1.950764842e+00 +9.368e-06 23 1.00e+00 3.61e-02 16 1
#> 5 +1.950764842e+00 -5.843e-06 23 1.00e+00 5.76e-05 20 1
#> Optimization took 0.02 seconds.
#> Convergence criteria met---optimal solution found.
#> Running mix-SQP algorithm 0.3-39 on 1000 x 28 matrix
#> convergence tol. (SQP): 1.0e-08
#> conv. tol. (active-set): 1.0e-10
#> zero threshold (solution): 1.0e-08
#> zero thresh. (search dir.): 1.0e-14
#> l.s. sufficient decrease: 1.0e-02
#> step size reduction factor: 7.5e-01
#> minimum step size: 1.0e-08
#> max. iter (SQP): 1000
#> max. iter (active-set): 20
#> number of EM iterations: 20
#> Computing SVD of 1000 x 28 matrix.
#> Matrix is not low-rank; falling back to full matrix.
#> iter objective max(rdual) nnz stepsize max.diff nqp nls
#> 1 +1.940511172e+00 -- EM -- 28 1.00e+00 5.13e-02 -- --
#> 2 +1.919496514e+00 -- EM -- 28 1.00e+00 1.94e-02 -- --
#> 3 +1.915264075e+00 -- EM -- 28 1.00e+00 1.00e-02 -- --
#> 4 +1.913430767e+00 -- EM -- 28 1.00e+00 6.25e-03 -- --
#> 5 +1.912288152e+00 -- EM -- 28 1.00e+00 4.40e-03 -- --
#> 6 +1.911476710e+00 -- EM -- 28 1.00e+00 3.55e-03 -- --
#> 7 +1.910865049e+00 -- EM -- 28 1.00e+00 3.17e-03 -- --
#> 8 +1.910385717e+00 -- EM -- 28 1.00e+00 2.89e-03 -- --
#> 9 +1.909998650e+00 -- EM -- 28 1.00e+00 2.67e-03 -- --
#> 10 +1.909678364e+00 -- EM -- 28 1.00e+00 2.47e-03 -- --
#> 11 +1.909407934e+00 -- EM -- 28 1.00e+00 2.30e-03 -- --
#> 12 +1.909175721e+00 -- EM -- 28 1.00e+00 2.14e-03 -- --
#> 13 +1.908973491e+00 -- EM -- 28 1.00e+00 1.99e-03 -- --
#> 14 +1.908795267e+00 -- EM -- 28 1.00e+00 1.86e-03 -- --
#> 15 +1.908636613e+00 -- EM -- 28 1.00e+00 1.74e-03 -- --
#> 16 +1.908494176e+00 -- EM -- 28 1.00e+00 1.62e-03 -- --
#> 17 +1.908365372e+00 -- EM -- 28 1.00e+00 1.52e-03 -- --
#> 18 +1.908248182e+00 -- EM -- 28 1.00e+00 1.42e-03 -- --
#> 19 +1.908141002e+00 -- EM -- 28 1.00e+00 1.34e-03 -- --
#> 20 +1.908042541e+00 -- EM -- 28 1.00e+00 1.25e-03 -- --
#> 1 +1.907951747e+00 +2.512e-02 28 ------ ------ -- --
#> 2 +1.906212170e+00 +1.758e-03 18 1.00e+00 3.54e-02 12 1
#> 3 +1.906211582e+00 -5.622e-06 18 1.00e+00 1.26e-03 2 1
#> Optimization took 0.01 seconds.
#> Convergence criteria met---optimal solution found.
ggplot(tibble(grid_dens = scale_vec,
llik = sapply(res_list, `[[`, "log_likelihood")),
aes(x = grid_dens, y = llik)) +
geom_point()
Visually, the CDFs are very similar for all densities less than 0.5 SD:
cdf_df <- tibble(x = rep(cdf_grid, length(res_list)),
y = as.vector(sapply(res_list,
function(res) drop(ashr::mixcdf(res$fitted_g, cdf_grid)))),
grid_dens = as.factor(rep(round(scale_vec, 2), each = length(cdf_grid))))
ggplot(cdf_df, aes(x = x, y = y, col = grid_dens)) +
geom_line()
Interestingly, the number of nonzero components is pretty much constant even as the total number of components increases:
cat("Number of components:\n",
rev(sapply(res_list, function(res) length(res$fitted_g$pi))), "\n",
"Number of nonzero components:\n",
rev(sapply(res_list, function(res) sum(res$fitted_g$pi > 0))))
#> Number of components:
#> 28 45 75 123 202 333
#> Number of nonzero components:
#> 18 23 22 22 21 21
I redo with 10000 observations. The same conclusions still hold, more or less. A good rule of thumb might be to set scale
equal to \(\text{SD} / \log_{10} (n)\):
n <- 10000
samp <- samp_from_g(true_g, n) + rnorm(n)
res_list <- list()
for (scale in scale_vec) {
ebnm_res <- ebnm::ebnm_npmle(samp, scale = scale, control = mixsqp_control)
res_list <- c(res_list, list(ebnm_res))
}
#> Running mix-SQP algorithm 0.3-39 on 10000 x 421 matrix
#> convergence tol. (SQP): 1.0e-08
#> conv. tol. (active-set): 1.0e-10
#> zero threshold (solution): 1.0e-08
#> zero thresh. (search dir.): 1.0e-14
#> l.s. sufficient decrease: 1.0e-02
#> step size reduction factor: 7.5e-01
#> minimum step size: 1.0e-08
#> max. iter (SQP): 1000
#> max. iter (active-set): 20
#> number of EM iterations: 20
#> Computing SVD of 10000 x 421 matrix.
#> SVD computation took 3.57 seconds.
#> Rank of matrix is estimated to be 70.
#> iter objective max(rdual) nnz stepsize max.diff nqp nls
#> 1 +2.024431705e+00 -- EM -- 421 1.00e+00 5.14e-03 -- --
#> 2 +2.005292240e+00 -- EM -- 421 1.00e+00 1.61e-03 -- --
#> 3 +2.001485507e+00 -- EM -- 421 1.00e+00 8.11e-04 -- --
#> 4 +1.999953997e+00 -- EM -- 421 1.00e+00 5.04e-04 -- --
#> 5 +1.999115254e+00 -- EM -- 421 1.00e+00 3.57e-04 -- --
#> 6 +1.998601264e+00 -- EM -- 421 1.00e+00 2.74e-04 -- --
#> 7 +1.998269736e+00 -- EM -- 421 1.00e+00 2.20e-04 -- --
#> 8 +1.998048473e+00 -- EM -- 421 1.00e+00 1.83e-04 -- --
#> 9 +1.997896397e+00 -- EM -- 421 1.00e+00 1.55e-04 -- --
#> 10 +1.997788855e+00 -- EM -- 421 1.00e+00 1.33e-04 -- --
#> 11 +1.997710587e+00 -- EM -- 421 1.00e+00 1.16e-04 -- --
#> 12 +1.997651931e+00 -- EM -- 421 1.00e+00 1.02e-04 -- --
#> 13 +1.997606659e+00 -- EM -- 421 1.00e+00 9.04e-05 -- --
#> 14 +1.997570694e+00 -- EM -- 421 1.00e+00 8.10e-05 -- --
#> 15 +1.997541325e+00 -- EM -- 421 1.00e+00 7.31e-05 -- --
#> 16 +1.997516726e+00 -- EM -- 421 1.00e+00 6.65e-05 -- --
#> 17 +1.997495650e+00 -- EM -- 421 1.00e+00 6.10e-05 -- --
#> 18 +1.997477235e+00 -- EM -- 421 1.00e+00 5.63e-05 -- --
#> 19 +1.997460876e+00 -- EM -- 421 1.00e+00 5.25e-05 -- --
#> 20 +1.997446142e+00 -- EM -- 421 1.00e+00 4.91e-05 -- --
#> 1 +1.997432723e+00 +2.350e-02 421 ------ ------ -- --
#> 2 +1.997420399e+00 +2.256e-02 401 1.00e+00 6.10e-05 20 1
#> 3 +1.997409003e+00 +2.169e-02 381 1.00e+00 1.82e-04 20 1
#> 4 +1.997398392e+00 +2.089e-02 361 1.00e+00 1.92e-04 20 1
#> 5 +1.997388454e+00 +2.018e-02 341 1.00e+00 3.97e-04 20 1
#> 6 +1.997379118e+00 +1.954e-02 321 1.00e+00 7.96e-04 20 1
#> 7 +1.997370339e+00 +1.898e-02 301 1.00e+00 1.66e-03 20 1
#> 8 +1.997362049e+00 +1.844e-02 281 1.00e+00 2.28e-03 20 1
#> 9 +1.997354191e+00 +1.792e-02 261 1.00e+00 2.54e-03 20 1
#> 10 +1.997346722e+00 +1.740e-02 241 1.00e+00 5.98e-03 20 1
#> 11 +1.997339656e+00 +1.687e-02 221 1.00e+00 4.23e-03 20 1
#> 12 +1.997332957e+00 +1.633e-02 201 1.00e+00 3.79e-03 20 1
#> 13 +1.997326508e+00 +1.578e-02 181 1.00e+00 1.22e-02 20 1
#> 14 +1.997320382e+00 +1.518e-02 161 1.00e+00 1.52e-02 20 1
#> 15 +1.997314604e+00 +1.462e-02 141 1.00e+00 1.08e-02 20 1
#> 16 +1.997309096e+00 +1.407e-02 121 1.00e+00 5.77e-03 20 1
#> 17 +1.997303852e+00 +1.353e-02 101 1.00e+00 7.02e-03 20 1
#> 18 +1.997298415e+00 +1.248e-02 81 1.00e+00 1.83e-02 20 1
#> 19 +1.997293212e+00 +1.145e-02 61 1.00e+00 4.12e-02 20 1
#> 20 +1.997278828e+00 +8.156e-03 41 1.00e+00 1.18e-01 20 1
#> 21 +1.997041649e+00 +1.031e-03 25 1.00e+00 1.18e-01 20 1
#> 22 +1.997034393e+00 +4.634e-05 26 1.00e+00 3.42e-03 20 1
#> 23 +1.996997194e+00 +3.545e-07 27 1.00e+00 1.62e-01 20 1
#> 24 +1.996990956e+00 -5.942e-06 29 1.00e+00 2.60e-02 20 1
#> Optimization took 16.50 seconds.
#> Convergence criteria met---optimal solution found.
#> Running mix-SQP algorithm 0.3-39 on 10000 x 256 matrix
#> convergence tol. (SQP): 1.0e-08
#> conv. tol. (active-set): 1.0e-10
#> zero threshold (solution): 1.0e-08
#> zero thresh. (search dir.): 1.0e-14
#> l.s. sufficient decrease: 1.0e-02
#> step size reduction factor: 7.5e-01
#> minimum step size: 1.0e-08
#> max. iter (SQP): 1000
#> max. iter (active-set): 20
#> number of EM iterations: 20
#> Computing SVD of 10000 x 256 matrix.
#> Matrix is not low-rank; falling back to full matrix.
#> iter objective max(rdual) nnz stepsize max.diff nqp nls
#> 1 +2.023505987e+00 -- EM -- 256 1.00e+00 8.44e-03 -- --
#> 2 +2.004346140e+00 -- EM -- 256 1.00e+00 2.64e-03 -- --
#> 3 +2.000534004e+00 -- EM -- 256 1.00e+00 1.33e-03 -- --
#> 4 +1.999000152e+00 -- EM -- 256 1.00e+00 8.29e-04 -- --
#> 5 +1.998159845e+00 -- EM -- 256 1.00e+00 5.88e-04 -- --
#> 6 +1.997644661e+00 -- EM -- 256 1.00e+00 4.51e-04 -- --
#> 7 +1.997312210e+00 -- EM -- 256 1.00e+00 3.63e-04 -- --
#> 8 +1.997090241e+00 -- EM -- 256 1.00e+00 3.02e-04 -- --
#> 9 +1.996937632e+00 -- EM -- 256 1.00e+00 2.55e-04 -- --
#> 10 +1.996829690e+00 -- EM -- 256 1.00e+00 2.19e-04 -- --
#> 11 +1.996751123e+00 -- EM -- 256 1.00e+00 1.91e-04 -- --
#> 12 +1.996692244e+00 -- EM -- 256 1.00e+00 1.67e-04 -- --
#> 13 +1.996646806e+00 -- EM -- 256 1.00e+00 1.49e-04 -- --
#> 14 +1.996610715e+00 -- EM -- 256 1.00e+00 1.33e-04 -- --
#> 15 +1.996581251e+00 -- EM -- 256 1.00e+00 1.20e-04 -- --
#> 16 +1.996556580e+00 -- EM -- 256 1.00e+00 1.10e-04 -- --
#> 17 +1.996535448e+00 -- EM -- 256 1.00e+00 1.01e-04 -- --
#> 18 +1.996516990e+00 -- EM -- 256 1.00e+00 9.31e-05 -- --
#> 19 +1.996500595e+00 -- EM -- 256 1.00e+00 8.66e-05 -- --
#> 20 +1.996485833e+00 -- EM -- 256 1.00e+00 8.11e-05 -- --
#> 1 +1.996472389e+00 +2.313e-02 256 ------ ------ -- --
#> 2 +1.996460049e+00 +2.232e-02 236 1.00e+00 1.58e-04 20 1
#> 3 +1.996448643e+00 +2.159e-02 216 1.00e+00 7.67e-04 20 1
#> 4 +1.996438030e+00 +1.968e-02 196 1.00e+00 1.12e-03 20 1
#> 5 +1.996428109e+00 +1.890e-02 176 1.00e+00 5.39e-03 20 1
#> 6 +1.996418794e+00 +1.809e-02 156 1.00e+00 1.08e-02 20 1
#> 7 +1.996409905e+00 +1.717e-02 136 1.00e+00 1.38e-02 20 1
#> 8 +1.996401592e+00 +1.617e-02 116 1.00e+00 2.78e-02 20 1
#> 9 +1.996393802e+00 +1.523e-02 96 1.00e+00 1.23e-02 20 1
#> 10 +1.996386208e+00 +1.402e-02 76 1.00e+00 2.65e-02 20 1
#> 11 +1.996378576e+00 +1.252e-02 56 1.00e+00 4.41e-02 20 1
#> 12 +1.996338164e+00 +8.490e-03 36 1.00e+00 9.75e-02 20 1
#> 13 +1.996099336e+00 +3.164e-04 27 1.00e+00 4.35e-02 20 1
#> 14 +1.996091475e+00 -6.183e-06 27 1.00e+00 1.10e-02 20 1
#> Optimization took 8.50 seconds.
#> Convergence criteria met---optimal solution found.
#> Running mix-SQP algorithm 0.3-39 on 10000 x 155 matrix
#> convergence tol. (SQP): 1.0e-08
#> conv. tol. (active-set): 1.0e-10
#> zero threshold (solution): 1.0e-08
#> zero thresh. (search dir.): 1.0e-14
#> l.s. sufficient decrease: 1.0e-02
#> step size reduction factor: 7.5e-01
#> minimum step size: 1.0e-08
#> max. iter (SQP): 1000
#> max. iter (active-set): 20
#> number of EM iterations: 20
#> Computing SVD of 10000 x 155 matrix.
#> Matrix is not low-rank; falling back to full matrix.
#> iter objective max(rdual) nnz stepsize max.diff nqp nls
#> 1 +2.021015099e+00 -- EM -- 155 1.00e+00 1.39e-02 -- --
#> 2 +2.001799345e+00 -- EM -- 155 1.00e+00 4.37e-03 -- --
#> 3 +1.997972385e+00 -- EM -- 155 1.00e+00 2.21e-03 -- --
#> 4 +1.996432112e+00 -- EM -- 155 1.00e+00 1.37e-03 -- --
#> 5 +1.995587520e+00 -- EM -- 155 1.00e+00 9.76e-04 -- --
#> 6 +1.995069059e+00 -- EM -- 155 1.00e+00 7.48e-04 -- --
#> 7 +1.994734071e+00 -- EM -- 155 1.00e+00 6.03e-04 -- --
#> 8 +1.994510162e+00 -- EM -- 155 1.00e+00 5.01e-04 -- --
#> 9 +1.994356084e+00 -- EM -- 155 1.00e+00 4.24e-04 -- --
#> 10 +1.994247040e+00 -- EM -- 155 1.00e+00 3.64e-04 -- --
#> 11 +1.994167648e+00 -- EM -- 155 1.00e+00 3.17e-04 -- --
#> 12 +1.994108152e+00 -- EM -- 155 1.00e+00 2.78e-04 -- --
#> 13 +1.994062253e+00 -- EM -- 155 1.00e+00 2.47e-04 -- --
#> 14 +1.994025817e+00 -- EM -- 155 1.00e+00 2.21e-04 -- --
#> 15 +1.993996091e+00 -- EM -- 155 1.00e+00 2.00e-04 -- --
#> 16 +1.993971220e+00 -- EM -- 155 1.00e+00 1.82e-04 -- --
#> 17 +1.993949934e+00 -- EM -- 155 1.00e+00 1.67e-04 -- --
#> 18 +1.993931354e+00 -- EM -- 155 1.00e+00 1.55e-04 -- --
#> 19 +1.993914862e+00 -- EM -- 155 1.00e+00 1.44e-04 -- --
#> 20 +1.993900020e+00 -- EM -- 155 1.00e+00 1.35e-04 -- --
#> 1 +1.993886508e+00 +2.331e-02 155 ------ ------ -- --
#> 2 +1.993874123e+00 +1.710e-02 135 1.00e+00 5.06e-04 20 1
#> 3 +1.993862764e+00 +1.527e-02 115 1.00e+00 4.38e-03 20 1
#> 4 +1.993852136e+00 +1.474e-02 95 1.00e+00 1.90e-02 20 1
#> 5 +1.993842303e+00 +1.426e-02 75 1.00e+00 2.70e-02 20 1
#> 6 +1.993832679e+00 +1.380e-02 55 1.00e+00 5.41e-02 20 1
#> 7 +1.993743300e+00 +6.595e-03 35 1.00e+00 9.65e-02 20 1
#> 8 +1.993523462e+00 +4.799e-04 28 1.00e+00 4.46e-02 20 1
#> 9 +1.993523448e+00 -5.974e-06 28 1.00e+00 1.46e-04 20 1
#> Optimization took 2.26 seconds.
#> Convergence criteria met---optimal solution found.
#> Running mix-SQP algorithm 0.3-39 on 10000 x 94 matrix
#> convergence tol. (SQP): 1.0e-08
#> conv. tol. (active-set): 1.0e-10
#> zero threshold (solution): 1.0e-08
#> zero thresh. (search dir.): 1.0e-14
#> l.s. sufficient decrease: 1.0e-02
#> step size reduction factor: 7.5e-01
#> minimum step size: 1.0e-08
#> max. iter (SQP): 1000
#> max. iter (active-set): 20
#> number of EM iterations: 20
#> Computing SVD of 10000 x 94 matrix.
#> Matrix is not low-rank; falling back to full matrix.
#> iter objective max(rdual) nnz stepsize max.diff nqp nls
#> 1 +2.014211990e+00 -- EM -- 94 1.00e+00 2.29e-02 -- --
#> 2 +1.994844637e+00 -- EM -- 94 1.00e+00 7.19e-03 -- --
#> 3 +1.990977384e+00 -- EM -- 94 1.00e+00 3.64e-03 -- --
#> 4 +1.989419703e+00 -- EM -- 94 1.00e+00 2.26e-03 -- --
#> 5 +1.988563494e+00 -- EM -- 94 1.00e+00 1.61e-03 -- --
#> 6 +1.988036125e+00 -- EM -- 94 1.00e+00 1.24e-03 -- --
#> 7 +1.987694219e+00 -- EM -- 94 1.00e+00 1.00e-03 -- --
#> 8 +1.987464997e+00 -- EM -- 94 1.00e+00 8.34e-04 -- --
#> 9 +1.987306886e+00 -- EM -- 94 1.00e+00 7.07e-04 -- --
#> 10 +1.987194803e+00 -- EM -- 94 1.00e+00 6.08e-04 -- --
#> 11 +1.987113132e+00 -- EM -- 94 1.00e+00 5.29e-04 -- --
#> 12 +1.987051929e+00 -- EM -- 94 1.00e+00 4.65e-04 -- --
#> 13 +1.987004750e+00 -- EM -- 94 1.00e+00 4.13e-04 -- --
#> 14 +1.986967350e+00 -- EM -- 94 1.00e+00 3.70e-04 -- --
#> 15 +1.986936895e+00 -- EM -- 94 1.00e+00 3.34e-04 -- --
#> 16 +1.986911466e+00 -- EM -- 94 1.00e+00 3.05e-04 -- --
#> 17 +1.986889749e+00 -- EM -- 94 1.00e+00 2.80e-04 -- --
#> 18 +1.986870830e+00 -- EM -- 94 1.00e+00 2.58e-04 -- --
#> 19 +1.986854068e+00 -- EM -- 94 1.00e+00 2.40e-04 -- --
#> 20 +1.986839003e+00 -- EM -- 94 1.00e+00 2.25e-04 -- --
#> 1 +1.986825306e+00 +2.345e-02 94 ------ ------ -- --
#> 2 +1.986812789e+00 +2.246e-02 74 1.00e+00 1.33e-02 20 1
#> 3 +1.986800937e+00 +2.120e-02 54 1.00e+00 4.23e-02 20 1
#> 4 +1.986693681e+00 +1.164e-02 34 1.00e+00 1.18e-01 20 1
#> 5 +1.986454060e+00 +4.429e-04 29 1.00e+00 6.01e-02 20 1
#> 6 +1.986448229e+00 -5.843e-06 29 1.00e+00 2.38e-03 20 1
#> Optimization took 0.68 seconds.
#> Convergence criteria met---optimal solution found.
#> Running mix-SQP algorithm 0.3-39 on 10000 x 57 matrix
#> convergence tol. (SQP): 1.0e-08
#> conv. tol. (active-set): 1.0e-10
#> zero threshold (solution): 1.0e-08
#> zero thresh. (search dir.): 1.0e-14
#> l.s. sufficient decrease: 1.0e-02
#> step size reduction factor: 7.5e-01
#> minimum step size: 1.0e-08
#> max. iter (SQP): 1000
#> max. iter (active-set): 20
#> number of EM iterations: 20
#> Computing SVD of 10000 x 57 matrix.
#> Matrix is not low-rank; falling back to full matrix.
#> iter objective max(rdual) nnz stepsize max.diff nqp nls
#> 1 +1.995993431e+00 -- EM -- 57 1.00e+00 3.70e-02 -- --
#> 2 +1.976214692e+00 -- EM -- 57 1.00e+00 1.16e-02 -- --
#> 3 +1.972237405e+00 -- EM -- 57 1.00e+00 5.96e-03 -- --
#> 4 +1.970632501e+00 -- EM -- 57 1.00e+00 3.74e-03 -- --
#> 5 +1.969744805e+00 -- EM -- 57 1.00e+00 2.68e-03 -- --
#> 6 +1.969193118e+00 -- EM -- 57 1.00e+00 2.08e-03 -- --
#> 7 +1.968832146e+00 -- EM -- 57 1.00e+00 1.69e-03 -- --
#> 8 +1.968588151e+00 -- EM -- 57 1.00e+00 1.41e-03 -- --
#> 9 +1.968418734e+00 -- EM -- 57 1.00e+00 1.20e-03 -- --
#> 10 +1.968298078e+00 -- EM -- 57 1.00e+00 1.03e-03 -- --
#> 11 +1.968209939e+00 -- EM -- 57 1.00e+00 8.99e-04 -- --
#> 12 +1.968143868e+00 -- EM -- 57 1.00e+00 7.91e-04 -- --
#> 13 +1.968093019e+00 -- EM -- 57 1.00e+00 7.03e-04 -- --
#> 14 +1.968052840e+00 -- EM -- 57 1.00e+00 6.31e-04 -- --
#> 15 +1.968020263e+00 -- EM -- 57 1.00e+00 5.70e-04 -- --
#> 16 +1.967993194e+00 -- EM -- 57 1.00e+00 5.19e-04 -- --
#> 17 +1.967970185e+00 -- EM -- 57 1.00e+00 4.76e-04 -- --
#> 18 +1.967950228e+00 -- EM -- 57 1.00e+00 4.40e-04 -- --
#> 19 +1.967932607e+00 -- EM -- 57 1.00e+00 4.09e-04 -- --
#> 20 +1.967916814e+00 -- EM -- 57 1.00e+00 3.83e-04 -- --
#> 1 +1.967902478e+00 +2.307e-02 57 ------ ------ -- --
#> 2 +1.967862203e+00 +1.489e-02 37 1.00e+00 3.16e-02 20 1
#> 3 +1.967543847e+00 +1.475e-03 29 1.00e+00 8.97e-02 20 1
#> 4 +1.967543808e+00 -5.771e-06 29 1.00e+00 1.00e-03 20 1
#> Optimization took 0.22 seconds.
#> Convergence criteria met---optimal solution found.
#> Running mix-SQP algorithm 0.3-39 on 10000 x 35 matrix
#> convergence tol. (SQP): 1.0e-08
#> conv. tol. (active-set): 1.0e-10
#> zero threshold (solution): 1.0e-08
#> zero thresh. (search dir.): 1.0e-14
#> l.s. sufficient decrease: 1.0e-02
#> step size reduction factor: 7.5e-01
#> minimum step size: 1.0e-08
#> max. iter (SQP): 1000
#> max. iter (active-set): 20
#> number of EM iterations: 20
#> Computing SVD of 10000 x 35 matrix.
#> Matrix is not low-rank; falling back to full matrix.
#> iter objective max(rdual) nnz stepsize max.diff nqp nls
#> 1 +1.951853222e+00 -- EM -- 35 1.00e+00 6.05e-02 -- --
#> 2 +1.931006703e+00 -- EM -- 35 1.00e+00 1.95e-02 -- --
#> 3 +1.926739177e+00 -- EM -- 35 1.00e+00 1.01e-02 -- --
#> 4 +1.925012384e+00 -- EM -- 35 1.00e+00 6.34e-03 -- --
#> 5 +1.924043980e+00 -- EM -- 35 1.00e+00 4.55e-03 -- --
#> 6 +1.923428706e+00 -- EM -- 35 1.00e+00 3.52e-03 -- --
#> 7 +1.923016357e+00 -- EM -- 35 1.00e+00 2.85e-03 -- --
#> 8 +1.922731218e+00 -- EM -- 35 1.00e+00 2.37e-03 -- --
#> 9 +1.922529262e+00 -- EM -- 35 1.00e+00 2.00e-03 -- --
#> 10 +1.922383141e+00 -- EM -- 35 1.00e+00 1.71e-03 -- --
#> 11 +1.922275244e+00 -- EM -- 35 1.00e+00 1.47e-03 -- --
#> 12 +1.922193954e+00 -- EM -- 35 1.00e+00 1.28e-03 -- --
#> 13 +1.922131460e+00 -- EM -- 35 1.00e+00 1.12e-03 -- --
#> 14 +1.922082433e+00 -- EM -- 35 1.00e+00 9.89e-04 -- --
#> 15 +1.922043184e+00 -- EM -- 35 1.00e+00 8.79e-04 -- --
#> 16 +1.922011132e+00 -- EM -- 35 1.00e+00 7.86e-04 -- --
#> 17 +1.921984446e+00 -- EM -- 35 1.00e+00 7.12e-04 -- --
#> 18 +1.921961820e+00 -- EM -- 35 1.00e+00 6.51e-04 -- --
#> 19 +1.921942307e+00 -- EM -- 35 1.00e+00 5.97e-04 -- --
#> 20 +1.921925217e+00 -- EM -- 35 1.00e+00 5.51e-04 -- --
#> 1 +1.921910042e+00 +8.142e-03 35 ------ ------ -- --
#> 2 +1.921511265e+00 +5.085e-04 28 1.00e+00 4.14e-02 12 1
#> 3 +1.921511234e+00 -5.629e-06 28 1.00e+00 3.08e-04 3 1
#> Optimization took 0.09 seconds.
#> Convergence criteria met---optimal solution found.
ggplot(tibble(grid_dens = scale_vec,
llik = sapply(res_list, `[[`, "log_likelihood")),
aes(x = grid_dens, y = llik)) +
geom_point()
cdf_df <- tibble(x = rep(cdf_grid, length(res_list)),
y = as.vector(sapply(res_list,
function(res) drop(ashr::mixcdf(res$fitted_g, cdf_grid)))),
grid_dens = as.factor(rep(round(scale_vec, 2), each = length(cdf_grid))))
ggplot(cdf_df, aes(x = x, y = y, col = grid_dens)) +
geom_line()
cat("Number of components:\n",
rev(sapply(res_list, function(res) length(res$fitted_g$pi))), "\n",
"Number of nonzero components:\n",
rev(sapply(res_list, function(res) sum(res$fitted_g$pi > 0))))
#> Number of components:
#> 35 57 94 155 256 421
#> Number of nonzero components:
#> 28 29 29 28 27 29
I include two examples with verbose output for inspection. Compare \(n = 10000\) with scale = 1 / 4
:
set.seed(666)
n <- 10000
samp <- samp_from_g(true_g, n) + rnorm(n)
g10000 <- ebnm::ebnm_npmle(samp, scale = 0.25, control = list(verbose = TRUE))
#> Running mix-SQP algorithm 0.3-39 on 10000 x 141 matrix
#> convergence tol. (SQP): 1.0e-08
#> conv. tol. (active-set): 1.0e-10
#> zero threshold (solution): 1.0e-08
#> zero thresh. (search dir.): 1.0e-14
#> l.s. sufficient decrease: 1.0e-02
#> step size reduction factor: 7.5e-01
#> minimum step size: 1.0e-08
#> max. iter (SQP): 1000
#> max. iter (active-set): 20
#> number of EM iterations: 20
#> Computing SVD of 10000 x 141 matrix.
#> Matrix is not low-rank; falling back to full matrix.
#> iter objective max(rdual) nnz stepsize max.diff nqp nls
#> 1 +2.021669639e+00 -- EM -- 141 1.00e+00 1.52e-02 -- --
#> 2 +2.003108745e+00 -- EM -- 141 1.00e+00 4.73e-03 -- --
#> 3 +1.999697243e+00 -- EM -- 141 1.00e+00 2.38e-03 -- --
#> 4 +1.998416351e+00 -- EM -- 141 1.00e+00 1.49e-03 -- --
#> 5 +1.997724431e+00 -- EM -- 141 1.00e+00 1.07e-03 -- --
#> 6 +1.997291274e+00 -- EM -- 141 1.00e+00 8.47e-04 -- --
#> 7 +1.997001201e+00 -- EM -- 141 1.00e+00 7.05e-04 -- --
#> 8 +1.996798354e+00 -- EM -- 141 1.00e+00 6.04e-04 -- --
#> 9 +1.996651348e+00 -- EM -- 141 1.00e+00 5.27e-04 -- --
#> 10 +1.996541268e+00 -- EM -- 141 1.00e+00 4.66e-04 -- --
#> 11 +1.996456255e+00 -- EM -- 141 1.00e+00 4.17e-04 -- --
#> 12 +1.996388659e+00 -- EM -- 141 1.00e+00 3.76e-04 -- --
#> 13 +1.996333437e+00 -- EM -- 141 1.00e+00 3.42e-04 -- --
#> 14 +1.996287192e+00 -- EM -- 141 1.00e+00 3.13e-04 -- --
#> 15 +1.996247599e+00 -- EM -- 141 1.00e+00 2.88e-04 -- --
#> 16 +1.996213038e+00 -- EM -- 141 1.00e+00 2.67e-04 -- --
#> 17 +1.996182366e+00 -- EM -- 141 1.00e+00 2.49e-04 -- --
#> 18 +1.996154761e+00 -- EM -- 141 1.00e+00 2.33e-04 -- --
#> 19 +1.996129627e+00 -- EM -- 141 1.00e+00 2.20e-04 -- --
#> 20 +1.996106521e+00 -- EM -- 141 1.00e+00 2.08e-04 -- --
#> 1 +1.996085115e+00 +2.593e-02 141 ------ ------ -- --
#> 2 +1.996065053e+00 +2.524e-02 121 1.00e+00 1.15e-03 20 1
#> 3 +1.996046287e+00 +2.414e-02 101 1.00e+00 8.55e-03 20 1
#> 4 +1.996028650e+00 +2.262e-02 81 1.00e+00 2.53e-02 20 1
#> 5 +1.996011918e+00 +2.092e-02 61 1.00e+00 3.00e-02 20 1
#> 6 +1.995978643e+00 +1.922e-02 41 1.00e+00 1.20e-01 20 1
#> 7 +1.995479254e+00 +3.028e-03 26 1.00e+00 4.68e-02 20 1
#> 8 +1.995453336e+00 +5.102e-04 27 1.00e+00 6.01e-03 20 1
#> 9 +1.995425984e+00 +1.469e-06 27 1.00e+00 5.12e-02 20 1
#> 10 +1.995412578e+00 -8.542e-07 30 1.00e+00 1.03e-01 20 1
#> Optimization took 1.99 seconds.
#> Convergence criteria met---optimal solution found.
and \(n = 100000\) with scale = 1 / 5
:
set.seed(666)
n <- 100000
samp <- samp_from_g(true_g, n) + rnorm(n)
g100000 <- ebnm::ebnm_npmle(samp, scale = 0.2, control = list(verbose = TRUE))
#> Running mix-SQP algorithm 0.3-39 on 100000 x 206 matrix
#> convergence tol. (SQP): 1.0e-08
#> conv. tol. (active-set): 1.0e-10
#> zero threshold (solution): 1.0e-08
#> zero thresh. (search dir.): 1.0e-14
#> l.s. sufficient decrease: 1.0e-02
#> step size reduction factor: 7.5e-01
#> minimum step size: 1.0e-08
#> max. iter (SQP): 1000
#> max. iter (active-set): 20
#> number of EM iterations: 20
#> Computing SVD of 100000 x 206 matrix.
#> Matrix is not low-rank; falling back to full matrix.
#> iter objective max(rdual) nnz stepsize max.diff nqp nls
#> 1 +2.027223557e+00 -- EM -- 206 1.00e+00 1.32e-02 -- --
#> 2 +2.008410910e+00 -- EM -- 206 1.00e+00 3.89e-03 -- --
#> 3 +2.004864385e+00 -- EM -- 206 1.00e+00 1.97e-03 -- --
#> 4 +2.003493379e+00 -- EM -- 206 1.00e+00 1.23e-03 -- --
#> 5 +2.002746710e+00 -- EM -- 206 1.00e+00 8.83e-04 -- --
#> 6 +2.002283415e+00 -- EM -- 206 1.00e+00 6.85e-04 -- --
#> 7 +2.001978999e+00 -- EM -- 206 1.00e+00 5.58e-04 -- --
#> 8 +2.001771577e+00 -- EM -- 206 1.00e+00 4.68e-04 -- --
#> 9 +2.001625879e+00 -- EM -- 206 1.00e+00 4.00e-04 -- --
#> 10 +2.001520556e+00 -- EM -- 206 1.00e+00 3.46e-04 -- --
#> 11 +2.001442247e+00 -- EM -- 206 1.00e+00 3.04e-04 -- --
#> 12 +2.001382396e+00 -- EM -- 206 1.00e+00 2.69e-04 -- --
#> 13 +2.001335418e+00 -- EM -- 206 1.00e+00 2.41e-04 -- --
#> 14 +2.001297602e+00 -- EM -- 206 1.00e+00 2.18e-04 -- --
#> 15 +2.001266443e+00 -- EM -- 206 1.00e+00 1.98e-04 -- --
#> 16 +2.001240223e+00 -- EM -- 206 1.00e+00 1.82e-04 -- --
#> 17 +2.001217743e+00 -- EM -- 206 1.00e+00 1.68e-04 -- --
#> 18 +2.001198156e+00 -- EM -- 206 1.00e+00 1.56e-04 -- --
#> 19 +2.001180852e+00 -- EM -- 206 1.00e+00 1.46e-04 -- --
#> 20 +2.001165386e+00 -- EM -- 205 1.00e+00 1.37e-04 -- --
#> 1 +2.001151433e+00 +1.545e-02 205 ------ ------ -- --
#> 2 +2.001138745e+00 +1.456e-02 185 1.00e+00 1.27e-04 20 1
#> 3 +2.001127136e+00 +1.372e-02 165 1.00e+00 3.26e-04 20 1
#> 4 +2.001116433e+00 +1.293e-02 145 1.00e+00 1.30e-03 20 1
#> 5 +2.001106483e+00 +1.290e-02 125 1.00e+00 6.38e-03 20 1
#> 6 +2.001097281e+00 +1.310e-02 105 1.00e+00 1.31e-02 20 1
#> 7 +2.001088677e+00 +1.310e-02 85 1.00e+00 1.52e-02 20 1
#> 8 +2.001080384e+00 +1.230e-02 65 1.00e+00 3.06e-02 20 1
#> 9 +2.001057776e+00 +4.822e-03 45 1.00e+00 8.57e-02 20 1
#> 10 +2.000856234e+00 +1.105e-04 34 1.00e+00 4.51e-02 20 1
#> 11 +2.000856230e+00 -5.901e-06 34 1.00e+00 1.31e-03 20 1
#> Optimization took 36.68 seconds.
#> Convergence criteria met---optimal solution found.
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 purrr_0.3.2
#> [5] readr_1.3.1 tidyr_0.8.3 tibble_2.1.1 ggplot2_3.2.0
#> [9] tidyverse_1.2.1
#>
#> loaded via a namespace (and not attached):
#> [1] tidyselect_0.2.5 xfun_0.6 ashr_2.2-50
#> [4] haven_2.1.1 lattice_0.20-38 colorspace_1.4-1
#> [7] generics_0.0.2 htmltools_0.3.6 yaml_2.2.0
#> [10] rlang_0.4.2 mixsqp_0.3-39 pillar_1.3.1
#> [13] glue_1.3.1 withr_2.1.2 modelr_0.1.5
#> [16] readxl_1.3.1 munsell_0.5.0 gtable_0.3.0
#> [19] workflowr_1.2.0 cellranger_1.1.0 rvest_0.3.4
#> [22] evaluate_0.13 labeling_0.3 knitr_1.22
#> [25] invgamma_1.1 irlba_2.3.3 broom_0.5.1
#> [28] Rcpp_1.0.1 scales_1.0.0 backports_1.1.3
#> [31] jsonlite_1.6 truncnorm_1.0-8 fs_1.2.7
#> [34] hms_0.4.2 digest_0.6.18 stringi_1.4.3
#> [37] ebnm_0.1-21 grid_3.5.3 rprojroot_1.3-2
#> [40] cli_1.1.0 tools_3.5.3 magrittr_1.5
#> [43] lazyeval_0.2.2 crayon_1.3.4 whisker_0.3-2
#> [46] pkgconfig_2.0.2 Matrix_1.2-15 SQUAREM_2017.10-1
#> [49] xml2_1.2.0 lubridate_1.7.4 assertthat_0.2.1
#> [52] rmarkdown_1.12 httr_1.4.0 rstudioapi_0.10
#> [55] R6_2.4.0 nlme_3.1-137 git2r_0.25.2
#> [58] compiler_3.5.3