knitr::opts_chunk$set(echo = TRUE)
Note: the estimation process can be time consuming depending on the computing power. You can same some time by reducing the length of the chains.
1) Load the package, obtain the data, and check the true loading pattern (qlam) and local dependence.
library(LAWBL) dat <- sim18cfa0$dat J <- ncol(dat) # no. of items K <- 3 # no. of factors sim18cfa0$qlam sim18cfa0$LD
2) E-step: Estimate with the PCFA-LI model (E-step) by setting LD=F and the design matrix Q. Only a few loadings need to be specified in Q (e.g., 2 per factor). Longer chain is suggested for stabler performance (burn=iter=5,000 by default).
Q<-matrix(-1,J,K); # -1 for unspecified items Q[1:2,1]<-Q[7:8,2]<-Q[13:14,3]<-1 # 1 for specified items Q m0 <- pcfa(dat = dat, Q = Q,LD = FALSE) # summarize basic information summary(m0) #summarize significant loadings in pattern/Q-matrix format summary(m0, what = 'qlambda') #factorial eigenvalue summary(m0,what='eigen') #plotting factorial eigenvalue plot_lawbl(m0) # trace plot_lawbl(m0, what='density') #density plot_lawbl(m0, what='EPSR') #EPSR
3) C-step: Reconfigure the Q matrix for the C-step with one specified loading per item based on results from the E-step. Estimate with the PCFA model by setting LD=TRUE (by default). Longer chain is suggested for stabler performance. Results are very close to the E-step, since there's no LD in the data.
Q<-matrix(-1,J,K); tmp<-summary(m0, what="qlambda") cind<-apply(tmp,1,which.max) Q[cbind(c(1:J),cind)]<-1 #alternatively #Q[1:6,1]<-Q[7:12,2]<-Q[13:18,3]<-1 # 1 for specified items m1 <- pcfa(dat = dat, Q = Q) summary(m1) summary(m1, what = 'qlambda') summary(m1, what = 'offpsx') #summarize significant LD terms summary(m1,what='eigen') #plotting factorial eigenvalue # par(mar = rep(2, 4)) plot_lawbl(m1) # trace plot_lawbl(m1, what='density') #density plot_lawbl(m1, what='EPSR') #EPSR
4) CFA-LD: One can also configure the Q matrix for a CFA model with local dependence (i.e. without any unspecified loading) based on results from the C-step. Results are also very close.
Q<-summary(m1, what="qlambda") Q[Q!=0]<-1 Q m2 <- pcfa(dat = dat, Q = Q) summary(m2) summary(m2, what = 'qlambda') summary(m2, what = 'offpsx') summary(m2,what='eigen') plot_lawbl(m2) # Eigens' traces are excellent without regularization of the loadings
1) Obtain the data and check the true loading pattern (qlam) and local dependence.
dat <- sim18cfa1$dat J <- ncol(dat) # no. of items K <- 3 # no. of factors sim18cfa1$qlam sim18cfa1$LD # effect size = .3
2) E-step: Estimate with the PCFA-LI model (E-step) by setting LD=FALSE and the design matrix Q. Only a few loadings need to be specified in Q (e.g., 2 per factor). Some loading estimates are biased due to ignoring the LD. So do the eigenvalues.
Q<-matrix(-1,J,K); # -1 for unspecified items Q[1:2,1]<-Q[7:8,2]<-Q[13:14,3]<-1 # 1 for specified items Q m0 <- pcfa(dat = dat, Q = Q,LD = FALSE) summary(m0) summary(m0, what = 'qlambda') summary(m0,what='eigen') plot_lawbl(m0) # trace plot_lawbl(m0, what='EPSR') #EPSR
3) C-step: Reconfigure the Q matrix for the C-step with one specified loading per item based on results from the E-step. Estimate with the PCFA model by setting LD=TRUE (by default). The estimates are more accurate, and the LD terms can be largely recovered.
Q<-matrix(-1,J,K); tmp<-summary(m0, what="qlambda") cind<-apply(tmp,1,which.max) Q[cbind(c(1:J),cind)]<-1 Q m1 <- pcfa(dat = dat, Q = Q) summary(m1) summary(m1, what = 'qlambda') summary(m1,what='eigen') summary(m1, what = 'offpsx')
4) CFA-LD: Configure the Q matrix for a CFA model with local dependence (i.e. without any unspecified loading) based on results from the C-step. Results are better than, but similar to the C-step.
Q<-summary(m1, what="qlambda") Q[Q!=0]<-1 Q m2 <- pcfa(dat = dat, Q = Q) summary(m2) summary(m2, what = 'qlambda') summary(m2,what='eigen') summary(m2, what = 'offpsx')
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.