Last updated: 2020-11-10

Checks: 7 0

Knit directory: mmbr-rss-dsc/

This reproducible R Markdown analysis was created with workflowr (version 1.6.2). 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(20200227) 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 results in this page were generated with repository version 034ffad. See the Past versions tab to see a history of the changes made to the R Markdown and HTML files.

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:    output/.DS_Store

Untracked files:
    Untracked:  code/mvsusie.R
    Untracked:  data/ENSG00000140265.12.Multi_Tissues.rds
    Untracked:  data/FastQTLSumStats.mash.FL_PC3.rds
    Untracked:  output/.mmbr_gtex_res.Rprof.swp
    Untracked:  output/GTExprofile_res.rds
    Untracked:  output/GTExprofile_resL1.rds
    Untracked:  output/GTExprofile_resL1_elbo.rds
    Untracked:  output/GTExprofile_resL3.rds
    Untracked:  output/GTExprofile_resL3_elbo.rds
    Untracked:  output/GTExprofile_res_elbo.rds
    Untracked:  output/GTExprofile_resapprox.rds
    Untracked:  output/GTExprofile_resapproxL1.rds
    Untracked:  output/GTExprofile_resapproxL1_elbo.rds
    Untracked:  output/GTExprofile_resapproxL3.rds
    Untracked:  output/GTExprofile_resapproxL3_elbo.rds
    Untracked:  output/GTExprofile_resapprox_elbo.rds
    Untracked:  output/GTExprofile_resapproxdiag.rds
    Untracked:  output/GTExprofile_resapproxdiagL1.rds
    Untracked:  output/GTExprofile_resapproxdiagL1_elbo.rds
    Untracked:  output/GTExprofile_resapproxdiagL3.rds
    Untracked:  output/GTExprofile_resapproxdiagL3_elbo.rds
    Untracked:  output/GTExprofile_resapproxdiag_elbo.rds
    Untracked:  output/GTExprofile_resdiag.rds
    Untracked:  output/mmbr_gtex_res.Rprof
    Untracked:  output/mmbr_gtex_res_approx.Rprof
    Untracked:  output/mmbr_gtex_res_approx_diag.Rprof
    Untracked:  output/mmbr_gtex_res_diag.Rprof
    Untracked:  output/mnm_missing_output.20200527.rds
    Untracked:  output/test
    Untracked:  output/tiny_data_211_cond2L2.gif
    Untracked:  output/tiny_data_211_cond2L2.pdf
    Untracked:  output/tiny_data_211_cond2L3.gif
    Untracked:  output/tiny_data_211_cond2L3.pdf
    Untracked:  output/tiny_data_211_cond2initL3.gif
    Untracked:  output/tiny_data_211_cond2initL3.pdf

Unstaged changes:
    Modified:   analysis/mmbr_missing_rss_problem1.Rmd

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 repository in which changes were made to the R Markdown (analysis/GTExprofileProblem.Rmd) and HTML (docs/GTExprofileProblem.html) files. If you've configured a remote Git repository (see ?wflow_git_remote), click on the hyperlinks in the table below to view the files as they were in that past version.

File Version Author Date Message
Rmd 034ffad zouyuxin 2020-11-10 wflow_publish("analysis/GTExprofileProblem.Rmd")
html bf1cf59 zouyuxin 2020-11-09 Build site.
Rmd 93280ec zouyuxin 2020-11-09 wflow_publish("analysis/GTExprofileProblem.Rmd")
html 176901a zouyuxin 2020-11-09 Build site.
Rmd b13c280 zouyuxin 2020-11-09 wflow_publish("analysis/GTExprofileProblem.Rmd")
html a029053 zouyuxin 2020-11-09 Build site.
Rmd e69e446 zouyuxin 2020-11-09 wflow_publish("analysis/GTExprofileProblem.Rmd")
html 85912de zouyuxin 2020-11-05 Build site.
Rmd 3f5d1aa zouyuxin 2020-11-05 wflow_publish("analysis/GTExprofileProblem.Rmd")
html a91be02 zouyuxin 2020-10-29 Build site.
Rmd 414facb zouyuxin 2020-10-29 wflow_publish("analysis/GTExprofileProblem.Rmd")
html 88f7737 zouyuxin 2020-10-29 Build site.
Rmd 6cd6fac zouyuxin 2020-10-29 wflow_publish("analysis/GTExprofileProblem.Rmd")

