我是一个非常新的统计分析世界,并且最近对BUGS/JAGS/STAN建模语言感兴趣.令我感到惊讶的是,我没有看到任何新函数或发行版的示例被定义以避免代码重复.例如,假设我经常使用泊松分布的平方,无论如何都要做以下事情?
dsqpo <- function(lambda) {
tmp ~ dpois(lambda)
tmp2 <- tmp * tmp
return(tmp2)
}
Run Code Online (Sandbox Code Playgroud)
然后是
model{
...
x ~ dsqpo(alpha)
y ~ dsqpo(beta)
}
Run Code Online (Sandbox Code Playgroud)
无需每次都定义新的临时变量.
小智 2
对于 Stan,功能将在下一个版本中提供。当前版本 v2.2.0 没有将用户定义函数作为该语言的一部分。
有关建议的语法,请参阅:https ://github.com/stan-dev/stan/wiki/Function-Syntax-and-Semantics-Design
有关 Stan 的其他帮助,请查看 stan-users google 群组:https://groups.google.com/forum/#! forum/stan-users