Skip to content

Commit

Permalink
lintr
Browse files Browse the repository at this point in the history
  • Loading branch information
strengejacke committed Oct 7, 2024
1 parent efc2eb4 commit 5a34f32
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions tests/testthat/test-GLMMadaptive.R
Original file line number Diff line number Diff line change
Expand Up @@ -387,29 +387,29 @@ test_that("detect custom families", {
hurdle.lognormal <- function() {
stats <- make.link("identity")
log_dens <- function(y, eta, mu_fun, phis, eta_zi) {
sigma <- exp(phis)
scaleParameter <- exp(phis)
# binary indicator for y > 0
ind <- y > 0
# non-zero part
eta <- as.matrix(eta)
eta_zi <- as.matrix(eta_zi)
out <- eta
out[ind, ] <- plogis(eta_zi[ind, ], lower.tail = FALSE, log.p = TRUE) +
dnorm(x = log(y[ind]), mean = eta[ind, ], sd = sigma, log = TRUE)
dnorm(x = log(y[ind]), mean = eta[ind, ], sd = scaleParameter, log = TRUE)
# zero part
out[!ind, ] <- plogis(eta_zi[!ind, ], log.p = TRUE)
attr(out, "mu_y") <- eta
out
}
score_eta_fun <- function(y, mu, phis, eta_zi) {
sigma <- exp(phis)
scaleParameter <- exp(phis)
# binary indicator for y > 0
ind <- y > 0
# non-zero part
eta <- as.matrix(mu)
out <- eta
out[!ind, ] <- 0
out[ind, ] <- (log(y[ind]) - eta[ind, ]) / sigma^2
out[ind, ] <- (log(y[ind]) - eta[ind, ]) / scaleParameter^2
out
}
score_eta_zi_fun <- function(y, mu, phis, eta_zi) {
Expand All @@ -420,17 +420,17 @@ test_that("detect custom families", {
out
}
score_phis_fun <- function(y, mu, phis, eta_zi) {
sigma <- exp(phis)
scaleParameter <- exp(phis)
# binary indicator for y > 0
ind <- y > 0
# non-zero part
eta <- as.matrix(mu)
out <- eta
out[!ind, ] <- 0
out[ind, ] <- -1 + (log(y[ind]) - eta[ind, ])^2 / sigma^2
out[ind, ] <- -1 + (log(y[ind]) - eta[ind, ])^2 / scaleParameter^2
out
}
simulate <- function(n, mu, phis, eta_zi) {
simulateResponses <- function(n, mu, phis, eta_zi) {
y <- rlnorm(n = n, meanlog = mu, sdlog = exp(phis))
y[as.logical(rbinom(n, 1, plogis(eta_zi)))] <- 0
y
Expand All @@ -440,7 +440,7 @@ test_that("detect custom families", {
family = "two-part log-normal", link = stats$name,
linkfun = stats$linkfun, linkinv = stats$linkinv, log_dens = log_dens,
score_eta_fun = score_eta_fun, score_eta_zi_fun = score_eta_zi_fun,
score_phis_fun = score_phis_fun, simulate = simulate
score_phis_fun = score_phis_fun, simulate = simulateResponses
),
class = "family"
)
Expand Down

0 comments on commit 5a34f32

Please sign in to comment.