We investigate the BF problem observed here in more details. We fit model with L = 1 and a simpler prior. We don't estimate prior scalar.

knitr::read_chunk("code/mvsusie_missing.R")

R code for mvSuSiE with missing data in Y:

## this is a simplified implementation for mvSuSiE with missing data in Y
## prior_variance is a matrix
## prior_variance and residual_variance are fixed in the algorithm.

## If compute_objective = TRUE, the stopping criteria is based on elbo;
## otherwise, it is based on changes in pip.
library(abind)
library(susieR)
mvsusie_missing = function(X, Y, L=10, prior_variance, residual_variance, approximate=FALSE, intercept = TRUE,
                           max_iter = 100, prior_weights=NULL, tol=1e-3, min_abs_corr=0.5, prior_tol=1E-9,
                           compute_objective = FALSE){
  if (is.null(dim(Y))) Y <- matrix(Y,length(Y),1)
  R <- ncol(Y)
  N <- nrow(Y)
  J <- ncol(X)
  Y_missing <- is.na(Y)
  Y_non_missing <- !Y_missing
  # store missing pattern, TRUE for observe, FALSE for missing
  missing_pattern <- unique(Y_non_missing)
  Y_missing_pattern_assign <- numeric(N)
  for(k in 1:nrow(missing_pattern)){
    idx = which(apply(Y_non_missing, 1, function(x) identical(x, missing_pattern[k,])))
    Y_missing_pattern_assign[idx] <- k
  }
  Y[Y_missing] <- 0
  if(approximate){
    X_for_Y_missing <- array(X, dim = c(N, J, R))
    for(r in 1:R) {
      X_for_Y_missing[Y_missing[,r],,r] <- NA
    }
  }else{
    X_for_Y_missing <- outer(X,  diag(R)) # N by J by R by R
  }

  ## compute inverse of residual variance for each missing pattern
  residual_variance_inv <- list()
  residual_variance_eigen <- list()
  for(k in 1:nrow(missing_pattern)){
    if(R == 1){
      residual_variance_inv[[k]] <- missing_pattern[k,] / residual_variance
      if(sum(missing_pattern[k,])>0){
        residual_variance_eigen[[k]] <- residual_variance
      }else{
        residual_variance_eigen[[k]] <- numeric(0)
      }
    }else{
      residual_variance_inv[[k]] <- matrix(0, R, R)
      if(sum(missing_pattern[k,])>0){
        Vk = residual_variance[which(missing_pattern[k,]), which(missing_pattern[k,])]
        eigenVk <- eigen(Vk, symmetric = TRUE)
        dinv <- 1/(eigenVk$values)
        residual_variance_eigen[[k]] <- eigenVk$values
        residual_variance_inv[[k]][which(missing_pattern[k,]), which(missing_pattern[k,])] <- eigenVk$vectors %*% (dinv * t(eigenVk$vectors))
      }else{
        residual_variance_eigen[[k]] <- numeric(0)
      }
    }
  }

  ## centering
  if(intercept){
    if(approximate){
      cm_x <- colMeans(X_for_Y_missing, na.rm=T) # J by R
      Xbar = cm_x
      for(r in 1:R){
        X_for_Y_missing[,,r] <- t(t(X_for_Y_missing[,,r]) - cm_x[,r])
        X_for_Y_missing[,,r][is.na(X_for_Y_missing[,,r])] <- 0
      }
      if (R == 1) Y_mean <- mean(Y[Y_non_missing])
      else Y_mean <- sapply(1:R, function(r) mean(Y[Y_non_missing[,r],r]))
      Y <- t(t(Y) - Y_mean)
      Y[!Y_non_missing] <- 0
    }else{
      # sum_i V_i^{-1} R by R matrix
      Vinvsum = Reduce('+', lapply(1:nrow(missing_pattern), function(i)
        residual_variance_inv[[i]] * sum(Y_missing_pattern_assign == i)))
      Vinvsuminv <- invert_via_chol(Vinvsum)

      # sum_i V_i^{-1} y_i R by 1 matrix
      Ysum = Reduce('+', lapply(1:N, function(i)
        residual_variance_inv[[Y_missing_pattern_assign[i]]] %*% Y[i,] ))

      # center Y
      Y_mean <- as.numeric(Vinvsuminv %*% Ysum)
      Y <- t(t(Y) - Y_mean)
      Y[!Y_non_missing] <- 0

      # center X
      Xbar <- array(0, dim=c(J, R, R))
      for(j in 1:J){
        # For variant j, Vinvsuminv sum_i V_i^{-1} X_{i,j} R by R matrix
        Xbar[j,,] <- Vinvsuminv %*% Reduce('+', lapply(1:N, function(i) residual_variance_inv[[Y_missing_pattern_assign[i]]] * X[i,j]) )
        X_for_Y_missing[,j,,] <- sweep(X_for_Y_missing[,j,,,drop=F], 3:4, Xbar[j,,])
      }
    }
  }

  svs_inv <- list()
  for(j in 1:J){
    # For variant j, sum_i X_for_Y_missing[i,j,,]^T V_i^{-1} X_for_Y_missing[i,j,,], R by R matrix
    # when there is no missing, it is sum(x_j^2) * V^{-1}
    if(approximate){
      svs_inv[[j]] <- Reduce('+', lapply(1:N, function(i) t(residual_variance_inv[[Y_missing_pattern_assign[i]]] *
                                                                 X_for_Y_missing[i,j,]) * X_for_Y_missing[i,j,]))
    }else{
      svs_inv[[j]] <- Reduce('+', lapply(1:N, function(i) crossprod(X_for_Y_missing[i,j,,],
                                             residual_variance_inv[[Y_missing_pattern_assign[i]]] %*%
                                             X_for_Y_missing[i,j,,])))
    }
  }
  s = init(N, J, R, L, prior_variance, prior_weights)
  s$R = Y
  pip_history = list()
  if(compute_objective){
    elbo = c()
  }else{
    elbo = NA
  }
  for(i in 1:max_iter){
    s = update_each_effect(X, Xbar, X_for_Y_missing, Y, s, Y_missing_pattern_assign, residual_variance_inv, svs_inv, compute_objective)
    pip_history[[i]] = s$alpha
    if(compute_objective){
      elbo = c(elbo, get_elbo(s, Xbar, X, X_for_Y_missing, Y, Y_missing_pattern_assign, residual_variance_eigen, residual_variance_inv))
    }
    if(i > 1){
      if(compute_objective){
        if((elbo[i]-elbo[i-1])<tol) {
          s$niter = i
          break;
        }
      }else{
        delta = max(abs(apply(1 - pip_history[[i]], 2, prod) - apply(1 - pip_history[[i-1]], 2, prod)))
        if(delta < tol){
          s$niter = i
          s$delta = delta
          break
        }
      }
    }
  }
  s$elbo = elbo
  s$null_index = -9
  s$V = 1
  s$sets = susie_get_cs(s, X=X, min_abs_corr=min_abs_corr)
  s$pip = susie_get_pip(s, prior_tol=prior_tol)
  return(s)
}

