Last updated: 2019-10-21
Checks: 7 0
Knit directory: mr-ash-workflow/
This reproducible R Markdown analysis was created with workflowr (version 1.4.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(20191007)
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/
Ignored: analysis/ETA_1_lambda.dat
Ignored: analysis/ETA_1_parBayesB.dat
Ignored: analysis/mu.dat
Ignored: analysis/varE.dat
Untracked files:
Untracked: .DS_Store
Untracked: .Rapp.history
Untracked: docs/figure/Result9_Changepoint.Rmd/
Untracked: results/estsigma.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.
There are no past versions. Publish this analysis with wflow_publish()
to start tracking its development.
This documentation is to analyze the effect of parametrization. Our convention is to write y∼g if g is a probability density (with respect to a fixed measure). Let
g(β)=K∑k=1πkgk(β) is fixed and independent of σ2. Let’s simply consider the normal case when gk=N(0,σ2k).
Parametrization 1: This is what VARBVS uses. y|X,β,σ2∼N(Xβ,σ2In),βj|g,σ2=K∑k=1πkN(0,σ2σ2k),qj(βj)=K∑k=1ϕjkN(mjk,s2jk) The update of βj is based on q∗j=argmin which is a posterior of b_j|\beta_j,\sigma^2 \sim \mathcal{N}(\beta_j,\sigma^2 / (X^T X)_{jj}),\quad \beta_j|g \sim \sum_k \pi_k \mathcal{N}(0,\sigma_k^2) The update of \sigma^2 in this case is \sigma^2 = \frac{\|y - {\bf X}\mu\|^2 + \sum_j ({\bf X}^T{\bf X})_{jj} \mathrm{Var}[\beta_j] + \sum_j \sum_{k=2}^K \phi_{jk} (m_{jk}^2 + s_{jk}^2)/\sigma_k^2} {n + \sum_j \sum_{k=2}^K \phi_{jk}} = \frac{\|y - {\bf X}\mu\|^2 + \sum_j ({\bf X}^T{\bf X})_{jj} (\sum_{k} \phi_{jk} (m_{jk}^2 + s_{jk}^2) - \mu_j^2) + \sum_j \sum_{k=2}^K \phi_{jk} (m_{jk}^2 + s_{jk}^2)/\sigma_k^2} {n + \sum_j \sum_{k=2}^K \phi_{jk}}. This is the varbvsmix’s update of \sigma^2. Compared to the update of Parametrization 2 below, it has additional s_{jk}^2 terms on the numerator and the \sum_j \sum_{k=2}^K \phi_{jk} term on the denominator.
Parametrization 2: y|X,\beta,\sigma^2 \sim \mathcal{N}(X\beta,\sigma^2 I_n),\quad \beta_j | g, \sigma^2 = \sum_{k=1}^K \pi_k \mathcal{N}(0,\sigma^2\sigma_k^2), \quad q_j(\beta_j) = \sum_{k=1}^K \phi_{jk} \mathcal{N}(\mu_{jk},\sigma^2s_{jk}^2) The update of \beta_j is based on q_j^* = \arg\min_{q_j} \frac{(X^T X)_{jj}}{2\sigma^2}\mathbb{E}_{q_j} (\beta_j - b_j)^2 + D_{KL}(q_j\|g) which is a posterior of b_j|\beta_j,\sigma^2 \sim \mathcal{N}(\beta_j,\sigma^2 / (X^T X)_{jj}),\quad \beta_j|g \sim \sum_k \pi_k \mathcal{N}(0,\sigma^2\sigma_k^2) where b_j = \mathbb{E}_q \beta_j + (X^T X)_{jj}^{-1}(y - X\beta). The update of \sigma^2 in this case is \sigma^2 = \frac{\|y - {\bf X}\mu\|^2 + \sum_j ({\bf X}^T{\bf X})_{jj} (\sum_{k} \phi_{jk} m_{jk}^2 - \mu_j^2) + \sum_j \sum_{k=2}^K \phi_{jk} m_{jk}^2/\sigma_k^2} {n}. This can be reduced to \sigma^2 = \frac{\|y - {\bf X}\mu\|^2 + \sum_j ({\bf X}^T{\bf X})_{jj} (b_j\mu_j - \mu_j^2)} {n}.
Parametrization 3: y|X,\beta,\sigma^2 \sim \mathcal{N}(\sigma X\beta,\sigma^2 I_n),\quad \beta_j | g = \sum_{k=1}^K \pi_k \mathcal{N}(0,\sigma_k^2), \quad q_j(\beta_j) = \sum_{k=1}^K \phi_{jk} \mathcal{N}(\mu_{jk},s_{jk}^2) The update of \beta_j is based on q_j^* = \arg\min_{q_j} \frac{(X^T X)_{jj}}{2\sigma^2}\mathbb{E}_{q_j} (\beta_j - b_j)^2 + D_{KL}(q_j\|g) which is a posterior of b_j|\beta_j,\sigma^2 \sim \mathcal{N}(\beta_j,1 / (X^T X)_{jj}),\quad \beta_j|g \sim \sum_k \pi_k \mathcal{N}(0,\sigma_k^2) where b_j = \mathbb{E}_q \beta_j + (X^T X)_{jj}^{-1}(y / \sigma - X\beta). In this case, the update of \sigma^2 is \sigma^2 = \arg\min_{\sigma} \frac{n}{2} \log(\sigma^2) + \frac{1}{2\sigma^2}\mathbb{E}_q \|y - \sigma X\beta \|^2 = \arg \min_\sigma \frac{n}{2} \log(\sigma^2) + \frac{1}{2\sigma^2} (y^T y - 2\sigma y^T X \mu) = \arg \min_\sigma A\log(\sigma^2) - \frac{2B}{\sigma} + \frac{C}{\sigma^2} where A = n, B = y^T X\mu and C = y^T y. Thus \sigma is a solution to 2A \sigma^2 + 2B \sigma - 2C = 0 \iff \sigma = \frac{-B + \sqrt{B^2 + 4AC}}{2A} = \frac{-(y^T X\mu) + \sqrt{(y^T X\mu)^2 + 4n(y^T y)}}{2n}
tdat = readRDS("results/estsigma.RDS")
res = matrix(0,4,3)
for (i in 1:4) {
res[i,] = colMeans(matrix(tdat[[i]]$sigma, 20, 3))
}
colnames(res) = c("original","Matthew","varbvsmix")
rownames(res) = c("pve = 0.1","pve = 0.5","pve = 0.9","pve = 0.9999")
print("average value of (sigma_est / sigma_true)")
[1] "average value of (sigma_est / sigma_true)"
res
original Matthew varbvsmix
pve = 0.1 1.061100 1.0610999 1.061073
pve = 0.5 1.039929 1.0399285 1.039890
pve = 0.9 1.003104 1.0030930 1.003073
pve = 0.9999 1.081021 0.7813146 3.597446
res = matrix(0,4,3)
for (i in 1:4) {
res[i,] = colMeans(matrix(tdat[[i]]$rate, 20, 3))
}
colnames(res) = c("original","Matthew","varbvsmix")
rownames(res) = c("pve = 0.1","pve = 0.5","pve = 0.9","pve = 0.9999")
print("average value of min(sigma_est / sigma_true, sigma_true / sigma_est)")
[1] "average value of min(sigma_est / sigma_true, sigma_true / sigma_est)"
res
original Matthew varbvsmix
pve = 0.1 0.9269040 0.9269038 0.9269171
pve = 0.5 0.9318945 0.9318945 0.9318989
pve = 0.9 0.9291743 0.9291845 0.9292332
pve = 0.9999 0.9247187 0.7813146 0.3561272
res = matrix(0,4,3)
for (i in 1:4) {
res[i,] = colMeans(matrix(tdat[[i]]$pred, 20, 3))
}
colnames(res) = c("original","Matthew","varbvsmix")
rownames(res) = c("pve = 0.1","pve = 0.5","pve = 0.9","pve = 0.9999")
print("prediction error (RMSE_test / sigma_true)")
[1] "prediction error (RMSE_test / sigma_true)"
res
original Matthew varbvsmix
pve = 0.1 1.040558 1.040652 1.040556
pve = 0.5 1.059430 1.060562 1.059428
pve = 0.9 1.035987 1.037942 1.036011
pve = 0.9999 1.012091 112.557985 1.014590
library(Matrix); library(ggplot2); library(cowplot); library(mr.ash); library(varbvs)
standardize = FALSE
source('code/method_wrapper.R')
source('code/sim_wrapper.R')
n = 500
p = 2000
s = 20
sa2 = (2^((0:19)/5) - 1)^2
K = length(sa2)
time = matrix(0,20,3)
sigma = matrix(0,20,3)
rate = matrix(0,20,3)
pred = matrix(0,20,3)
pve_list = c(0.1,0.5,0.9,0.9999)
tdat = list()
for (iter in 1:4) {
for (i in 1:20) {
data = simulate_data(n, p, s = s, seed = i, signal = "normal",
design = "indepgauss", pve = pve_list[iter])
#sigma.init = var(data$y)
sigma.init = data$sigma^2
t.mr.ash1 = system.time(
fit.mr.ash1 <- mr.ash(X = data$X, y = data$y, sa2 = sa2, sigma2 = sigma.init,
max.iter = 2000, min.iter = 1,
standardize = standardize,
tol = list(epstol = 1e-12, convtol = 1e-8)))
t.mr.ash2 = system.time(
fit.mr.ash2 <- mr.ash(X = data$X, y = data$y, sa2 = sa2, method = "em2",
max.iter = 2000, min.iter = 1, sigma2 = sigma.init,
standardize = standardize,
tol = list(epstol = 1e-12, convtol = 1e-8)))
t.varbvsmix = system.time(
fit.varbvsmix <- varbvsmix(X = data$X, Z = NULL, y = data$y, sa = sa2,
mu = matrix(0, p, K), sigma = sigma.init,
alpha = matrix(1, p, K) / K, update.sa = FALSE,
update.sigma = TRUE, verbose = FALSE))
pred1 = data$y.test - predict(fit.mr.ash1, data$X.test)
pred2 = data$y.test - data$X.test %*% fit.mr.ash2$beta * sqrt(fit.mr.ash2$sigma) - fit.mr.ash2$intercept
pred3 = data$y.test - data$X.test %*% c(rowSums(fit.varbvsmix$alpha * fit.varbvsmix$mu)) - fit.varbvsmix$mu.cov
pred[i,] <- c(norm(pred1, '2'), norm(pred2, '2'), norm(pred3, '2')) / sqrt(n) / data$sigma
a = fit.mr.ash1$sigma / data$sigma^2
b = fit.mr.ash2$sigma / data$sigma^2
c = fit.varbvsmix$sigma / data$sigma^2
time[i,] = c(t.mr.ash1[3], t.mr.ash2[3], t.varbvsmix[3])
rate[i,] = c("caisa" = min(a,1/a), "new" = min(b, 1/b), "varbvsmix" = min(c, 1/c))
sigma[i,] = c(a,b,c)
}
tdat[[iter]] = data.frame(pred = c(pred), time = c(time), rate = c(rate), sigma = c(sigma),
fit = c("caisa","new","varbvsmix"))
print(colMeans(pred))
print(colMeans(rate))
}
sessionInfo()
R version 3.5.3 (2019-03-11)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Mojave 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
loaded via a namespace (and not attached):
[1] workflowr_1.4.0 Rcpp_1.0.2 digest_0.6.21 rprojroot_1.3-2
[5] backports_1.1.4 git2r_0.26.1 magrittr_1.5 evaluate_0.14
[9] stringi_1.4.3 fs_1.3.1 rmarkdown_1.15 tools_3.5.3
[13] stringr_1.4.0 glue_1.3.1 xfun_0.9 yaml_2.2.0
[17] compiler_3.5.3 htmltools_0.3.6 knitr_1.25