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

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

View source: R/linearMGSP.R

Description

Perform Bayesian factor analysis by sampling the posterior distribution of parameters in a factor model with the Multiplicative Gamma Shrinkage Prior of Bhattacharya and Dunson

Usage

1
2
3
4
5
6
linearMGSP(X, nrun, burn, thin = 1, prop = 1, 
epsilon = 1e-3, kinit = NULL, adapt = TRUE, 
output = c("covMean", "covSamples", "factSamples",
"sigSamples", "numFactors"), 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

kinit

initial value for the number of factors

adapt

logical. Whether or not to adapt number of factors across sampling

output

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

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, and David B. Dunson. "Sparse Bayesian infinite factor models." Biometrika (2011): 291-306.

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)

poworoznek/infinitefactor documentation built on April 7, 2020, 1:10 p.m.