update_each_effect = function(X, Xbar, X_for_Y_missing, Y, s, Y_missing_pattern_assign, residual_variance_inv, svs_inv, compute_objective) {
  # Repeat for each effect to update.
  L = nrow(s$alpha)
  if (L > 0)
    for (l in 1:L) {

      # # Remove lth effect from fitted values.
      # s$Xr = s$Xr - compute_Xb(Xbar, X, X_for_Y_missing, s$alpha[l,] * s$mu[l,,])
      #
      # # Compute residuals.
      # R = Y - s$Xr
      s$R = s$R + compute_Xb(Xbar, X, X_for_Y_missing, s$alpha[l,] * s$mu[l,,])

      res = SER(X, X_for_Y_missing,Xbar,s$R,Y_missing_pattern_assign,residual_variance_inv,svs_inv, s$prior, s$prior_weights)

      # Update the variational estimate of the posterior mean.
      s$alpha[l,]  = res$alpha
      s$mu[l,,]    = res$mu1
      s$mu2[l,,,]   = res$mu2
      s$lbf[l]     = res$lbf_model
      if(compute_objective){
        if (length(dim(res$mu2)) == 3) {
          pb2 = lapply(1:nrow(res$mu1), function(j) res$alpha[j] * res$mu2[j,,])
        } else {
          pb2 = lapply(1:nrow(res$mu1), function(j) res$alpha[j] * matrix(res$mu2[j,]))
        }
        Xb = compute_Xb(Xbar, X, X_for_Y_missing, s$alpha[l,] * s$mu[l,,])
        E1 = sum(sapply(1:nrow(Y), function(i) crossprod(s$R[i,], residual_variance_inv[[Y_missing_pattern_assign[i]]] %*% Xb[i,])))
        s$vbxxb[l] = sum(sapply(1:length(pb2), function(j) tr(svs_inv[[j]] %*% pb2[[j]])))
        s$kl[l] = E1 - (s$vbxxb[l] / 2) - res$lbf_model
      }
      # s$Xr = s$Xr + compute_Xb(Xbar, X, X_for_Y_missing, s$alpha[l,] * s$mu[l,,])
      s$R = s$R - compute_Xb(Xbar, X, X_for_Y_missing, s$alpha[l,] * s$mu[l,,])
    }
  return(s)
}

