MCMCfactanal            package:MCMCpack            R Documentation

_M_a_r_k_o_v _c_h_a_i_n _M_o_n_t_e _C_a_r_l_o _f_o_r _N_o_r_m_a_l _T_h_e_o_r_y _F_a_c_t_o_r _A_n_a_l_y_s_i_s _M_o_d_e_l

_D_e_s_c_r_i_p_t_i_o_n:

     This function generates a posterior density sample from 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 density is returned as an mcmc object, which can be
     subsequently analyzed with functions provided in the coda package.

_U_s_a_g_e:

     MCMCfactanal(x, factors, lambda.constraints=list(),
                  data=list(), burnin = 1000, mcmc = 10000,
                  thin=5, verbose = FALSE, seed = 0,
                  lambda.start = NA, psi.start = NA,
                  l0=0, L0=0, a0=0.001, b0=0.001,
                  store.scores = FALSE, std.var=TRUE, ... )
      

_A_r_g_u_m_e_n_t_s:

       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: 'varname=list(d,c)'
          which will constrain the dth loading for the variable named
          varname to be equal to c, 'varname=list(d,"+")' which will
          constrain the dth loading for the variable named varname to
          be positive, and 'varname=list(d, "-")' which will constrain
          the dth loading for the variable named varname to be
          negative. If x is a matrix without column names defaults
          names of ``V1",``V2", ... , etc will be used.

    data: A data frame.

  burnin: The number of burn-in 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 TRUE, the iteration
          number and the factor loadings and uniquenesses are printed
          to the screen.

    seed: The seed for the random number generator.  The code uses the
          Mersenne Twister, which requires an integer as an input.  If
          nothing is provided, the Scythe default seed is used.

lambda.start: Starting values for the factor loading matrix Lambda. If
          'lambda.start' is set to a scalar the starting value for all
          unconstrained loadings will be set to that scalar. If
          'lambda.start' is a matrix of the same dimensions as Lambda
          then the 'lambda.start' matrix is used as the starting values
          (except for equality-constrained elements). If 'lambda.start'
          is set to 'NA' (the default) then starting values for
          unconstrained elements are set to 0, and starting values for
          inequality constrained elements are set to either 0.5 or -0.5
          depending on the nature of the constraints.

psi.start: Starting values for the uniquenesses. If 'psi.start' is set
          to a scalar then the starting value for all diagonal elements
          of 'Psi' are set to this value. If 'psi.start' is a k-vector
          (where k is the number of manifest variables) then the
          staring value of 'Psi' has 'psi.start' on the main diagonal.
          If 'psi.start' is set to 'NA' (the default) the starting
          values of all the uniquenesses are set to 0.5.

      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 'Lambda'.

      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 'Lambda'.

      a0: Controls the shape of the inverse Gamma prior on the
          uniqueness. The actual shape parameter is set to 'a0/2'. Can
          be either a scalar or a k-vector.

      b0: Controls the scale of the inverse Gamma prior on the
          uniquenesses. The actual scale parameter is set to 'b0/2'.
          Can be either a scalar or a k-vector.

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 'TRUE' (the default) the manifest variables are rescaled
          to have zero mean and unit variance. Otherwise, the manifest
          variables are rescaled to have zero mean but retain their
          observed variances.

     ...: further arguments to be passed

_D_e_t_a_i_l_s:

     The model takes the following form:


                    x_i = Lambda phi_i + epsilon_i


                        epsilon_i ~ N(0, Psi)


     where x_i is the k-vector of observed variables specific to
     observation i, Lambda is the k by 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 ~ N(l0_ij,  L0_ij^-1), i=1,...,k, j=1,...,d



                      phi_i ~ N(0, I), i=1,...,n



                Psi_ii ~ IG(a0_i/2, b0_i/2), i=1,...,k


     'MCMCfactanal' simulates from the posterior density 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 density sample.

_V_a_l_u_e:

     An mcmc object that contains the posterior density sample.  This 
     object can be summarized by functions provided by the coda
     package.

_R_e_f_e_r_e_n_c_e_s:

     Andrew D. Martin, Kevin M. Quinn, and Daniel Pemstein.  2003.  
     _Scythe Statistical Library 0.4._ <URL: http://scythe.wustl.edu>.

     Martyn Plummer, Nicky Best, Kate Cowles, and Karen Vines. 2002.
     _Output Analysis and Diagnostics for MCMC (CODA)_. <URL:
     http://www-fis.iarc.fr/coda/>.

_S_e_e _A_l_s_o:

     'plot.mcmc','summary.mcmc','factanal'

_E_x_a_m_p_l_e_s:

        ## 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=FALSE, 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
        Lambda <- matrix(runif(45,-.5,.5), 15, 3)
        Psi <- diag(1 - apply(Lambda ^2, 1, sum))
        Sigma <- Lambda %*% t(Lambda) + Psi 
        Y <- t(t(chol(Sigma)) %*% matrix(rnorm(500*15), 15, 500))

        posterior <- MCMCfactanal(Y, factors=3,
                         lambda.constraints=list(V1=c(2,0),
                            V1=c(3,0), V2=c(3,0), V3=list(1,"+"),
                            V3=list(2,"+"), V3=list(3,"+")),
                         verbose=FALSE)
        plot(posterior)
        summary(posterior)        
        ## End(Not run)

