Permalink
Browse files

fix lower truncation bound in discrete models

  • Loading branch information...
paul-buerkner committed Feb 9, 2019
1 parent 773a914 commit 966947e8b2573bd0014213fec4af58f7f70e0997
Showing with 3 additions and 2 deletions.
  1. +2 −1 R/stan-likelihood.R
  2. +1 −1 tests/testthat/tests.make_stancode.R
@@ -194,7 +194,8 @@ stan_llh_trunc <- function(llh, bterms, data, resp = "", short = FALSE) {
if (!any(bounds$lb > -Inf | bounds$ub < Inf)) {
return("")
}
lb <- str_if(any(bounds$lb > -Inf), glue("lb{resp}[n]"))
m1 <- str_if(use_int(bterms), " - 1")
lb <- str_if(any(bounds$lb > -Inf), glue("lb{resp}[n]{m1}"))
ub <- str_if(any(bounds$ub < Inf), glue("ub{resp}[n]"))
if (short) {
# truncation using T[, ] syntax
@@ -284,7 +284,7 @@ test_that("truncation appears in the Stan code", {
data = epilepsy, family = "poisson")
expect_match2(scode, "target += poisson_lpmf(Y[n] | mu[n]) -")
expect_match2(scode,
"log_diff_exp(poisson_lcdf(ub[n] | mu[n]), poisson_lcdf(lb[n] | mu[n]));"
"log_diff_exp(poisson_lcdf(ub[n] | mu[n]), poisson_lcdf(lb[n] - 1 | mu[n]));"
)
})

0 comments on commit 966947e

Please sign in to comment.