Stan's T[lower, upper], as an object. The returned prior is the original
restricted to the box and renormalized by the mass it keeps, so its
log_prob is a proper log density rather than the original shifted by an
unknown constant. That matters here in a way it does not in Stan: the
density is compared against a learned posterior in nle()'s MCMC target and
summed with it in c2st() and the diagnostics, so a missing constant is a
wrong answer rather than a constant offset.
Details
Renormalization needs the family's CDF, so prior has to come from a named
family: prior_uniform(), prior_normal(), anything in prior_families,
or a prior_independent() built from those. A prior_custom() is arbitrary
R code with no CDF behind it; give it lower/upper there instead, which
rejects out-of-support draws without claiming to renormalize.
Examples
# A half-normal, the long way round (prior_half_normal() is the short one).
prior_truncated(prior_normal(mean = 0, sd = 1), lower = 0)
#> <nsbi_prior> type=truncated, dim=1
#> lower: 0
#> theta[1] ~ normal(0, 1) T[0, ]
# A contact rate known to be between 0.1 and 2, log-normal in between.
prior <- prior_truncated(prior_lognormal(log(0.4), 0.5),
lower = 0.1, upper = 2)
range(sample_prior(prior, 100))
#> [1] 0.1397014 1.4725125
