Keith, thanks for sending the question.
Are you looking for a truncated univariate normal distribution, or some version of a multivariate normal distribution, which is what's implied when you mention "rmnorm_chol". If you're looking at dmnorm(), and you do mean a truncated *multivariate* normal, then we'd have to pinpoint more specifically what you mean, about a truncated version of a multivariate normal distribution.
On the other hand, if you mean a truncated (1-dimensional) univariate normal distribution, then you have the following options. Let's say you're interested in generating a truncated version of a standard normal (mean=0, sd=1) distribution. And say you want to truncate it between the two values "lower" and "upper".
Inside a nimble model object is easier. This syntax is supported in nimble model code:
code <- nimbleCode({
x ~ T(dnorm(0, 1), lower, upper)
...
})
In a nimbleFunction, as you asked, isn't quite as straightforward. The T() syntax for truncation isn't supported inside a nimbleFunction. You could work around this without too much trouble, however, using a draw from a uniform distribution, and the standard normal CDF function, as:
my_nf <- nimbleFunction(
run = function() {
u_lower <- pnorm(lower, 0, 1)
u_upper <- pnorm(upper, 0, 1)
u <- runif(1, u_lower, u_upper)
x <- qnorm(u, 0, 1)
returnType(double())
return(x)
}
)
If you fill in the values of "lower" and "upper" in that code above, then that should accomplish what you want: generating "x" as a draw from a truncated standard normal distribution.
Hope this helps,
Daniel