spca.cavi.Laplace {VBsparsePCA} | R Documentation |
Function for the PX-CAVI algorithm using the Laplace slab
Description
This function employs the PX-CAVI algorithm proposed in Ning (2020).
The g
in the slab density of the spike and slab prior is chosen to be the Laplace density, i.e.,
N(0, \sigma^2/\lambda_1 I_r)
.
Details of the model and the prior can be found in the Details section in the description of the 'VBsparsePCA()' function.
This function is not capable of handling the case when r > 1. In that case, we recommend to use the multivariate distribution instead.
Usage
spca.cavi.Laplace(
x,
r = 1,
lambda = 1,
max.iter = 100,
eps = 0.001,
sig2.true = NA,
threshold = 0.5,
theta.int = NA,
theta.var.int = NA,
kappa.para1 = NA,
kappa.para2 = NA,
sigma.a = NA,
sigma.b = NA
)
Arguments
x |
Data an |
r |
Rank. |
lambda |
Tuning parameter for the density |
max.iter |
The maximum number of iterations for running the algorithm. |
eps |
The convergence threshold; the default is |
sig2.true |
The default is false, |
threshold |
The threshold to determine whether |
theta.int |
The initial value of theta mean; if not provided, the algorithm will estimate it using PCA. |
theta.var.int |
The initial value of theta.var; if not provided, the algorithm will set it to be 1e-3*diag(r). |
kappa.para1 |
The value of |
kappa.para2 |
The value of |
sigma.a |
The value of |
sigma.b |
The value of |
Value
iter |
The number of iterations to reach convergence. |
selection |
A vector (if |
theta.mean |
The loadings matrix. |
theta.var |
The covariance of each non-zero rows in the loadings matrix. |
sig2 |
Variance of the noise. |
obj.fn |
A vector contains the value of the objective function of each iteration. It can be used to check whether the algorithm converges |
Examples
#In this example, the first 20 rows in the loadings matrix are nonzero, the rank is 1
set.seed(2021)
library(MASS)
library(pracma)
n <- 200
p <- 1000
s <- 20
r <- 1
sig2 <- 0.1
# generate eigenvectors
U.s <- randortho(s, type = c("orthonormal"))
U <- rep(0, p)
U[1:s] <- as.vector(U.s[, 1:r])
s.star <- rep(0, p)
s.star[1:s] <- 1
eigenvalue <- seq(20, 10, length.out = r)
# generate Sigma
theta.true <- U * sqrt(eigenvalue)
Sigma <- tcrossprod(theta.true) + sig2*diag(p)
# generate n*p dataset
X <- t(mvrnorm(n, mu = rep(0, p), Sigma = Sigma))
result <- spca.cavi.Laplace(x = X, r = 1)
loadings <- result$theta.mean