Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
For-Loop For-poLCA包(R)运行多个类模型_R_For Loop - Fatal编程技术网

For-Loop For-poLCA包(R)运行多个类模型

For-Loop For-poLCA包(R)运行多个类模型,r,for-loop,R,For Loop,我试图根据潜在类的不同数量选择最适合我的数据的LCA模型(R package=poLCA) 我想使用for循环为1:5的潜在类运行模型,并为每个模型生成一个带有G2,AIC&BIC值的表 ## Generating a table of G2,AIC & BIC for different no of LCA classes (1:5) for 6 variables. library(poLCA) as.data.frame(mod_sum_v6) for(i in 1:5){

我试图根据潜在类的不同数量选择最适合我的数据的LCA模型(R package=
poLCA

我想使用for循环为1:5的潜在类运行模型,并为每个模型生成一个带有
G2
AIC
&
BIC
值的表

## Generating a table of G2,AIC & BIC for different no of LCA classes (1:5) for 6 variables. 

library(poLCA)
as.data.frame(mod_sum_v6)
for(i in 1:5){
    lca_v6<- poLCA(cbind(A,B,C,D,E,F) ~ 1, 
    maxiter=50000,nclass=i,
    nrep=1, data=data)
    mod_sum_v6[i]<-c(lca_v6$Chisq,lca_v6$resid.df,lca_v6$Gsq,lca_v6$aic,lca_v6$bic)
}
##为6个变量的不同LCA类别(1:5)生成G2、AIC和BIC表。
图书馆(波尔卡)
as.data.frame(mod_sum_v6)
(我在1:5中){

lca_v6我在网上找到了这段代码,它运行一系列模型,有两到十组。当nrep=10时,它会对每个模型运行10次,并保持模型的BIC最低

f<-with(mydata, cbind(F29_a,F29_b,F29_c,F27_a,F27_b,F27_e,F09_a, F09_b, F09_c)~1) #

max_II <- -100000
min_bic <- 100000
for(i in 2:10){
lc <- poLCA(f, mydata, nclass=i, maxiter=3000, 
          tol=1e-5, na.rm=FALSE,  
          nrep=10, verbose=TRUE, calc.se=TRUE)
  if(lc$bic < min_bic){
  min_bic <- lc$bic
LCA_best_model<-lc
}
}       
LCA_best_model
f