MCMCfactanal  R Documentation 
This function generates a sample from the posterior distribution of a normal theory factor analysis model. Normal priors are assumed on the factor loadings and factor scores while inverse Gamma priors are assumed for the uniquenesses. The user supplies data and parameters for the prior distributions, and a sample from the posterior distribution is returned as an mcmc object, which can be subsequently analyzed with functions provided in the coda package.
MCMCfactanal(
x,
factors,
lambda.constraints = list(),
data = NULL,
burnin = 1000,
mcmc = 20000,
thin = 1,
verbose = 0,
seed = NA,
lambda.start = NA,
psi.start = NA,
l0 = 0,
L0 = 0,
a0 = 0.001,
b0 = 0.001,
store.scores = FALSE,
std.var = TRUE,
...
)
x 
Either a formula or a numeric matrix containing the manifest variables. 
factors 
The number of factors to be fitted. 
lambda.constraints 
List of lists specifying possible simple
equality or inequality constraints on the factor loadings. A
typical entry in the list has one of three forms:

data 
A data frame. 
burnin 
The number of burnin iterations for the sampler. 
mcmc 
The number of iterations for the sampler. 
thin 
The thinning interval used in the simulation. The number of iterations must be divisible by this value. 
verbose 
A switch which determines whether or not the
progress of the sampler is printed to the screen. If

seed 
The seed for the random number generator. If NA, the
Mersenne Twister generator is used with default seed 12345; if an
integer is passed it is used to seed the Mersenne twister. The
user can also pass a list of length two to use the L'Ecuyer
random number generator, which is suitable for parallel
computation. The first element of the list is the L'Ecuyer seed,
which is a vector of length six or NA (if NA a default seed of

lambda.start 
Starting values for the factor loading matrix
Lambda. If 
psi.start 
Starting values for the uniquenesses. If

l0 
The means of the independent Normal prior on the factor loadings.
Can be either a scalar or a matrix with the same dimensions as

L0 
The precisions (inverse variances) of the independent Normal prior
on the factor loadings. Can be either a scalar or a matrix with the same
dimensions as 
a0 
Controls the shape of the inverse Gamma prior on the uniqueness.
The actual shape parameter is set to 
b0 
Controls the scale of the inverse Gamma prior on the uniquenesses.
The actual scale parameter is set to 
store.scores 
A switch that determines whether or not to store the factor scores for posterior analysis. NOTE: This takes an enormous amount of memory, so should only be used if the chain is thinned heavily, or for applications with a small number of observations. By default, the factor scores are not stored. 
std.var 
If 
... 
further arguments to be passed 
The model takes the following form:
x_i = \Lambda \phi_i + \epsilon_i
\epsilon_i \sim \mathcal{N}(0,\Psi)
where x_i
is the k
vector of observed variables
specific to observation i
, \Lambda
is the k \times
d
matrix of factor loadings, \phi_i
is the d
vector of
latent factor scores, and \Psi
is a diagonal, positive
definite matrix. Traditional factor analysis texts refer to the
diagonal elements of \Psi
as uniquenesses.
The implementation used here assumes independent conjugate priors
for each element of \Lambda
each \phi_i
, and each
diagonal element of \Psi
. More specifically we assume:
\Lambda_{ij} \sim \mathcal{N}(l_{0_{ij}}, L_{0_{ij}}^{1}),
i=1,\ldots,k, j=1,\ldots,d
\phi_i \sim \mathcal{N}(0, I), i=1,\dots,n
\Psi_{ii} \sim \mathcal{IG}(a_{0_i}/2, b_{0_i}/2),
i=1,\ldots,k
MCMCfactanal
simulates from the posterior distribution using
standard Gibbs sampling. The simulation proper is done in compiled
C++ code to maximize efficiency. Please consult the coda
documentation for a comprehensive list of functions that can be
used to analyze the posterior sample.
As is the case with all measurement models, make sure that you have plenty of free memory, especially when storing the scores.
An mcmc object that contains the sample from the posterior distribution. This object can be summarized by functions provided by the coda package.
Andrew D. Martin, Kevin M. Quinn, and Jong Hee Park. 2011. “MCMCpack: Markov Chain Monte Carlo in R.”, Journal of Statistical Software. 42(9): 121. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.18637/jss.v042.i09")}.
Daniel Pemstein, Kevin M. Quinn, and Andrew D. Martin. 2007. Scythe Statistical Library 1.0. http://scythe.lsa.umich.edu.
Martyn Plummer, Nicky Best, Kate Cowles, and Karen Vines. 2006. “Output Analysis and Diagnostics for MCMC (CODA)”, R News. 6(1): 711. https://CRAN.Rproject.org/doc/Rnews/Rnews_20061.pdf.
plot.mcmc
,summary.mcmc
,factanal
## Not run:
### An example using the formula interface
data(swiss)
posterior < MCMCfactanal(~Agriculture+Examination+Education+Catholic
+Infant.Mortality, factors=2,
lambda.constraints=list(Examination=list(1,"+"),
Examination=list(2,""), Education=c(2,0),
Infant.Mortality=c(1,0)),
verbose=0, store.scores=FALSE, a0=1, b0=0.15,
data=swiss, burnin=5000, mcmc=50000, thin=20)
plot(posterior)
summary(posterior)
### An example using the matrix interface
Y < cbind(swiss$Agriculture, swiss$Examination,
swiss$Education, swiss$Catholic,
swiss$Infant.Mortality)
colnames(Y) < c("Agriculture", "Examination", "Education", "Catholic",
"Infant.Mortality")
post < MCMCfactanal(Y, factors=2,
lambda.constraints=list(Examination=list(1,"+"),
Examination=list(2,""), Education=c(2,0),
Infant.Mortality=c(1,0)),
verbose=0, store.scores=FALSE, a0=1, b0=0.15,
burnin=5000, mcmc=50000, thin=20)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.