Skip to content

Commit

Permalink
correct dummy response values for simulate_new
Browse files Browse the repository at this point in the history
  • Loading branch information
bbolker committed Mar 24, 2024
1 parent f94ee66 commit b701b2f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
6 changes: 4 additions & 2 deletions glmmTMB/R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -654,8 +654,10 @@ simulate_new <- function(object,
form <- object
form[[3]] <- form[[2]]
form[[2]] <- quote(..y)
## insert a legal value: 1.0 is OK as long as family != "beta_family"
newdata[["..y"]] <- if (family$family == "beta_family") 0.5 else 1.0
## insert a legal value: 1.0 is OK as long as family != "beta"
## (note the family *function* is 'beta_family' but the internal
## $family value is 'beta')
newdata[["..y"]] <- if (family$family == "beta") 0.5 else 1.0
r1 <- glmmTMB(form,
data = newdata,
family = family,
Expand Down
10 changes: 9 additions & 1 deletion glmmTMB/inst/NEWS.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,15 @@
\title{glmmTMB News}
\encoding{UTF-8}

\section{CHANGES IN VERSION 1.1.9}{
\section{CHANGES IN VERSION 1.1.9-9000}{
\subsection{BUG FIXES}{
\itemize{
\item fixed bug in \code{simulate_new} for \code{family = "beta_family")
}
} % bug fixes
} % 1.1.9-9000

\section{CHANGES IN VERSION 1.1.9 (2024-03-20)}{
\subsection{USER-VISIBLE CHANGES}{
\itemize{
\item the underlying parameterization of the dispersion for
Expand Down
13 changes: 13 additions & 0 deletions glmmTMB/tests/testthat/test-methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,19 @@ test_that("de novo simulation error checking", {
"unmatched parameter names: junk")
})

test_that("good simulate_new response values for beta", {
data("sleepstudy", package = "lme4")
ss <- simulate_new(
~ Days + (Days | Subject),
newdata = sleepstudy,
newparams = list(beta = c(-1, 0.1),
theta = c(-1, -1, 0),
betad = 10),
family = "beta_family",
seed = 101)
expect_equal(head(ss[[1]], 3),
c(0.246573218210702, 0.309824346705961, 0.367484246522732))
})

test_that("weighted residuals", {
set.seed(101)
Expand Down

0 comments on commit b701b2f

Please sign in to comment.