SER = function(X, X_for_Y_missing, Xbar, Y, Y_missing_pattern_assign, residual_variance_inv, svs_inv, prior, prior_weights = NULL){
  J = dim(X_for_Y_missing)[2]
  if (is.null(prior_weights))
    prior_weights = rep(1/J,J)
  XtY = compute_XtY(X, X_for_Y_missing,Y,Y_missing_pattern_assign, residual_variance_inv, Xbar)
  post = multivariate_regression(XtY, svs_inv, prior)
  lbf = post$lbf
  maxlbf = max(lbf)
  # w is proportional to BF, but subtract max for numerical stability.
  w = exp(lbf - maxlbf)
  # Posterior prob for each SNP.
  w_weighted = w * prior_weights
  weighted_sum_w = sum(w_weighted)
  alpha = w_weighted / weighted_sum_w
  lbf_model = maxlbf + log(weighted_sum_w)
  return(list(alpha = alpha,mu1 = post$b1 , mu2 = post$b2 , lbf = lbf,
              lbf_model = lbf_model))
}

multivariate_regression = function(XtY, svs_inv, U) {
  post_cov = lapply(1:length(svs_inv), function(j) U %*% solve(diag(nrow(U)) + svs_inv[[j]] %*% U))
  lbf = sapply(1:length(svs_inv), function(j) -0.5 * log(det(diag(nrow(U)) + svs_inv[[j]] %*% U)) + 0.5*t(XtY[j,])%*%(post_cov[[j]]%*%XtY[j,]))
  lbf[which(is.nan(lbf))] = 0
  post_b1 = t(do.call(cbind, lapply(1:length(svs_inv), function(j) post_cov[[j]] %*% XtY[j,]))) # J by R
  post_b2 = lapply(1:length(post_cov), function(j) tcrossprod(post_b1[j,]) + post_cov[[j]]) # length J list with R by R matrix
  # deal with degerated case with 1 condition
  if (ncol(post_b1) == 1) {
    post_b2 = matrix(unlist(post_b2), length(post_b2), 1)
  } else {
    post_b2 = aperm(abind(post_b2, along = 3), c(3,1,2)) # J by R by R
  }
  return(list(b1 = post_b1, b2 = post_b2, lbf = lbf, cov = post_cov))
}

