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.
library(LAWBL) dat <- sim18cfa0$dat J <- ncol(dat) # no. of items K <- 3 # no. of factors qlam <- sim18cfa0$qlam qlam #> [,1] [,2] [,3] #> [1,] 0.7 0.0 0.0 #> [2,] 0.7 0.0 0.0 #> [3,] 0.7 0.0 0.0 #> [4,] 0.7 0.0 0.0 #> [5,] 0.7 0.4 0.0 #> [6,] 0.7 0.4 0.0 #> [7,] 0.0 0.7 0.0 #> [8,] 0.0 0.7 0.0 #> [9,] 0.0 0.7 0.0 #> [10,] 0.0 0.7 0.0 #> [11,] 0.0 0.7 0.4 #> [12,] 0.0 0.7 0.4 #> [13,] 0.0 0.0 0.7 #> [14,] 0.0 0.0 0.7 #> [15,] 0.0 0.0 0.7 #> [16,] 0.0 0.0 0.7 #> [17,] 0.4 0.0 0.7 #> [18,] 0.4 0.0 0.7 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 #> [,1] [,2] [,3] #> [1,] 1 -1 -1 #> [2,] 1 -1 -1 #> [3,] -1 -1 -1 #> [4,] -1 -1 -1 #> [5,] -1 -1 -1 #> [6,] -1 -1 -1 #> [7,] -1 1 -1 #> [8,] -1 1 -1 #> [9,] -1 -1 -1 #> [10,] -1 -1 -1 #> [11,] -1 -1 -1 #> [12,] -1 -1 -1 #> [13,] -1 -1 1 #> [14,] -1 -1 1 #> [15,] -1 -1 -1 #> [16,] -1 -1 -1 #> [17,] -1 -1 -1 #> [18,] -1 -1 -1
m0 <- pcfa(dat = dat, Q = Q,LD = FALSE, burn = 2000, iter = 2000) # summarize basic information summary(m0) #> $N #> [1] 500 #> #> $J #> [1] 18 #> #> $K #> [1] 3 #> #> $`Miss%` #> [1] 0 #> #> $`LD enabled` #> [1] FALSE #> #> $`Burn in` #> [1] 2000 #> #> $Iteration #> [1] 2000 #> #> $`No. of sig lambda` #> [1] 24 #> #> $`Adj. PSR` #> Point est. Upper C.I. #> F1 1.159097 1.437669 #> F2 1.377527 2.323779 #> F3 1.069836 1.274876 #summarize significant loadings in pattern/Q-matrix format summary(m0, what = 'qlambda') #> [,1] [,2] [,3] #> I1 0.7006520 0.0000000 0.0000000 #> I2 0.7129764 0.0000000 0.0000000 #> I3 0.7201485 0.0000000 0.0000000 #> I4 0.6764871 0.0000000 0.0000000 #> I5 0.7018335 0.3981160 0.0000000 #> I6 0.6705350 0.4148202 0.0000000 #> I7 0.0000000 0.7219834 0.0000000 #> I8 0.0000000 0.7758877 0.0000000 #> I9 0.0000000 0.7342936 0.0000000 #> I10 0.0000000 0.6643274 0.0000000 #> I11 0.0000000 0.6936387 0.3736486 #> I12 0.0000000 0.6626755 0.4260824 #> I13 0.0000000 0.0000000 0.6365149 #> I14 0.0000000 0.0000000 0.6849702 #> I15 0.0000000 0.0000000 0.7129319 #> I16 0.0000000 0.0000000 0.7902067 #> I17 0.3956917 0.0000000 0.7233275 #> I18 0.3888041 0.0000000 0.7186225 #factorial eigenvalue summary(m0,what='eigen') #> est sd lower upper sig #> F1 3.332857 0.4751161 2.472778 4.148886 1 #> F2 3.485774 0.5385707 2.567001 4.614304 1 #> F3 3.492405 0.4823052 2.616686 4.444067 1 #plotting factorial eigenvalue oldmar <- par("mar") par(mar = rep(2, 4)) plot_eigen(m0) # trace

plot_eigen(m0, what='density') #density

plot_eigen(m0, what='APSR') #adj, PSRF

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, burn = 2000, iter = 2000) 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_eigen(m1) # trace plot_eigen(m1, what='density') #density plot_eigen(m1, what='APSR') #adj, PSRF
dat <- sim18cfa1$dat J <- ncol(dat) # no. of items K <- 3 # no. of factors sim18cfa1$qlam sim18cfa1$LD # effect size = .3 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, burn = 10000, iter = 10000) summary(m0) summary(m0, what = 'qlambda') summary(m0,what='eigen') plot_eigen(m0) # trace plot_eigen(m0, what='APSR')
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,burn = 10000, iter = 10000) summary(m1) summary(m1, what = 'qlambda') summary(m1,what='eigen') summary(m1, what = 'offpsx')