%~% {RTMB} | R Documentation |
Distributional assignment operator
Description
Distributional assignment operator
Usage
x %~% distr
Arguments
x |
LHS; Random effect or data for which distribution assignment applies |
distr |
RHS; Distribution expression |
Details
Provides a slightly simplified syntax inspired by, but not compatible with, other probabilistic programming languages (e.g. BUGS/JAGS):
-
x %~% distribution(...)
is syntactic sugar for.nll <- .nll - sum(distribution(x,...,log=TRUE))
The variable
.nll
is automatically initialized to0
and returned on exit.
Value
The updated value of the hidden variable .nll
.
Note
If the shorter name ~
is preferred, it can be locally overloaded using "~" <- RTMB::"%~%"
.
Examples
f <- function(parms) {
getAll(parms)
x %~% dnorm(mu, 1)
y %~% dpois(exp(x))
}
p <- list(mu=0, x=numeric(10))
y <- 1:10
obj <- MakeADFun(f, p, random="x")
[Package RTMB version 1.5 Index]