get_elbo = function(s, Xbar, X, X_for_Y_missing, Y, Y_missing_pattern_assign, residual_variance_eigenvalues, residual_variance_inv){
  N = length(Y_missing_pattern_assign)
  Y_missing_assign =  table(Y_missing_pattern_assign)
  expected_loglik = -0.5 * log(2*pi) * sum(sapply(residual_variance_eigenvalues, length) * Y_missing_assign) -
    0.5 * sum(sapply(residual_variance_eigenvalues, function(x) ifelse(length(x)>0,sum(log(x)),0)) * Y_missing_assign)
  E1 = sapply(1:nrow(s$alpha), function(l){
    Xb = compute_Xb(Xbar, X, X_for_Y_missing,s$alpha[l,] * s$mu[l,,])
    sum(sapply(1:N, function(i) crossprod(Xb[i,], residual_variance_inv[[Y_missing_pattern_assign[i]]] %*% Xb[i, ])  ))
  })
  E1 = sum(sapply(1:N, function(i) crossprod(s$R[i,],residual_variance_inv[[Y_missing_pattern_assign[i]]] %*% s$R[i,]) )) - sum(E1)
  essr = E1 + sum(s$vbxxb)
  expected_loglik - 0.5 * essr - sum(s$kl)
}

## utils
invert_via_chol = function(x) {
  if (all(x==0)) return(x)
  return(chol2inv(muffled_chol(x)))
}

muffled_chol = function(x, ...){
  withCallingHandlers(chol(x, ...),
                      warning = function(w) {
                        if (grepl("the matrix is either rank-deficient or indefinite", w$message))
                          invokeRestart("muffleWarning")
                      })
}

compute_XtY = function(X, X_for_Y_missing,Y,Y_missing_pattern_assign,residual_variance_inv, Xbar){ # J by R
  N = dim(X_for_Y_missing)[1]
  J = dim(X_for_Y_missing)[2]
  VinvY <- t(sapply(1:N, function(i) residual_variance_inv[[Y_missing_pattern_assign[i]]] %*% Y[i,])) # N by R
  if(length(dim(X_for_Y_missing)) == 3){ ## approximate
    XtY <- t(sapply(1:J, function(j) colSums(X_for_Y_missing[,j,] * VinvY) ))
  }else{
    XtY <- t(sapply(1:J, function(j) colSums(X[,j] * VinvY) - crossprod(Xbar[j,,], colSums(VinvY)) ))
  }
  if (nrow(XtY) != J) XtY <- t(XtY)
  return(XtY)
}

init = function(N, J, R, L, U, prior_weights){
  if(is.null(prior_weights))
    prior_weights = rep(1/J,J)
  else
    prior_weights = prior_weights / sum(prior_weights)

  s = list(alpha  = matrix(1/J, L, J),
           mu     = array(0,dim = c(L, J, R)),
           mu2    = array(0,dim = c(L, J, R, R)),
           Xr     = matrix(0,N, R),
           prior      = U,
           prior_weights = prior_weights,
           kl = numeric(L),
           vbxxb = numeric(L),
           R = matrix(0,N, R))
  class(s) = 'susie'
  return(s)
}

