# NOT RUN {
#Load the psych package to apply the algorithm with the bfi dataset
library(psych)
data(bfi)
#subtract 1 from all items so scores start at 0
ydat<-as.matrix(bfi[,1:25])-1
J<-ncol(ydat)
N<-nrow(ydat)
#compute the number of item categories
Ms<-apply(ydat,2,max)+1
#specify burn-in and chain length
#in full application set these to 10000 and 20000
burnin = 10
chain_length=20
out5<-IFA_Mode_Jumper(ydat,M=5,gamma=.5,Ms,sdMH=rep(.025,J),burnin,chain_length)
#check the acceptance rates for the threshold tuning parameter fall between .2 and .5
mh_acceptance_rates<-t(out5$MHACCEPT)
#compute mean thresholds
mthresholds<-apply(out5$THRESHOLDS,c(1,2),mean)
#compute mean intercepts
mintercepts<-apply(out5$INTERCEPTS,1,mean)
#rotate loadings to PLT
my_lambda_sample = out5$LAMBDA
my_M<-5
for (j in 1:dim(my_lambda_sample)[3]) {
my_rotate = proposal2(1:my_M,my_lambda_sample[,,j],matrix(0,nrow=N,ncol = my_M))
my_lambda_sample[,,j] = my_rotate$lambda
}
#compute mean of PLT loadings
mLambda<-apply(my_lambda_sample,c(1,2),mean)
#find promax rotation of posterior mean
rotatedLambda<-promax(mLambda)$loadings[1:J,1:my_M]
#save promax rotation matrix
promaxrotation<-promax(mLambda)$rotmat
#compute the factor correlation matrix
phi<-solve(t(promaxrotation)%*%promaxrotation)
# }
Run the code above in your browser using DataLab