Multivariate Bayesian variable selection regression

Abstract

I test three different ways to calculate an inverse to see performance gains.

Code

Show that the three inversion formulas I have are the same

In [1]:
## Moore Penrose --------------------------------------------------------------
set.seed(1824)
M <- 11
L <- 5

diag_lambda <- rchisq(M, df = 1)
Lambda <- diag(diag_lambda)
U <- matrix(rnorm(M * L), nrow = M)
V <- U %*% t(U)

LHS <- solve(diag(M) + V %*% Lambda) %*% V

ULU <- t(U) %*% Lambda %*% U
middle <- V - U %*% solve(diag(L) + ULU ) %*% ULU %*% t(U)

RHS <- V - U %*% solve(solve(t(U) %*% Lambda %*% U) + diag(L)) %*% t(U)

plot(LHS, RHS)
plot(middle, LHS)
plot(middle, RHS)

Now test for large M

In [2]:
rm(list = ls())
M <- 2000
L <- 11

diag_lambda <- rchisq(M, df = 1)
Lambda <- diag(diag_lambda)
U <- matrix(rnorm(M * L), nrow = M)
V <- U %*% t(U)

Sys.sleep(1)
lstart <- proc.time()
LHS <- solve(diag(M) + V %*% Lambda) %*% V
ltot <- proc.time() - lstart

mstart <- proc.time()
ULU <- t(U) %*% Lambda %*% U
middle <- V - U %*% solve(diag(L) + ULU ) %*% ULU %*% t(U)
mtot <- proc.time() - mstart

rstart <- proc.time()
RHS <- V - U %*% solve(solve(t(U) %*% Lambda %*% U) + diag(L)) %*% t(U)
rtot <- proc.time() - rstart

ltot
mtot
rtot
   user  system elapsed 
  6.650   0.157   6.806 
   user  system elapsed 
  0.076   0.008   0.084 
   user  system elapsed 
  0.131   0.020   0.151 

Copyright © 2016-2020 Gao Wang et al at Stephens Lab, University of Chicago