From beddcb9a82ca1e375a116b661909e0e579b05811 Mon Sep 17 00:00:00 2001 From: Mike Barkmin Date: Mon, 26 Feb 2018 15:55:11 +0100 Subject: [PATCH 1/2] add caic --- R/poLCA.R | 1 + R/print.poLCA.R | 1 + man/poLCA.Rd | 1 + 3 files changed, 3 insertions(+) diff --git a/R/poLCA.R b/R/poLCA.R index 35d3949..5a6c04f 100644 --- a/R/poLCA.R +++ b/R/poLCA.R @@ -159,6 +159,7 @@ function(formula,data,nclass=2,maxiter=1000,graphs=FALSE,tol=1e-10, ret$npar <- (R*sum(K.j-1)) + (R-1) # number of degrees of freedom used by the model (number of estimated parameters) if (S>1) { ret$npar <- ret$npar + (S*(R-1)) - (R-1) } ret$aic <- (-2 * ret$llik) + (2 * ret$npar) # Akaike Information Criterion + ret$caic <- -2*ret$llik + ret$npar(log(N) + 1) ret$bic <- (-2 * ret$llik) + (log(N) * ret$npar) # Schwarz-Bayesian Information Criterion ret$Nobs <- sum(rowSums(y==0)==0) # number of fully observed cases (if na.rm=F) if (all(rowSums(y==0)>0)) { # if no rows are fully observed diff --git a/R/print.poLCA.R b/R/print.poLCA.R index 0c5098d..16ff789 100644 --- a/R/print.poLCA.R +++ b/R/print.poLCA.R @@ -27,6 +27,7 @@ function(x, ...) { cat("residual degrees of freedom:", x$resid.df, "\n") cat("maximum log-likelihood:", x$llik, "\n \n") cat("AIC(",R,"): ",x$aic,"\n",sep="") + cat("CAIC(",R,"): ",x$caic,"\n",sep="") cat("BIC(",R,"): ",x$bic,"\n",sep="") if (S==1) cat("G^2(",R,"): ",x$Gsq," (Likelihood ratio/deviance statistic) \n",sep="") cat("X^2(",R,"): ",x$Chisq," (Chi-square goodness of fit) \n \n",sep="") diff --git a/man/poLCA.Rd b/man/poLCA.Rd index 3429e1d..e437a3b 100644 --- a/man/poLCA.Rd +++ b/man/poLCA.Rd @@ -47,6 +47,7 @@ Model specification: Latent class models have more than one manifest variable, s \item{coeff.se}{standard errors of coefficient estimates on covariates (when estimated), in the same format as \code{coeff}.} \item{coeff.V}{covariance matrix of coefficient estimates on covariates (when estimated).} \item{aic}{Akaike Information Criterion.} +\item{caic}{Consistent Akaike Information Criterion.} \item{bic}{Bayesian Information Criterion.} \item{Gsq}{Likelihood ratio/deviance statistic.} \item{Chisq}{Pearson Chi-square goodness of fit statistic for fitted vs. observed multiway tables.} From ec40c4af1db5bdd27727684f0c1f1f62718d3d07 Mon Sep 17 00:00:00 2001 From: Mike Barkmin Date: Mon, 26 Feb 2018 15:56:20 +0100 Subject: [PATCH 2/2] better formating --- R/poLCA.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/poLCA.R b/R/poLCA.R index 5a6c04f..e06fde7 100644 --- a/R/poLCA.R +++ b/R/poLCA.R @@ -159,7 +159,7 @@ function(formula,data,nclass=2,maxiter=1000,graphs=FALSE,tol=1e-10, ret$npar <- (R*sum(K.j-1)) + (R-1) # number of degrees of freedom used by the model (number of estimated parameters) if (S>1) { ret$npar <- ret$npar + (S*(R-1)) - (R-1) } ret$aic <- (-2 * ret$llik) + (2 * ret$npar) # Akaike Information Criterion - ret$caic <- -2*ret$llik + ret$npar(log(N) + 1) + ret$caic <- (-2 * ret$llik) + ret$npar(log(N) + 1) ret$bic <- (-2 * ret$llik) + (log(N) * ret$npar) # Schwarz-Bayesian Information Criterion ret$Nobs <- sum(rowSums(y==0)==0) # number of fully observed cases (if na.rm=F) if (all(rowSums(y==0)>0)) { # if no rows are fully observed