compute_Xb = function(Xbar, X, X_for_Y_missing, b){
  if(is.vector(b)){
    b = matrix(b, length(b),1)
  }
  if(length(dim(X_for_Y_missing)) == 3){
    Xb = sapply(1:ncol(b), function(r) X_for_Y_missing[,,r] %*% b[,r])
  }else{
    Xbarb = Reduce('+', lapply(1:ncol(X), function(j) Xbar[j,,] %*% b[j,]))
    Xb = X %*% b - matrix(Xbarb, nrow(X), ncol(b), byrow = TRUE)
  }
  return(Xb)
}

tr = function (m) {
  if (!is.matrix(m) | (dim(m)[1] != dim(m)[2]))
    stop("Input to tr() function must be a square matrix")
  return(sum(diag(m), na.rm = TRUE))
}

Load data

dat = readRDS('data/ENSG00000140265.12.Multi_Tissues.problem.rds')

Model with dense residual varaince

m = mvsusie_missing(dat$X, dat$Y, prior_variance = dat$prior$XX, residual_variance = dat$residual_var, L = 1, approximate=FALSE, compute_objective = T)
susie_plot(m, y='PIP', main=paste0('ELBO=', round(m$elbo[m$niter],2)))

Version Author Date
a029053 zouyuxin 2020-11-09
88f7737 zouyuxin 2020-10-29

Check CS details:

m$sets
$cs
$cs$L1
 [1] 121 131 132 134 137 143 144 148 166 185 192 198 204 214 215 222 230 239 242
[20] 248 279 283 284 289 293 302 306 307 318 319 320 323 331 335 338 347 360 366
[39] 367 369 380 384 385 393 397 399 407 418 419 423 430 431 433 435 446 448 458
[58] 477 478 487


$purity
   min.abs.corr mean.abs.corr median.abs.corr
L1    0.8939012     0.9743227       0.9791716

$cs_index
[1] 1

$coverage
[1] 0.95

Model with diagonal residual variance

m_diag = mvsusie_missing(dat$X, dat$Y, prior_variance = dat$prior$XX, residual_variance = diag(diag(dat$residual_var)), L = 1, approximate=TRUE, compute_objective = T)
susie_plot(m_diag, y='PIP', main=paste0('ELBO=', round(m_diag$elbo[m_diag$niter],2)))

Version Author Date
a029053 zouyuxin 2020-11-09
85912de zouyuxin 2020-11-05
88f7737 zouyuxin 2020-10-29

Check CS details:

m_diag$sets
$cs
$cs$L1
[1] 253 260 263 264 265 268


$purity
   min.abs.corr mean.abs.corr median.abs.corr
L1    0.9495083     0.9859745               1

$cs_index
[1] 1

$coverage
[1] 0.95

There is no overlep between CSs from these 2 models.

Sanity check using Identity matrix as prior variance

Model with dense residual varaince

mi = mvsusie_missing(dat$X, dat$Y, prior_variance = diag(49), residual_variance = dat$residual_var, L = 1, approximate=FALSE, compute_objective = T)
susie_plot(mi, y='PIP', main=paste0('ELBO=', round(mi$elbo[mi$niter],2)))

Version Author Date
a029053 zouyuxin 2020-11-09
85912de zouyuxin 2020-11-05
88f7737 zouyuxin 2020-10-29

Model with diagonal residual variance

mi_diag = mvsusie_missing(dat$X, dat$Y, prior_variance = diag(49), residual_variance = diag(diag(dat$residual_var)), L = 1, approximate=TRUE, compute_objective = T)
susie_plot(mi_diag, y='PIP', main=paste0('ELBO=', round(mi_diag$elbo[mi_diag$niter],2)))

Version Author Date
a029053 zouyuxin 2020-11-09
85912de zouyuxin 2020-11-05
88f7737 zouyuxin 2020-10-29

As a sanity check for the implemented method, we fit model for each tissue separately. The product of fitted BFs over all tissues should equal to the BFs from model with diagonal residual variance and Identity prior matrix.

