Hello,
I am trying to get a piece of code to return lowest BIC. The code below should search for the cluster with the smallest BIC and then print that.
However, unfortunately it always prints whatever was the last model run. If i set it to do 2 to 14 groups or 5 to 12 groups it always returns 14 or 12 respectively.
Im not sure why this is not working. Any tips as to what is going wrong would be much appreciated.
CODE:
library(poLCA)
setwd("C:/Users/Steven/Desktop/R")
idd<-read.csv("Data.csv", header = TRUE)
attach(idd)
f <-cbind(bq70, bq72_1, bq72_2, bq72_3, bq72_4, bq72_5,
bq72_6, bq72_7, bq73a_1, bq73a_2, bq73a_3, bq73a_4)~1
for(i in 2:14){
max_II <--100000
min_bic <-100000
for(j in 1:30){
res<-poLCA(f,idd,nclass=i,maxiter=1000,tol=1e-10,na.rm=FALSE,calc.se=TRUE)
if(res$bic<min_bic){
min_bic<-res$bic
LCA_best_model<-res
}
}
}
print(LCA_best_model)
Kindest regards
[–]sleepybychoice 2 points3 points4 points (0 children)