linearDL: Sample Bayesian linear infinite factor models with the...

Description Usage Arguments Value Author(s) References See Also Examples

View source: R/linearDL.R

Description

Perform Bayesian factor analysis by sampling the posterior distribution of parameters in a factor model with the Dirichlet-Laplace shrinkage prior of Bhattacharya et al.

Usage

1
2
3
4
5
6
linearDL(X, nrun, burn, thin = 1, prop = 1, 
epsilon = 1e-3, k = NULL,
output = c("covMean", "covSamples", "factSamples",
"sigSamples"), verbose = TRUE, dump = FALSE,
filename = "samps.Rds", buffer = 10000,
augment = NULL)

Arguments

X

Data matrix (n x p)

nrun

number of iterations

burn

burn-in period

thin

thinning interval

prop

proportion of elements in each column less than epsilon in magnitude cutoff

epsilon

tolerance

k

Number of factors

output

output type, a vector including some of: c("covMean", "covSamples", "factSamples", "sigSamples")

verbose

logical. Show progress bar?

dump

logical. Save output object during sampling?

filename

if dump, filename for output

buffer

if dump, frequency of saving

augment

additional sampling steps as an expression

Value

some of:

covMean

X covariance posterior mean

omegaSamps

X covariance posterior samples

lambdaSamps

Posterior factor loadings samples (rotationally ambiguous)

etaSamps

Posterior factor samples (rotationally ambiguous)

sigmaSamps

Posterior marginal variance samples (see notation in Bhattacharya and Dunson (2011))

numFacts

Number of factors for each iteration

Author(s)

Evan Poworoznek

References

Bhattacharya, Anirban, et al. "Dirichlet-Laplace priors for optimal shrinkage." Journal of the American Statistical Association 110.512 (2015): 1479-1490.

See Also

linearDL

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
k0 = 5
p = 20
n = 50

lambda = matrix(rnorm(p*k0, 0, 0.01), ncol = k0)
lambda[sample.int(p, 40, replace = TRUE) +
         p*(sample.int(k0, 40, replace = TRUE)-1)] = rnorm(40, 0, 1)
lambda[1:7, 1] = rnorm(7, 2, 0.5)
lambda[8:14, 2] = rnorm(7, -2, 0.5)
lambda[15:20, 3] = rnorm(6, 2, 0.5)
lambda[,4] = rnorm(p, 0, 0.5)
lambda[,5] = rnorm(p, 0, 0.5)
plotmat(varimax(lambda)[[1]])

X = matrix(rnorm(n*k0),n,k0)%*%t(lambda) + matrix(rnorm(n*p), n, p)

out = linearMGSP(X = X, nrun = 1000, burn = 500)

infinitefactor documentation built on April 3, 2020, 5:09 p.m.