| Title: | Bayesian Exploratory Factor Analysis |
|---|---|
| Description: | Exploratory Bayesian factor analysis of continuous, mixed-type, and bounded continuous variables using the mode-jumping algorithm of Man and Culpepper (2020) <doi:10.1080/01621459.2020.1773833>. |
| Authors: | Albert Man [aut], Steven Andrew Culpepper [aut, cre] (ORCID: <https://orcid.org/0000-0003-4226-6176>) |
| Maintainer: | Steven Andrew Culpepper <[email protected]> |
| License: | GPL-3 |
| Version: | 0.0.0.6 |
| Built: | 2026-06-12 14:51:25 UTC |
| Source: | https://github.com/cran/bayesefa |
Exploratory Bayesian factor analysis of continuous, mixed-type, and bounded continuous variables using the mode-jumping algorithm of Man and Culpepper (2020) doi:10.1080/01621459.2020.1773833.
Maintainer: Steven Andrew Culpepper [email protected] (ORCID)
Authors:
Steven Andrew Culpepper [email protected] (ORCID)
Albert Man [email protected]
Man, A. & Culpepper, S. A. (2020). A mode-jumping algorithm for Bayesian factor analysis. Journal of the American Statistical Association, doi:10.1080/01621459.2020.1773833.
Implement the Man and Culpepper (2020) mode-jumping algorithm to factor analyze continuous response data.
EFA_Mode_Jumper(Y, M, gamma, burnin, chain_length = 10000L)EFA_Mode_Jumper(Y, M, gamma, burnin, chain_length = 10000L)
Y |
A N by J matrix of mean-centered, continuous variables. |
M |
An integer specifying the number of factors. |
gamma |
The value of the mode-jumping tuning parameter. Man and Culpepper (2020) used gamma = 0.5. |
burnin |
Number of burn-in iterations to discard. |
chain_length |
The total number of iterations (burn-in + post-burn-in). |
A list that contains nsamples = chain_length - burnin array draws from the posterior distribution:
LAMBDA: A J by M by nsamples array of sampled loading matrices.
PSIs: A J by nsamples matrix of vector of variable uniquenesses.
ROW_OUT: A matrix of sampled row indices of founding variables for mode-jumping algorithm.
F_OUT: An array of sampled factor scores.
ACCEPTED: Acceptance rates for mode-jumping Metropolis-Hastings (MH) steps.
Steven Andrew Culpepper, Albert Man
Man, A. & Culpepper, S. A. (2020). A mode-jumping algorithm for Bayesian factor analysis. Journal of the American Statistical Association, doi:10.1080/01621459.2020.1773833.
data(exchangerate) #Retain complete cases and drop Month_Year column X<-exchangerate[complete.cases(exchangerate),-1] X<-apply(X,2, diff) X<-as.matrix(scale(X)) #Specify the number of factors my_M<-2 #Run the mode-jumping EFA algorithm burn_in<-150 chain_length<-300 out <- EFA_Mode_Jumper(X,my_M,gamma=0.5,burnin=burn_in,chain_length) #Rotate all samples to permutation positive lower triangular (PPLT) #structure with USD and FRF as factor founding variables my_lambda_sample = out$LAMBDA for (j in 1:dim(my_lambda_sample)[3]) { my_rotate = proposal2(c(1,4),my_lambda_sample[,,j],out$F_OUT[,,j]) my_lambda_sample[,,j] = my_rotate$lambda } #compute posterior mean of PPLT loadings mLambda<-apply(my_lambda_sample,c(1,2),mean)data(exchangerate) #Retain complete cases and drop Month_Year column X<-exchangerate[complete.cases(exchangerate),-1] X<-apply(X,2, diff) X<-as.matrix(scale(X)) #Specify the number of factors my_M<-2 #Run the mode-jumping EFA algorithm burn_in<-150 chain_length<-300 out <- EFA_Mode_Jumper(X,my_M,gamma=0.5,burnin=burn_in,chain_length) #Rotate all samples to permutation positive lower triangular (PPLT) #structure with USD and FRF as factor founding variables my_lambda_sample = out$LAMBDA for (j in 1:dim(my_lambda_sample)[3]) { my_rotate = proposal2(c(1,4),my_lambda_sample[,,j],out$F_OUT[,,j]) my_lambda_sample[,,j] = my_rotate$lambda } #compute posterior mean of PPLT loadings mLambda<-apply(my_lambda_sample,c(1,2),mean)
This dataset was considered by West and Harrison (1997) and Lopes and West (2004). The dataset consists of n = 143 monthly first-differences of the exchange rates of 6 international currencies against the British pound, from Jan 1975 to Dec 1986, these currencies are: US dollar (USD), Canadian dollar (CAD), Japanese yen (JPY), French franc (FRF), German (deutsche) mark (DEM), and the Italian lira (ITL).
exchangerateexchangerate
A 143 by 7 matrix of exchange rate time-series. The variables include:
Month_YearMonth and year of exchange rate data.
USDUS dollar
CADCanadian dollar
JPYJapanese yen
FRFFrench franc
DEMGerman (deutsche) mark
ITLItalian lira
Steven Culpepper
Lopes, H. F., and West, M. (2004). Bayesian model assessment in factor analysis, Statistica Sinica, 14, 41–67.
Man, A. & Culpepper, S. A. (2020). A mode-jumping algorithm for Bayesian factor analysis. Journal of the American Statistical Association, doi:10.1080/01621459.2020.1773833.
West, M., and Harrison, J. (1997), Bayesian forecasting and dynamic models (2nd ed.), Berlin, Heidelberg: Springer-Verlag.
Implement the Man and Culpepper (2020) mode-jumping algorithm to factor analyze ordinal response data. Missing values should be specified as a non-numeric value such as NA.
IFA_Mode_Jumper(Y, M, gamma, Ms, sdMH, burnin, chain_length = 10000L)IFA_Mode_Jumper(Y, M, gamma, Ms, sdMH, burnin, chain_length = 10000L)
Y |
A N by J matrix of item responses. |
M |
The number of factors. |
gamma |
Mode-jumping tuning parameter. Man & Culpepper used 0.5. |
Ms |
A vector of the number of score categories. Note 2 = two parameter normal ogive, >2 ordinal normal ogive. |
sdMH |
A vector of tuning parameters of length J for implementing the Cowles (1996) Metropolis-Hastings threshold sampler. |
burnin |
Number of burn-in iterations to discard. |
chain_length |
The total number of iterations (burn-in + post-burn-in). |
A list that contains nsamples = chain_length - burnin array draws from the posterior distribution:
LAMBDA: A J by M by nsamples array of sampled loading matrices on the standardized metric.
PSIs: A J by nsamples matrix of vector of variable uniquenesses on the standardized metric.
ROW_OUT: A matrix of sampled row indices of founding variables for mode-jumping algorithm.
THRESHOLDS: An array of sampled thresholds.
INTERCEPTS: Sampled variable thresholds on the standardized metric.
ACCEPTED: Acceptance rates for mode-jumping Metropolis-Hastings (MH) steps.
MHACCEPT: A J vector of acceptance rates for item threshold parameters. Note that binary items have an acceptance rate of zero, because MH steps are never performed.
Albert X Man, Steven Andrew Culpepper
Cowles, M. K. (1996), Accelerating Monte Carlo Markov chain convergence for cumulative link generalized linear models," Statistics and Computing, 6, 101-111.
Man, A. & Culpepper, S. A. (2020). A mode-jumping algorithm for Bayesian factor analysis. Journal of the American Statistical Association, doi:10.1080/01621459.2020.1773833.
Implement the Man and Culpepper (2020) mode-jumping algorithm to factor analyze mixed-type response data. Missing values should be specified as a non-numeric value such as NA.
IFA_Mode_Jumper_MixedResponses( Y, M, gamma, Ms, sdMH, bounds, burnin, chain_length = 10000L )IFA_Mode_Jumper_MixedResponses( Y, M, gamma, Ms, sdMH, bounds, burnin, chain_length = 10000L )
Y |
A N by J matrix of mixed-type item responses. |
M |
An interger specifying the number of factors. |
gamma |
The value of the mode-jumping tuning parameter. Man and Culpepper (2020) used gamma = 0.5. |
Ms |
model indicator where 0 = "bounded", 1 = "continuous", 2 = "binary", >2 = "ordinal". |
sdMH |
A J vector of tuning parameters for the Cowles (1996) Metropolis-Hastings sampler for ordinal data latent thresholds. |
bounds |
A J by 2 matrix denoting the min and max variable values. Note that bounds are only used for variable j if element j of Ms is zero. |
burnin |
Number of burn-in iterations to discard. |
chain_length |
The total number of iterations (burn-in + post-burn-in). |
A list that contains nsamples = chain_length - burnin array draws from the posterior distribution:
LAMBDA: A J by M by nsamples array of sampled loading matrices on the standardized metric.
PSIs: A J by nsamples matrix of vector of variable uniquenesses on the standardized metric.
ROW_OUT: A matrix of sampled row indices of founding variables for mode-jumping algorithm.
THRESHOLDS: An array of sampled thresholds.
INTERCEPTS: Sampled variable thresholds on the standardized metric.
ACCEPTED: Acceptance rates for mode-jumping Metropolis-Hastings (MH) steps.
MHACCEPT: A J vector of acceptance rates for item threshold parameters. Note that binary items have an acceptance rate of zero, because MH steps are never performed.
LAMBDA_unst: An array of unstandardized loadings.
PSIs_inv_unst: A matrix of unstandardized uniquenesses.
THRESHOLDS_unst: Unstandardized thresholds.
INTERCEPTS_unst: Unstandardized intercepts.
Albert X Man, Steven Andrew Culpepper
Cowles, M. K. (1996), Accelerating Monte Carlo Markov chain convergence for cumulative link generalized linear models," Statistics and Computing, 6, 101-111.
Man, A. & Culpepper, S. A. (2020). A mode-jumping algorithm for Bayesian factor analysis. Journal of the American Statistical Association, doi:10.1080/01621459.2020.1773833.
Internal function to compute -2LL using unstandardized parameters.
min2LL_ono(N, J, Y, MISS, as, bs, theta, Ms, Kaps)min2LL_ono(N, J, Y, MISS, as, bs, theta, Ms, Kaps)
N |
The number of observations. (> 0) |
J |
The number of items. (> 0) |
Y |
A N by J matrix of item responses. |
MISS |
A N by J matrix of missing data indicators. |
as |
A matrix of item loadings. |
bs |
A vector of threshold parameters. |
theta |
A matrix of factor scores. |
Ms |
A vector of the number of score categories. Note 2 = two parameter normal ogive, >2 ordinal normal ogive. |
Kaps |
A matrix of category thresholds. |
-2LL.
Steven Andrew Culpepper
Generate posterior predictions for new variables using posterior samples.
mixedresponse_posterior_prediction( OUTPUT, Y, Ms, variable_predict_flag, bounds, n_mcmc_iterations = 10L )mixedresponse_posterior_prediction( OUTPUT, Y, Ms, variable_predict_flag, bounds, n_mcmc_iterations = 10L )
OUTPUT |
A list of output from IFA_Mode_Jumper_MixedResponses. |
Y |
A N by J matrix of item responses for predictions. Variables to predict are indicated in Y by NAs. |
Ms |
model indicator where 0 = "bounded", 1 = "continuous", 2 = "binary", >2 = "ordinal". |
variable_predict_flag |
A J vector. 0 = do not predict the variable; 1 = predict the variable. |
bounds |
A J by 2 matrix denoting the min and max variable values. Note that bounds are only used for variable j if element j of Ms is zero. |
n_mcmc_iterations |
The number of Gibbs iterations for sampling posterior predictions for factor scores and missing data. The default is 10 iterations. |
array of predictions for all posterior samples provided in OUTPUT.
Steven Andrew Culpepper
Rotates loading matrix according to specified founding variable row indices.
proposal2(new_r_idx, lambda, factors)proposal2(new_r_idx, lambda, factors)
new_r_idx |
vector of row indices of length equal to the number of factors. |
lambda |
Loading matrix. |
factors |
A n x m matrix of factor scores that is rotated. |
A list of rotated loadings and factors.
Albert X Man