author: Junhao Pan, Lijin Zhang
published: May 28, 2019
The 'blcfa' package uses Bayesian covariance lasso prior confirmatory factor analysis to detect significant residual covariances and generate the corresponding mplus file.
If you would like to know the details about Bayesian covariance lasso prior confirmatory factor analysis, please refer to Pan, Ip and Dubé(2017).
(Pan, J., Ip, E. H., & Dubé, L. (2017). An alternative to post hoc model modification in confirmatory factor analysis: the Bayesian lasso. Psychological Methods, 22(4), 687–704.)
install.packages("blcfa") #It hasn't been released yet. 2019-05-28
If you want to try out the latest development 'blcfa' code, you can install it from github using Hadley Wickham's 'devtools' package.
install.packages("devtools")
library(devtools)
install_github("zhanglj37/blcfa")
library(blcfa)
filename <- "ss.txt"
varnames <- c("gender",paste("y", 1:17, sep = ""))
usevar <- c(paste("y", 1:17, sep = ""))
myModel<-'
# 1. CFA
f1 =~ y1 + y2 + y3 + y4 + y5
f2 =~ y6 + y7 + y8 + y9 + y10 + y11
f3 =~ y12 + y13 + y14 + y15 + y16 + y17
'
# make sure there is a space between each variable or symbol
blcfa(filename,varnames,usevar,myModel,ms=-9)
# ms represents missing value (you don't need to define it if -999 or NA represents missing value in the dataset).
After running this function(two chains):
num of chain:1
num of iteration:100
num of iteration:200
....
num of chain:2
...
you will get Mplus input file and output file that include significant residual correlations detected by Bayesian covariance lasso prior confirmatory factor analysis. For example:
TITLE: Bayesian Lasso CFA
DATA: FILE = ss.txt ;
VARIABLE:
NAMES = gender y1 y2 y3 y4 y5 y6 y7 y8 y9
y10 y11 y12 y13 y14 y15 y16 y17 ;
USEV = y1 y2 y3 y4 y5 y6 y7 y8 y9
y10 y11 y12 y13 y14 y15 y16 y17 ;
ANALYSIS:
ESTIMATOR = BAYES;
PROC = 2;
BITERATIONS = (10000);
MODEL:
! 1. CFA;
f1 BY y1 y2 y3 y4 y5 ;
f2 BY y6 y7 y8 y9 y10 y11;
f3 BY y12 y13 y14 y15 y16 y17 ;
y11 with y13 ;
y11 with y14 ;
y13 with y14 ;
OUTPUT: TECH1 TECH8 STDY;
PLOT: TYPE= PLOT2;
The convergence criterion is epsr value < 1.2. If the model does not converge within the number of burn-in MCMC samples(N.burn) (the default value = 5000), you will get an epsr graph (for reference) and the warnings:
Error: The convergence criterion is not satisfied.
Please refer to the epsr graph and increase the MCMAX.
Then you should increase the value of N.burn and MCMAX (Total number of MCMC samples for inference, the default value = 15000).
blcfa(filename,varnames,usevar,myModel,ms=-9,MCMAX=30000,N.burn=15000)
If you want to get the detailed results of the Bayesian covariance lasso prior confirmatory factor analysis:
blcfa(filename,varnames,usevar,myModel,ms=-9,MCMAX = 10000, N.burn = 5000,bloutput = TRUE)
Then you will get the results folder includes: ppp, epsr graph, estimated value, standard error and hpd interval of parameters (ly, mu, phi and psx).
Detect significant residual correlations by p-value rather than Highest Posterior Density (HPD) interval.
blcfa(filename,varnames,usevar,myModel,ms=-9,MCMAX = 10000, N.burn = 5000,bloutput = TRUE,interval_psx = FALSE)
https://github.com/zhanglj37/blcfa/issues
or contact with me: zhanglj37@mail2.sysu.edu.cn.
- Bayesian lasso confirmatory factor analysis models with ordered categorical data.
- Parallel computing of two MCMC chains.
If you have any suggestions or are willing to join in the improvement of this package, please contact with me. I really hope that we can jointly promote the improvement of this package.