Built using Zelig version r packageVersion("Zelig")

knitr::opts_knit$set(
    stop_on_error = 2L
)
knitr::opts_chunk$set(
    fig.height = 11,
    fig.width = 7
)

options(cite = FALSE)

Bayesian Factor Analysis with factor.bayes.

Given some unobserved explanatory variables and observed dependent variables, the Normal theory factor analysis model estimates the latent factors. The model is implemented using a Markov Chain Monte Carlo algorithm (Gibbs sampling with data augmentation).

Syntax

z.out <- zelig(cbind(Y1 ,Y2, Y3) ~ NULL, factors = 2,
               model = "factor.bayes", weights = w, data = mydata)

Inputs

zelig() takes the following functions for factor.bayes:

Additional Inputs

In addition, zelig() accepts the following additional arguments for model specification:

In addition, zelig() accepts the following additional inputs for bayes.factor:

The model also accepts the following additional arguments to specify prior parameters:

Zelig users may wish to refer to help(MCMCfactanal) for more information.

Example

rm(list=ls(pattern="\\.out"))
suppressWarnings(suppressMessages(library(Zelig)))
set.seed(1234)

Attaching the sample dataset:

data(swiss)
names(swiss) <- c("Fert", "Agr", "Exam", "Educ", "Cath", "InfMort")

Factor analysis:

z.out <- zelig(~ Agr + Exam + Educ + Cath + InfMort,
               model = "factor.bayes", data = swiss,
               factors = 2, verbose = FALSE,
               a0 = 1, b0 = 0.15, burnin = 500, mcmc = 5000)

Checking for convergence before summarizing the estimates. See the section Diagnostics for Zelig Models for examples of the output with interpretation:

z.out$geweke.diag()

Since the algorithm did not converge, we now add some constraints on $\Lambda$ to optimize the algorithm:

z.out <- zelig(~ Agr + Exam + Educ + Cath + InfMort,
               model = "factor.bayes", data = swiss, factors = 2,
               lambda.constraints =
                   list(Exam = list(1,"+"),
                        Exam = list(2,"-"),
                        Educ = c(2, 0),
                        InfMort = c(1, 0)),
               verbose = FALSE, a0 = 1, b0 = 0.15,
               burnin = 500, mcmc = 5000)
z.out$geweke.diag()
z.out$heidel.diag()
z.out$raftery.diag()
summary(z.out)

Model

Suppose for observation $i$ we observe $K$ variables and hypothesize that there are $d$ underlying factors such that:

$$ \begin{aligned} Y_i = \Lambda \phi_i+\epsilon_i\end{aligned} $$

where $Y_{i}$ is the vector of $K$ manifest variables for observation $i$. $\Lambda$ is the $K \times d$ factor loading matrix and $\phi_i$ is the $d$-vector of latent factor scores. Both $\Lambda$ and $\phi$ need to be estimated.

$$ \begin{aligned} \epsilon_{i} \sim \textrm{Normal}(0, \Psi).\end{aligned} $$

where $\Psi$ is a diagonal, positive definite matrix. The diagonal elements of $\Psi$ are referred to as uniquenesses.

$$ \begin{aligned} \mu_i = E(Y_i) = \Lambda\phi_i\end{aligned} $$

$$ \begin{aligned} \Lambda_{ij} \sim \textrm{Normal}(l_{0_{ij}}, L_{0_{ij}}^{-1}) \textrm{ for } i=1,\ldots, k; \quad j=1,\ldots, d. \end{aligned} $$ - The independent conjugate prior for each $\Psi_{ii}$ is given by

$$ \begin{aligned} \Psi_{ii} \sim \textrm{InverseGamma}(\frac{a_0}{2}, \frac{b_0}{2}), \textrm{ for } i = 1, \ldots, k.\end{aligned} $$ - The prior for $\phi_i$ is

$$ \begin{aligned} \phi_i &\sim& \textrm{Normal}(0, I_d), \textrm{ for } i = 1, \ldots, n.\end{aligned} $$

where $I_d$ is a $d\times d$ identity matrix.

Output Values

The output of each zelig() call contains useful information which you may view. For example, if you run:

z.out <- zelig(cbind(Y1, Y2, Y3), model = "factor.bayes", data)

then you may examine the available information in z.out by using names(z.out), see the draws from the posterior distribution of the coefficients by using z.out$coefficients, and view a default summary of information through summary(z.out). Other elements available through the $ operator are listed below.

See also

Bayesian factor analysis is part of the MCMCpack package by Andrew D. Martin and Kevin M. Quinn. The convergence diagnostics are part of the CODA package by Martyn Plummer, Nicky Best, Kate Cowles, and Karen Vines.

z.out$references()


IQSS/Zelig documentation built on Dec. 11, 2023, 1:51 a.m.