Skip to content

Commit

Permalink
coef reorder
Browse files Browse the repository at this point in the history
  • Loading branch information
kim0sun committed Aug 27, 2024
1 parent bca6dc5 commit 63d3b69
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 92 deletions.
Binary file modified .DS_Store
Binary file not shown.
87 changes: 85 additions & 2 deletions R/coef.glca.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,91 @@ coef.glca = function(
if (is.null(object$param$beta))
return(NULL)
else {
# Coefficient design
coef = list()
if (object$model$W > 1) {
coef$Level1 = list()
for (w in 1L:object$model$W) {
coef[[1L]][[w]] = list()
for (c in 1L:(object$model$C - 1L)) {
coef[[1L]][[w]][[c]] = data.frame(
exp(object$param$beta[[1L]][[w]][, c]),
b <- object$param$beta[[1L]][[w]][, c],
row.names = object$var.names$x.names
)
colnames(coef[[1L]][[w]][[c]]) =
c("Odds Ratio", "Coefficient")

if (!is.null(object$convergence$score)) {
coef[[1L]][[w]][[c]] = cbind(
coef[[1L]][[w]][[c]],
se <- object$std.err$beta[[1L]][[w]][, c],
tval <- b / se,
2L * stats::pt(abs(tval), object$model$df, lower.tail = FALSE)
)
colnames(coef[[1L]][[w]][[c]]) =
c("Odds Ratio", "Coefficient", " Std. Error",
" t value", " Pr(>|t|)")
}
}
names(coef[[1L]][[w]]) = paste0("Class", 1L:(object$model$C - 1L), "/", object$model$C)
}
names(coef[[1L]]) = paste0("Cluster", 1L:object$model$W)
if (object$model$Q > 0L) {
coef$Level2 = list()
for (c in 1L:(object$model$C - 1L)) {
coef[[2L]][[c]] <- data.frame(
exp(object$param$beta[[2L]][, c]),
b <- object$param$beta[[2L]][, c],
row.names = object$var.names$z.names
)
colnames(coef[[2L]][[c]]) <-
c("Odds Ratio", "Coefficient")

if (!is.null(object$convergence$score)) {
coef[[2L]][[c]] <- cbind(
coef[[2L]][[c]],
se <- object$std.err$beta[[2L]][, c],
tval <- b / se,
2 * stats::pt(abs(tval), object$model$df, lower.tail = FALSE)
)
colnames(coef[[2L]][[c]]) <-
c("Odds Ratio", "Coefficient", " Std. Error",
" t value", " Pr(>|t|)")
}
}
names(coef[[2L]]) <- paste0("Class", 1L:(object$model$C - 1L), "/", object$model$C)
}

} else {
for (g in 1L:object$model$G) {
coef[[g]] <- list()
for (c in 1L:(object$model$C - 1L)) {
coef[[g]][[c]] <- data.frame(
exp(object$param$beta[[g]][, c]),
b <- object$param$beta[[g]][, c],
row.names = object$var.names$x.names
)
colnames(coef[[g]][[c]]) <-
c("Odds Ratio", "Coefficient")

if (!is.null(object$convergence$score)) {
coef[[g]][[c]] <- cbind(
coef[[g]][[c]],
se <- object$std.err$beta[[g]][, c],
tval <- b / se,
2 * stats::pt(abs(tval), object$model$df, lower.tail = FALSE)
)
colnames(coef[[g]][[c]]) <-
c("Odds Ratio", "Coefficient", " Std. Error",
" t value", " Pr(>|t|)")
}
}
names(coef[[g]]) <- paste0("Class", 1L:(object$model$C - 1L), "/", object$model$C)
}
names(coef) <- object$var.names$g.names
}
if (object$model$coeff.inv) {
coef = object$coefficient
if (object$model$W > 1) {
if (intercept) {
cat("Intercept :\n\n")
Expand Down Expand Up @@ -120,7 +203,7 @@ coef.glca = function(
}
}
} else {
coef = object$coefficient
coef = coeff
if (object$model$W > 1) {
cat("Level 1 Coefficients :\n\n")
for (w in 1:object$model$W) {
Expand Down
90 changes: 0 additions & 90 deletions R/glca_output.R
Original file line number Diff line number Diff line change
Expand Up @@ -161,95 +161,6 @@ glca_output <- function(
}
}

# Coefficient design
if (!is.null(param$beta)) {
coeff = list()
if (W > 1) {
coeff$Level1 = list()
for (w in 1L:W) {
coeff[[1L]][[w]] = list()
for (c in 1L:(C - 1L)) {
coeff[[1L]][[w]][[c]] = data.frame(
exp(param$beta[[1L]][[w]][, c]),
b <- param$beta[[1L]][[w]][, c],
row.names = x.names
)
colnames(coeff[[1L]][[w]][[c]]) =
c("Odds Ratio", "Coefficient")

if (!is.null(scores)) {
coeff[[1L]][[w]][[c]] = cbind(
coeff[[1L]][[w]][[c]],
se <- std.err$beta[[1L]][[w]][, c],
tval <- b / se,
2L * stats::pt(abs(tval), df, lower.tail = FALSE)
)
colnames(coeff[[1L]][[w]][[c]]) =
c("Odds Ratio", "Coefficient", " Std. Error",
" t value", " Pr(>|t|)")
}
}
names(coeff[[1L]][[w]]) = paste0("Class", 1L:(C - 1L), "/", C)
}
names(coeff[[1L]]) = paste0("Cluster", 1L:W)
if (Q > 0L) {
coeff$Level2 = list()
for (c in 1L:(C - 1L)) {
coeff[[2L]][[c]] <- data.frame(
exp(param$beta[[2L]][, c]),
b <- param$beta[[2L]][, c],
row.names = z.names
)
colnames(coeff[[2L]][[c]]) <-
c("Odds Ratio", "Coefficient")

if (!is.null(scores)) {
coeff[[2L]][[c]] <- cbind(
coeff[[2L]][[c]],
se <- std.err$beta[[2L]][, c],
tval <- b / se,
2 * stats::pt(abs(tval), df, lower.tail = FALSE)
)
colnames(coeff[[2L]][[c]]) <-
c("Odds Ratio", "Coefficient", " Std. Error",
" t value", " Pr(>|t|)")
}
}
names(coeff[[2L]]) <- paste0("Class", 1L:(C - 1L), "/", C)
}

} else {
for (g in 1L:G) {
coeff[[g]] <- list()
for (c in 1L:(C - 1L)) {
coeff[[g]][[c]] <- data.frame(
exp(param$beta[[g]][, c]),
b <- param$beta[[g]][, c],
row.names = x.names
)
colnames(coeff[[g]][[c]]) <-
c("Odds Ratio", "Coefficient")

if (!is.null(scores)) {
coeff[[g]][[c]] <- cbind(
coeff[[g]][[c]],
se <- std.err$beta[[g]][, c],
tval <- b / se,
2 * stats::pt(abs(tval), df, lower.tail = FALSE)
)
colnames(coeff[[g]][[c]]) <-
c("Odds Ratio", "Coefficient", " Std. Error",
" t value", " Pr(>|t|)")
}
}
names(coeff[[g]]) <- paste0("Class", 1L:(C - 1L), "/", C)
}
names(coeff) <- g.names
}
} else {
coeff = NULL
}

# Posterior design
post = list()
if (W > 0L) {
Expand Down Expand Up @@ -305,7 +216,6 @@ glca_output <- function(
ret$param <- param
if (!is.null(scores))
ret$std.err <- std.err
ret$coefficient <- coeff
ret$posterior <- post
ret$gof <- gof
ret$convergence <- convergence
Expand Down
Binary file modified src/RcppExports.o
Binary file not shown.
Binary file modified src/glca.o
Binary file not shown.
Binary file modified src/glca.so
Binary file not shown.

0 comments on commit 63d3b69

Please sign in to comment.