Skip to content

Commit 1c85b60

Browse files
committed
fix newdata error when family = mgcv::betar
fixes #406 fixes #407
1 parent 2ab134f commit 1c85b60

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

R/stanreg-methods.R

+3-2
Original file line numberDiff line numberDiff line change
@@ -267,14 +267,15 @@ ranef_template <- function(object) {
267267
new_formula <- as.formula(paste(new_formula_lhs, "~", new_formula_rhs))
268268
}
269269

270-
if (stan_fun != "stan_nlmer" && is.gaussian(object$family$family)) {
270+
if (stan_fun != "stan_nlmer" &&
271+
(is.gaussian(object$family$family) || is.beta(object$family$family))) {
271272
stan_fun <- "stan_lmer"
272273
}
273274
lme4_fun <- switch(
274275
stan_fun,
275276
"stan_lmer" = "lmer",
276277
"stan_nlmer" = "nlmer",
277-
"glmer" # for stan_glmer, stan_glmer.nb, stan_gamm4 (unless gaussian)
278+
"glmer" # for stan_glmer, stan_glmer.nb, stan_gamm4 (unless gaussian or beta)
278279
)
279280
cntrl_args <- list(optimizer = "Nelder_Mead", optCtrl = list(maxfun = 1))
280281
if (lme4_fun != "nlmer") { # nlmerControl doesn't allow these

tests/testthat/test_stan_glmer.R

+8
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,14 @@ test_that("compatible with stan_lmer with offset", {
243243
check_for_error(fit, offset = offs)
244244
})
245245

246+
test_that("predition with family mgcv::betar doesn't error", {
247+
test_data <- data.frame(y = c(0.1, 0.3), x = c(TRUE, FALSE))
248+
fit <- SW(stan_glmer(y ~ (1|x), family=mgcv::betar(link="logit"),
249+
data=test_data, seed = 101, iter = 200, chains = 1, refresh = 0))
250+
expect_silent(posterior_linpred(res, newdata=test_data))
251+
expect_silent(posterior_predict(res, newdata=test_data))
252+
})
253+
246254
# compare to lme4 ---------------------------------------------------------
247255
context("posterior_predict (compare to lme4)")
248256
test_that("posterior_predict close to predict.merMod for gaussian", {

0 commit comments

Comments
 (0)