Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
drizopoulos committed Mar 21, 2024
1 parent 619d511 commit de00779
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 16 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
Package: GLMMadaptive
Title: Generalized Linear Mixed Models using Adaptive Gaussian Quadrature
Version: 0.9-2
Version: 0.9-3
Authors@R: person("Dimitris", "Rizopoulos", email = "d.rizopoulos@erasmusmc.nl",
role = c("aut", "cre"), comment = c(ORCID = '0000-0001-9397-0900'))
Date: 2024-01-16
Date: 2024-03-21
Maintainer: Dimitris Rizopoulos <d.rizopoulos@erasmusmc.nl>
BugReports: https://github.com/drizopoulos/GLMMadaptive/issues
Description: Fits generalized linear mixed models for a single grouping factor under
Expand Down
12 changes: 7 additions & 5 deletions R/Functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -584,15 +584,17 @@ cr_marg_probs <- function (eta, direction = c("forward", "backward")) {
direction <- match.arg(direction)
ncoefs <- ncol(eta)
if (direction == "forward") {
cumsum_1_minus_p <- t(apply(plogis(eta[, -ncoefs], log.p = TRUE,
lower.tail = FALSE), 1, cumsum))
cumsum_1_minus_p <- apply(plogis(eta[, -ncoefs, drop = FALSE], log.p = TRUE,
lower.tail = FALSE), 1L, cumsum)
if (is.matrix(cumsum_1_minus_p)) cumsum_1_minus_p <- t(cumsum_1_minus_p)
probs <- exp(plogis(eta, log.p = TRUE) + cbind(0, cumsum_1_minus_p))
cbind(probs, 1 - rowSums(probs))
} else {
cumsum_1_minus_p <- t(apply(plogis(eta[, seq(ncoefs, 2)], log.p = TRUE,
lower.tail = FALSE), 1, cumsum))
cumsum_1_minus_p <- apply(plogis(eta[, seq(ncoefs, 2), drop = FALSE], log.p = TRUE,
lower.tail = FALSE), 1L, cumsum)
if (is.matrix(cumsum_1_minus_p)) cumsum_1_minus_p <- t(cumsum_1_minus_p)
probs <- exp(plogis(eta, log.p = TRUE) +
cbind(cumsum_1_minus_p[, seq(ncoefs - 1, 1)], 0))
cbind(1 - rowSums(probs), probs)
}
}
}
15 changes: 8 additions & 7 deletions R/methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ marginal_coefs.MixMod <- function (object, std_errors = FALSE, link_fun = NULL,
compute_marg_coefs <- function (object, X, betas, Z, X_zi, gammas, Z_zi, D, M,
link_fun, seed) {
if (!exists(".Random.seed", envir = .GlobalEnv))
runif(1)
runif(1L)
RNGstate <- get(".Random.seed", envir = .GlobalEnv)
on.exit(assign(".Random.seed", RNGstate, envir = .GlobalEnv))
mu_fun <- object$Funs$mu_fun
Expand All @@ -549,12 +549,12 @@ marginal_coefs.MixMod <- function (object, std_errors = FALSE, link_fun = NULL,
}
Xbetas <- c(X %*% betas)
if (!is.null(offset)) {
Xbetas <- Xbetas #+ offset
Xbetas <- Xbetas + offset
}
if (!is.null(gammas)) {
eta_zi <- c(X_zi %*% gammas)
if (!is.null(offset_zi)) {
eta_zi <- eta_zi #+ offset_zi
eta_zi <- eta_zi + offset_zi
}
}
id <- match(object$id[[1]], unique(object$id[[1]]))
Expand Down Expand Up @@ -605,7 +605,7 @@ marginal_coefs.MixMod <- function (object, std_errors = FALSE, link_fun = NULL,
Z_zi, M, compute_marg_coefs, chol_transf,
object, link_fun, seed) {
if (!exists(".Random.seed", envir = .GlobalEnv))
runif(1)
runif(1L)
RNGstate <- get(".Random.seed", envir = .GlobalEnv)
on.exit(assign(".Random.seed", RNGstate, envir = .GlobalEnv))
n_block <- length(block)
Expand Down Expand Up @@ -687,7 +687,7 @@ effectPlotData.MixMod <- function (object, newdata, level = 0.95, marginal = FAL
X <- model.matrix(termsX, mfX)
if (is.null(object$gammas)) {
if (marginal) {
mcoefs <- marginal_coefs(object, std_errors = TRUE, ...)
mcoefs <- marginal_coefs(object, std_errors = TRUE, seed = seed, ...)
betas <- mcoefs$betas
var_betas <- mcoefs$var_betas
} else {
Expand All @@ -702,7 +702,7 @@ effectPlotData.MixMod <- function (object, newdata, level = 0.95, marginal = FAL
newdata$upp <- pred + qnorm((1 + level) / 2) * ses
} else {
if (!exists(".Random.seed", envir = .GlobalEnv, inherits = FALSE))
runif(1)
runif(1L)
R.seed <- get(".Random.seed", envir = .GlobalEnv)
set.seed(seed)
RNGstate <- structure(seed, kind = as.list(RNGkind()))
Expand Down Expand Up @@ -752,7 +752,8 @@ effectPlotData.MixMod <- function (object, newdata, level = 0.95, marginal = FAL
V <- V[ind, ind, drop = FALSE]
new_tht <- MASS::mvrnorm(K, tht, V)
if (marginal) {
mcoefs <- marginal_coefs(object, std_errors = TRUE, ...)
mcoefs <- marginal_coefs(object, std_errors = TRUE, seed = seed,
...)
betas <- mcoefs$betas
var_betas <- mcoefs$var_betas
pred <- c(X %*% betas)
Expand Down
4 changes: 2 additions & 2 deletions man/GLMMadaptive.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ Gaussian quadrature rule.
\tabular{ll}{
Package: \tab GLMMadaptive\cr
Type: \tab Package\cr
Version: \tab 0.9-2\cr
Date: \tab 2024-01-16\cr
Version: \tab 0.9-3\cr
Date: \tab 2024-03-21\cr
License: \tab GPL (>=3)\cr
}

Expand Down

0 comments on commit de00779

Please sign in to comment.