malpha_r = matrix(NA, 49, 501)
for(r in 1:49){
  id = which(!is.na(dat$Y[,r]))
  mr = susie(dat$X[id,], dat$Y[id,r], scaled_prior_variance = 1/var(dat$Y[,r], na.rm=T) , residual_variance = diag(dat$residual_var)[r], L=1,
        intercept = T, standardize = F, estimate_residual_variance = F, estimate_prior_variance = F)
  malpha_r[r, ] = mr$alpha
}
{plot(apply(malpha_r, 2, prod)/sum(apply(malpha_r, 2, prod)), mi_diag$alpha, xlab='product of BF', ylab='BF from mvsusie')
abline(0,1)}

Version Author Date
a029053 zouyuxin 2020-11-09
85912de zouyuxin 2020-11-05
88f7737 zouyuxin 2020-10-29

Impute missing Y

To check if the diagonal residual variance has different result in full data case, we column center Y based on observed entries, then fill in the missing data with 0s.

Ymean = colMeans(dat$Y, na.rm=T)
Y = t(t(dat$Y) - Ymean)
Y[is.na(Y)] = 0

m1 = mmbr::msusie(dat$X, Y, prior_variance = dat$prior$XX, residual_variance = dat$residual_var, L = 1, compute_objective = T, estimate_prior_variance = FALSE)
susie_plot(m1, y='PIP', main=paste0('V, ELBO=', round(m1$elbo[m1$niter],2)))

Version Author Date
a029053 zouyuxin 2020-11-09
85912de zouyuxin 2020-11-05
m2 = mmbr::msusie(dat$X, Y, prior_variance = dat$prior$XX, residual_variance = diag(diag(dat$residual_var)), L = 1, approximate=FALSE, compute_objective = T, estimate_prior_variance = FALSE)
susie_plot(m2, y='PIP', main=paste0('diag(V), ELBO=', round(m2$elbo[m2$niter],2)))

Version Author Date
a029053 zouyuxin 2020-11-09

sessionInfo()
R version 3.6.3 (2020-02-29)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Catalina 10.15.7

Matrix products: default
BLAS:   /Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libRblas.0.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.6/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] susieR_0.9.26   abind_1.4-5     workflowr_1.6.2

loaded via a namespace (and not attached):
 [1] progress_1.2.2     tidyselect_1.1.0   xfun_0.19          purrr_0.3.4       
 [5] ashr_2.2-51        lattice_0.20-41    colorspace_1.4-1   vctrs_0.3.4       
 [9] generics_0.1.0     htmltools_0.5.0    yaml_2.2.1         rlang_0.4.8       
[13] mixsqp_0.3-46      later_1.1.0.1      pillar_1.4.6       glue_1.4.2        
[17] mashr_0.2.40       matrixStats_0.57.0 lifecycle_0.2.0    plyr_1.8.6        
[21] stringr_1.4.0      munsell_0.5.0      gtable_0.3.0       mvtnorm_1.1-1     
[25] evaluate_0.14      knitr_1.30         httpuv_1.5.4       invgamma_1.1      
[29] irlba_2.3.3        Rcpp_1.0.5         promises_1.1.1     scales_1.1.1      
[33] backports_1.2.0    rmeta_3.0          truncnorm_1.0-8    fs_1.5.0          
[37] ggplot2_3.3.2      hms_0.5.3          digest_0.6.27      stringi_1.5.3     
[41] dplyr_1.0.2        mmbr_0.0.1.0305    grid_3.6.3         rprojroot_1.3-2   
[45] tools_3.6.3        magrittr_1.5       tibble_3.0.4       crayon_1.3.4      
[49] whisker_0.4        pkgconfig_2.0.3    ellipsis_0.3.1     Matrix_1.2-18     
[53] prettyunits_1.1.1  SQUAREM_2020.5     assertthat_0.2.1   rmarkdown_2.5     
[57] reshape_0.8.8      rstudioapi_0.11    R6_2.5.0           git2r_0.27.1      
[61] compiler_3.6.3