dncObjs = list()
BICvals = numeric(9)
for(i in 2:10){
print(i)
dncObjs[[i]] <- dnc(friendship,M=i,p=3,method="VB",
controls=list(nDraws=500,burnin=100,
MaxItStg2=50,epsilonStg2=1e-15))
BICvals[i-1] <- BIC(dncObjs[[i]])
}
plot(BICvals~c(2:10),type="b",pch=16,
xlab="Number of communities",ylab="BIC value")
( MBest = which.min(BICvals)+1 )
abline(v=MBest,lty=2,col="blue")
Run the code above in your browser using DataLab