gpt4 book ai didi

bayesian - 狄利克雷多项式 WinBUGS 代码

转载 作者:行者123 更新时间:2023-12-05 01:03:42 25 4
gpt4 key购买 nike

我正在尝试使用 BUGS 编写狄利克雷多项式模型。
基本上我有 18 个区域和每个区域 3 个类别。例如,
区域 1:0.50 属于低,0.30 属于中,0.20 属于高。列表当然以不同的比例继续到区域 18。我得到的唯一代码是这个

`model  {
for (i in 1:N) {
x[1:3] ~ dmulti(p[],n[i])
p[1:3] ~ ddirch(alpha[])
}
for (k in 1:3) {
alpha[k] <- 1
}
}
DATA list(n=c(38483, 2259, 1900),x=c(29256.42719, 1857.431404, 1548.007808, 29256.42719, 1857.431404, 1548.007808, 29256.42719, 1857.431404, 1548.007808), N=3)`

例如,我首先将其缩短为 3 个区域。单击“gen inits”后,它会显示“Dirichlet36”。请帮我编码这个。

最佳答案

这可能会有所帮助( source ):

Learning about the parameters of a Dirichlet distribution

Suppose as part of a model there are J probability arrays p[j, 1:K], j = 1, ..., J, where K is the dimension of each array and sum(p[j, 1:K]) = 1 for all j. We give each of them a Dirichlet prior:

      p[j, 1:K] ~ ddirch(alpha[])

and we would like to learn about alpha[]. However, the parameters alpha[] of a Dirichlet distribution cannot be stochastic nodes. The trick is to note that if delta[k] ~ dgamma(alpha[k], 1), then the vector with elements delta[k] / sum(delta[1:K]), k = 1, ..., K, is Dirichlet with parameters alpha[k], k = 1, ..., K. So the following construction should allow learning about the parameters alpha[]:

      for (k in 1:K) {
p[j, k] <- delta[j, k] / sum(delta[j,])
delta[j, k] ~ dgamma(alpha[k], 1)
}

A prior can be put directly on the alpha[k]'s.

关于bayesian - 狄利克雷多项式 WinBUGS 代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24349692/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com