Appreciated. I just add a print(n)beforeresult <- summary(model) according to your advice. It didn't help, and now R session aborted before printed n. So now I realize that the error may happened after model <- brm() but not exactly a fault of summary().
It's not always the same dataset. For example, when R aborted, I restart the session and reset 1:500 in for() to 4:500 etc. After few cycles when it absorted again, I restart and reset to 6:500 .
In addition, you are right to find it same as only running for n=500 . Indeed, some parameters of result are assigned to a matrix output as followed.
if(all(result$fixed[,5]<1.1) && all(result$random$group[,5]<1.1))
{
output[n,1] <- result$fixed[1,1] #gamma00
output[n,2] <- result$fixed[1,2] #gamma00_se
......
} else {
output[n,40] <- "unconverged"
}
write.table(output,output_name,F,T)
The sentences after result <- summary(model) are omitted in my description for simplified purposes. Sorry for causing confusion.