I am very new statistical analysis world and have taken a recent interest in the BUGS/JAGS/STAN modelling language. Something which really surprises me is that I haven't seen any examples of new functions or distributions being defined to avoid code duplication. For example, say I frequently use the square of the poisson distribution, is there anyway to do the following ?
dsqpo <- function(lambda) {
tmp ~ dpois(lambda)
tmp2 <- tmp * tmp
return(tmp2)
}
and then later on
model{
...
x ~ dsqpo(alpha)
y ~ dsqpo(beta)
}
Without defining a new temporary variable each time.