From c0ed04aae02e81faa83e046034cb08a8b03092c7 Mon Sep 17 00:00:00 2001 From: Mike Barkmin Date: Mon, 26 Feb 2018 16:16:28 +0100 Subject: [PATCH] add pvalues --- R/poLCA.R | 3 +++ R/print.poLCA.R | 4 ++-- man/poLCA.Rd | 4 +++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/R/poLCA.R b/R/poLCA.R index 35d3949..5f6ee60 100644 --- a/R/poLCA.R +++ b/R/poLCA.R @@ -180,6 +180,9 @@ function(formula,data,nclass=2,maxiter=1000,graphs=FALSE,tol=1e-10, } ret$predcell <- data.frame(datacell,observed=freq,expected=round(fit,3)) # Table that gives observed vs. predicted cell counts ret$Gsq <- 2 * sum(freq*log(freq/fit)) # Likelihood ratio/deviance statistic + ret$df <- max(K.j) ^ J - ret$npar - 1 # Degrees of freedom + ret$Gsq.pvalue <- 1 - pchisq(ret$Gsq, ret$df) + ret$Chisq.pvalue <- 1 - pchisq(ret$Chisq, ret$df) } y[y==0] <- NA ret$y <- data.frame(y) # outcome variables diff --git a/R/print.poLCA.R b/R/print.poLCA.R index 0c5098d..8d3e015 100644 --- a/R/print.poLCA.R +++ b/R/print.poLCA.R @@ -28,8 +28,8 @@ function(x, ...) { cat("maximum log-likelihood:", x$llik, "\n \n") cat("AIC(",R,"): ",x$aic,"\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="") + if (S==1) cat("G^2(",R,"): ",x$Gsq," (", x$Gsq.pvalue, ")"," (Likelihood ratio/deviance statistic) \n",sep="") + cat("X^2(",R,"): ",x$Chisq," (", x$Chisq.pvalue, ")"," (Chi-square goodness of fit) \n \n",sep="") if (x$numiter==x$maxiter) cat("ALERT: iterations finished, MAXIMUM LIKELIHOOD NOT FOUND \n \n") if (!x$probs.start.ok) cat("ALERT: error in user-specified starting values; new start values generated \n \n") if (x$npar>x$N) cat("ALERT: number of parameters estimated (",x$npar,") exceeds number of observations (",x$N,") \n \n") diff --git a/man/poLCA.Rd b/man/poLCA.Rd index 3429e1d..7a09e12 100644 --- a/man/poLCA.Rd +++ b/man/poLCA.Rd @@ -49,7 +49,9 @@ Model specification: Latent class models have more than one manifest variable, s \item{aic}{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.} +\item{Gsq.pvalue}{Likelihood ratio/deviance statistic.} +\item{Chisq}{Pearson Chi-square goodness of fit statistic for fitted vs. observed multiway tables p-value.} +\item{Chisq.pvalue}{Pearson Chi-square goodness of fit statistic for fitted vs. observed multiway tables p-value.} \item{time}{length of time it took to run the model.} \item{npar}{number of degrees of freedom used by the model (estimated parameters).} \item{resid.df}{number of residual degrees of freedom.}