Skip to content

Commit

Permalink
hompage update
Browse files Browse the repository at this point in the history
  • Loading branch information
kim0sun committed Oct 10, 2023
1 parent aa524a7 commit 518c421
Show file tree
Hide file tree
Showing 15 changed files with 262 additions and 462 deletions.
Binary file modified .DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ BugReports: https://github.com/kim0sun/glca/issues/
Encoding: UTF-8
LazyData: true
Depends: R (>= 3.5.0)
RoxygenNote: 7.1.1
RoxygenNote: 7.2.1
Imports:
MASS,
Rcpp,
Expand Down
5 changes: 2 additions & 3 deletions R/glca_output.R
Original file line number Diff line number Diff line change
Expand Up @@ -281,9 +281,8 @@ glca_output <- function(
P = do.call(rbind, pclass)
gof <- list(
loglik = EM$loglik,
aic = -2 * EM$loglik + 2 * npar,
caic = -2 * EM$loglik + (log(N) + 1L) * npar,
bic = -2 * EM$loglik + log(N) * npar,
AIC = -2 * EM$loglik + 2 * npar,
BIC = -2 * EM$loglik + log(N) * npar,
entropy = 1 - sum(-P[P != 0] * log(P)[P != 0]) / (N * log(C)),
df = df,
Gsq = 2 * (datalist$loglik0 - EM$loglik)
Expand Down
10 changes: 4 additions & 6 deletions R/gofglca.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#' Goodness of Fit Tests for Fitted \code{glca} Model
#'
#' Provides AIC, CAIC, BIC, entropy and deviance statitistic for goodness of fit test for the fitted model. Given \code{object2}, the function computes the log-likelihood ratio (LRT) statisic for comparing the goodness of fit for two models. The bootstrap p-value can be obtained from the empirical distribution of LRT statistic by choosing \code{test = "boot"}.
#' Provides AIC, BIC, entropy and deviance statitistic for goodness of fit test for the fitted model. Given \code{object2}, the function computes the log-likelihood ratio (LRT) statisic for comparing the goodness of fit for two models. The bootstrap p-value can be obtained from the empirical distribution of LRT statistic by choosing \code{test = "boot"}.
#'
#' @param object an object of "\code{glca}", usually, a result of a call to \code{glca}.
#' @param ... an optional object of "\code{glca}" to be compared with \code{object}.
Expand Down Expand Up @@ -69,7 +69,7 @@

gofglca <- function(
object, ..., test = NULL, nboot = 50,
criteria = c("logLik", "AIC", "CAIC", "BIC", "entropy"),
criteria = c("AIC", "BIC", "entropy"),
maxiter = 500, eps = 1e-4, seed = NULL, verbose = FALSE
)
{
Expand Down Expand Up @@ -105,8 +105,7 @@ gofglca <- function(
})

criteria <- match.arg(criteria, several.ok = TRUE)
valid.ind <- match(criteria, c("logLik", "AIC", "CAIC", "BIC", "entropy"), 0L)
gof <- lapply(obj, function(x) x$gof[c(valid.ind, 6L:7L)])
gof <- lapply(obj, function(x) x$gof[c("loglik", criteria, "df", "Gsq")])

models <- sapply(obj, function(x) x$model)
resp <- sapply(obj, function(x) paste0(x$var.names$y.names, collapse = ","))
Expand All @@ -122,7 +121,6 @@ gofglca <- function(
gsqR <- 2L * diff(llik)

gtable <- as.matrix(do.call(rbind, lapply(gof[ord], unlist)))
colnames(gtable) <- c(criteria, "Res.Df", "Gsq")
rownames(gtable) <- ord

# random seed
Expand Down Expand Up @@ -189,7 +187,7 @@ gofglca <- function(
npar <- sapply(obj[ord], function(x) x$model$npar)
Df <- diff(npar)
dtable <- cbind(npar, llik, c(NA, Df), c(NA, round(gsqR, 3L)))
colnames(dtable) <- c("npar", "logLik", "Df", "Deviance")
colnames(dtable) <- c("npar", "loglik", "Df", "Deviance")
rownames(dtable) <- ord

if (!is.null(test))
Expand Down
4 changes: 2 additions & 2 deletions R/print.glca.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ print.glca = function(x, ...)

cat("\nlog-likelihood :", gof$loglik,
"\n G-squared :", gof$Gsq,
"\n AIC :", gof$aic,
"\n BIC :", gof$bic, "\n")
"\n AIC :", gof$AIC,
"\n BIC :", gof$BIC, "\n")
}
2 changes: 1 addition & 1 deletion R/reorder.glca.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
#' @import stats
#' @export

reorder.glca <- function(x, ..., class.order = NULL, cluster.order = NULL, decreasing = TRUE)
reorder.glca <- function(x, class.order = NULL, cluster.order = NULL, decreasing = TRUE, ...)
{
if (!is.null(class.order)) {
if (!setequal(as.numeric(class.order), 1:x$model$C))
Expand Down
28 changes: 16 additions & 12 deletions R/summary.glca.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ summary.glca <- function(

cat("\nlog-likelihood :", gof$loglik,
"\n G-squared :", gof$Gsq,
"\n AIC :", gof$aic,
"\n BIC :", gof$bic, "\n")
"\n AIC :", gof$AIC,
"\n BIC :", gof$BIC, "\n")

if (model$W > 1L){
cat("\nMarginal prevalences for latent classes :\n")
Expand All @@ -61,19 +61,22 @@ summary.glca <- function(
print(round(colMeans(posterior$cluster), 5L))
cat("\nClass prevalences by cluster :\n")
print(round(posterior$wclass, 5L))
cat("\n")
} else {
cat("\nMarginal prevalences for latent classes :\n")
print(round(colMeans(do.call(rbind, posterior)), 5L))
if (model$G < 15L) {
cat("\nClass prevalences by group :\n")
prev = as.matrix(do.call(rbind, lapply(posterior, colMeans)))
dimnames(prev) = list(var.names$g.names,
paste0("Class ", 1L:model$C))
print(round(prev, 5L))
cat("\n")
} else {
cat("\nToo many groups to be printed.\n")
}
if (model$G > 1) {
if (model$G < 15L) {
cat("\nClass prevalences by group :\n")
prev = as.matrix(do.call(rbind, lapply(posterior, colMeans)))
dimnames(prev) = list(var.names$g.names,
paste0("Class ", 1L:model$C))
print(round(prev, 5L))
cat("\n")
} else {
cat("\nToo many groups to be printed.\n")
}
} else cat("\n")
}

if (model$W > 1L) {
Expand All @@ -87,6 +90,7 @@ summary.glca <- function(
if (model$Q > 0L) {
cat("Logistic regression coefficients (level 2) :\n")
print(round(param$beta[[2L]], digits))
cat("\n")
}
cat("\n")
}
Expand Down
138 changes: 49 additions & 89 deletions docs/404.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 518c421

Please sign in to comment.