- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我需要帮助才能在我的 WINBUGS 代码 (v. 1.4.3) 中找到错误。
在“模型规范”步骤中,模型在语法上看起来是正确的。但是,在我尝试加载数据时,出现此错误:
数组索引大于 phi3 的数组上限
有人可以帮助我吗?我的模型如下:
model {
for(w in 1: W){
m[w] <- n[w]-y1[w]
h[w] <- n[w]-y1[w]-y2[w]
y1[w] ~ dbin(delta[w],n[w])
y2[w] ~ dbin(theta[w],m[w])
y3[w] ~ dbin(eta[w],h[w])
y4[w] <- n[w]-y1[w]-y2[w]-y3[w]
logit(delta[w]) <- mu1+theta1[a[w]]+phi1[p[w]]+psi1[c[w]]
logit(theta[w]) <- mu2+theta2[a[w]]+phi2[p[w]]+psi2[c[w]]
logit(eta[w]) <- mu3+theta3[a[w]]+phi3[p[w]]+psi3[c[w]]
}
## Autoregressive prior model for p effects
phi1mean[1] <- 0.0
phi1prec[1] <- tauphi1*1.0E-6
phi1mean[2] <- 0.0
phi1prec[2] <- tauphi1*1.0E-6
phi2mean[1] <- 0.0
phi2prec[1] <- tauphi2*1.0E-6
phi2mean[2] <- 0.0
phi2prec[2] <- tauphi2*1.0E-6
phi3mean[1] <- 0.0
phi3prec[1] <- tauphi3*1.0E-6
phi3mean[2] <- 0.0
phi3prec[2] <- tauphi3*1.0E-6
phi4mean[1] <- 0.0
phi4prec[1] <- tauphi4*1.0E-6
phi4mean[2] <- 0.0
phi4prec[2] <- tauphi4*1.0E-6
for (j in 3:JJ) {
phi1mean[j] <- 2*phi1[j-1]-phi1[j-2]
phi1prec[j] <- tauphi1
phi2mean[j] <- 2*phi2[j-1]-phi2[j-2]
phi2prec[j] <- tauphi2
phi3mean[j] <- 2*phi3[j-1]-phi3[j-2]
phi3prec[j] <- tauphi3
phi4mean[j] <- 2*phi4[j-1]-phi4[j-2]
phi4prec[j] <- tauphi4
}
# Sampling p effects and subtracting mean for observed p
for (j in 1:JJ) {
phi1[j] ~ dnorm(phi1mean[j],phi1prec[j])
phi2[j] ~ dnorm(phi2mean[j],phi2prec[j])
phi3[j] ~ dnorm(phi3mean[j],phi3prec[j])
phi4[j] ~ dnorm(phi4mean[j],phi4prec[j])
phi1c[j] <- phi1[j]-mean(phi1[1:J])
phi2c[j] <- phi2[j]-mean(phi2[1:J])
phi3c[j] <- phi3[j]-mean(phi3[1:J])
phi4c[j] <- phi4[j]-mean(phi4[1:J])
}
# Hyppriors for the precision parameters
tauphi1 ~ dgamma(1.0E-1,1.0E-1)
tauphi2 ~ dgamma(1.0E-1,1.0E-1)
tauphi3 ~ dgamma(1.0E-1,1.0E-1)
tauphi4 ~ dgamma(1.0E-1,1.0E-1)
sigmaphi1 <- 1/sqrt(tauphi1)
sigmaphi2 <- 1/sqrt(tauphi2)
sigmaphi3 <- 1/sqrt(tauphi3)
sigmaphi4 <- 1/sqrt(tauphi4)
## Autoregressive prior model for c effects
psi1mean[1] <- 0.0
psi1prec[1] <- taupsi1*1.0E-6
psi1mean[2] <- 0.0
psi1prec[2] <- taupsi1*1.0E-6
psi2mean[1] <- 0.0
psi2prec[1] <- taupsi2*1.0E-6
psi2mean[2] <- 0.0
psi2prec[2] <- taupsi2*1.0E-6
psi3mean[1] <- 0.0
psi3prec[1] <- taupsi3*1.0E-6
psi3mean[2] <- 0.0
psi3prec[2] <- taupsi3*1.0E-6
psi4mean[1] <- 0.0
psi4prec[1] <- taupsi4*1.0E-6
psi4mean[2] <- 0.0
psi4prec[2] <- taupsi4*1.0E-6
for (l in 3:LL) {
psi1mean[l] <- 2*psi1[l-1]-psi1[l-2]
psi1prec[l] <- taupsi1
psi2mean[l] <- 2*psi2[l-1]-psi2[l-2]
psi2prec[l] <- taupsi2
psi3mean[l] <- 2*psi3[l-1]-psi3[l-2]
psi3prec[l] <- taupsi3
psi4mean[l] <- 2*psi4[l-1]-psi4[l-2]
psi4prec[l] <- taupsi4
}
# Sampling c effects and subtracting mean for observed c
for (l in 1:LL) {
psi1[l] ~ dnorm(psi1mean[l],psi1prec[l])
psi2[l] ~ dnorm(psi2mean[l],psi2prec[l])
psi3[l] ~ dnorm(psi3mean[l],psi3prec[l])
psi4[l] ~ dnorm(psi4mean[l],psi4prec[l])
psi1c[l] <- psi1[l]-mean(psi1[1:L])
psi2c[l] <- psi2[l]-mean(psi2[1:L])
psi3c[l] <- psi3[l]-mean(psi3[1:L])
psi4c[l] <- psi4[l]-mean(psi4[1:L])
}
# Hyppriors for the precision parameters
taupsi1 ~ dgamma(1.0E-1,1.0E-1)
taupsi2 ~ dgamma(1.0E-1,1.0E-1)
taupsi3 ~ dgamma(1.0E-1,1.0E-1)
taupsi4 ~ dgamma(1.0E-1,1.0E-1)
sigmapsi1 <- 1/sqrt(taupsi1)
sigmapsi2 <- 1/sqrt(taupsi2)
sigmapsi3 <- 1/sqrt(taupsi3)
sigmapsi4 <- 1/sqrt(taupsi4)
## Autoregressive prior model for a effects
theta1mean[1] <- 0.0
theta1prec[1] <- tautheta1*1.0E-6
theta1mean[2] <- 0.0
theta1prec[2] <- tautheta1*1.0E-6
theta2mean[1] <- 0.0
theta2prec[1] <- tautheta2*1.0E-6
theta2mean[2] <- 0.0
theta2prec[2] <- tautheta2*1.0E-6
theta3mean[1] <- 0.0
theta3prec[1] <- tautheta3*1.0E-6
theta3mean[2] <- 0.0
theta3prec[2] <- tautheta3*1.0E-6
theta4mean[1] <- 0.0
theta4prec[1] <- tautheta4*1.0E-6
theta4mean[2] <- 0.0
theta4prec[2] <- tautheta4*1.0E-6
for (i in 3:I) {
theta1mean[i] <- 2*theta1[i-1]-theta1[i-2]
theta1prec[i] <- tautheta1
theta2mean[i] <- 2*theta2[i-1]-theta2[i-2]
theta2prec[i] <- tautheta2
theta3mean[i] <- 2*theta3[i-1]-theta3[i-2]
theta3prec[i] <- tautheta3
theta4mean[i] <- 2*theta4[i-1]-theta4[i-2]
theta4prec[i] <- tautheta4
}
# Sampling a effects
for (i in 1:I) {
theta1[i] ~ dnorm(theta1mean[i],theta1prec[i])
theta2[i] ~ dnorm(theta2mean[i],theta2prec[i])
theta3[i] ~ dnorm(theta3mean[i],theta3prec[i])
theta4[i] ~ dnorm(theta4mean[i],theta4prec[i])
}
# Hyppriors for the precision parameters
tautheta1 ~ dgamma(1.0E-1,1.0E-1)
tautheta2 ~ dgamma(1.0E-1,1.0E-1)
tautheta3 ~ dgamma(1.0E-1,1.0E-1)
tautheta4 ~ dgamma(1.0E-1,1.0E-1)
sigmatheta1 <- 1/sqrt(tautheta1)
sigmatheta2 <- 1/sqrt(tautheta2)
sigmatheta3 <- 1/sqrt(tautheta3)
sigmatheta4 <- 1/sqrt(tautheta4)
# Removing linear trends from a
for (i in 1:I) {
ivec1[i] <- i-(I+1)/2
aivec1[i] <- ivec1[i]*theta1[i]
theta1c[i] <- theta1[i]-ivec1[i]*sum(aivec1[])/(I*(I+1)*(I-1)/12)
ivec2[i] <- i-(I+1)/2
aivec2[i] <- ivec2[i]*theta2[i]
theta2c[i] <- theta2[i]-ivec2[i]*sum(aivec2[])/(I*(I+1)*(I-1)/12)
ivec3[i] <- i-(I+1)/2
aivec3[i] <- ivec3[i]*theta3[i]
theta3c[i] <- theta3[i]-ivec3[i]*sum(aivec3[])/(I*(I+1)*(I-1)/12)
ivec4[i] <- i-(I+1)/2
aivec4[i] <- ivec4[i]*theta4[i]
theta4c[i] <- theta4[i]-ivec4[i]*sum(aivec4[])/(I*(I+1)*(I-1)/12)
}
## Computing fitted and projected probabilities
for (i in 1:I) {
for (j in 1:JJ) {
deltapred[i,j] <- exp(mu1+theta1[i]+phi1[j]+psi1[I+j-i])
thetapred[i,j] <- exp(mu2+theta2[i]+phi2[j]+psi2[I+j-i])
etapred[i,j] <- exp(mu3+theta3[i]+phi3[j]+psi3[I+j-i])
p1[i,j] <- deltapred[i,j]
p2[i,j] <- thetapred[i,j]*(1-deltapred[i,j])
p3[i,j] <- etapred[i,j]*(1-deltapred[i,j])*(1-thetapred[i,j])
p4[i,j] <- (1-deltapred[i,j])*(1-thetapred[i,j]-etapred[i,j]+(etapred[i,j]*thetapred[i,j]))
}
}
}
### Data
list(
y1=c(1538727,1444672,1206999,1002960,744597,390301,1640130,1472255,1383947,1109395,984775,697701,1769569,1573498,1489025,1351284,1111397,935166,1747764,1790841,1626852,1407388,1284583,995236,1676555,1787181,1655400,1527122,1421772,1309989,1561922,1643467,1598855,1570645,1495999,1319439,1456258,1561892,1567872,1555237,1551579,1532222,1243436,1387943,1436659,1511134,1549578,1539580),
y2=c(2634569,3031916,3138776,2875868,2495888,1886174,2148776,2567507,2747428,2696199,2593985,2138303,1662296,2224336,2489723,2698322,2655746,2450716,1304387,1734318,2180203,2396749,2629088,2555934,1087351,1380119,1616309,2109287,2408800,2369855,821642,1041702,1221283,1661647,2098345,2426842,708327,873092,952245,1237084,1628334,2123709,549763,666699,774205,981393,1243888,1538431),
y3=c(1245931,1664176,1659375,2313647,3850196,4254634,825634,1293382,1454776,1736181,2596719,3655532,554953,901957,1186747,1490664,2083400,2738988,335824,630232,847486,1239538,1702256,2296941,218213,373786,555286,907876,1397221,2005940,143202,237344,344229,594993,1012777,1510283,121187,151070,219731,351040,650930,1157146,87211,120279,140551,226530,393887,733699),
n=c(5862309,6673625,6534802,6942747,8329067,8152696,5049199,5913474,6268113,6253757,7298375,8260640,4319559,5245545,5840408,6306245,6785242,7492958,3588778,4553684,5259609,5813653,6517271,7001560,3105173,3797508,4271831,5180290,6086716,7002991,2591140,3063506,3428373,4305319,5326889,6217360,2329398,2661972,2886111,3418403,4327922,5565798,1906676,2224544,2444586,2864892,3473404,4362648),
a=c(1,1,1,1,1,1,2,2,2,2,2,2,3,3,3,3,3,3,4,4,4,4,4,4,5,5,5,5,5,5,6,6,6,6,6,6,7,7,7,7,7,7,8,8,8,8,8,8),
p=c(9,10,11,12,13,14,9,10,11,12,13,14,9,10,11,12,13,14,9,10,11,12,13,14,9,10,11,12,13,14,9,10,11,12,13,14,9,10,11,12,13,14,9,10,11,12,13,14),
c=c(8,9,10,11,12,13,7,8,9,10,11,12,6,7,8,9,10,11,5,6,7,8,9,10,4,5,6,7,8,9,3,4,5,6,7,8,2,3,4,5,6,7,1,2,3,4,5,6),
W=48,
I=8,
J=6,
JJ=8,
L=13,
LL=15
)
# Inits
list(
tauphi1=1,
tauphi2=1,
tauphi3=1,
tauphi4=1,
taupsi1=1,
taupsi2=1,
taupsi3=1,
taupsi4=1,
tautheta1=1,
tautheta2=1,
tautheta3=1,
tautheta4=1,
theta1=c(0,0,0,0,0,0,0,0),
theta2=c(0,0,0,0,0,0,0,0),
theta3=c(0,0,0,0,0,0,0,0),
theta4=c(0,0,0,0,0,0,0,0),
phi1=c(0,0,0,0,0,0),
phi2=c(0,0,0,0,0,0),
phi3=c(0,0,0,0,0,0),
phi4=c(0,0,0,0,0,0),
psi1=c(0,0,0,0,0,0,0,0,0,0,0,0,0),
psi2=c(0,0,0,0,0,0,0,0,0,0,0,0,0),
psi3=c(0,0,0,0,0,0,0,0,0,0,0,0,0),
psi4=c(0,0,0,0,0,0,0,0,0,0,0,0,0)
)
最佳答案
在 logit(eta[w]) 的定义中,您使用了 phi3[p[w]],而 p[w] 的值从 9 到 14。但 phi3[j] 的定义仅针对 j = 1 到 JJ =8。因此“数组索引(9 到 14)大于数组上限(8)”
关于WINBugs:数组索引大于数组上限,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16430741/
我有一些简单的时间事件数据,没有协变量。我试图将 Weibull 分布拟合到它。所以我有以下代码。在我加载姓名首字母之前,一切看起来都很好。它说“这个链包含未初始化的变量”。但我不明白。我认为 Wei
我需要帮助才能在我的 WINBUGS 代码 (v. 1.4.3) 中找到错误。 在“模型规范”步骤中,模型在语法上看起来是正确的。但是,在我尝试加载数据时,出现此错误: 数组索引大于 phi3 的数组
我在 winbugs 中对这段代码有一些问题。该模型在本质上是正确的并且数据已加载,但是当我编译时,软件输出是“节点 Z 的多重定义”。我不知道如何解决问题。 这是模型: #BUGS Model mo
当我为带有附加模型的 3 个链加载初始化时,我得到“此链包含未初始化的变量”。我点击“gen init”继续。这是正确的做法吗?它不会发生在固定模型上,但往往会发生在随机模型上。请指教。 #BUGS
我有一个输入需求模型,数据不平衡。因变量为yijt,其中i表示生产函数(i=1,2,3)的输入,j code>表示公司(j=1,..,21),t表示时间(ti=1,..,Ti) .那么,由于面板是不平
我正在尝试使用 BUGS 编写狄利克雷多项式模型。 基本上我有 18 个区域和每个区域 3 个类别。例如, 区域 1:0.50 属于低,0.30 属于中,0.20 属于高。列表当然以不同的比例继续到区
首先,有人知道 WinBUGS 的开发人员指南吗?该网站充满了涂鸦的详细示例和模型语言的文档,但我还没有找到任何关于如何解释陷阱窗口的信息。 其次,有没有人找到任何方法来简化检查/加载/编译/初始化/
我正在使用 Kruschke 描述的分层建模框架在 JAGS 中建立两个模型之间的比较。该框架的想法是通过将每个版本指定为分类变量的一个级别来运行和比较模型的多个版本。该分类变量的后验分布可以解释为各
我有一个 OpenBUGS 模型,它使用随着时间的推移 (x.values) 观察到的数据 (y.values) 来模拟多次运行 (~100000),并对每次运行的 y 值 (y.est) 进行新的估
我用过 Winbugs来自 R通过 R2WinBUGS和 BRugs包,我写了模型,尝试运行,结果没出来,看了WinBUGS日志,似乎没有出错。 这是模型: require(BRugs) requir
我目前正在对多项临床试验的生存数据进行荟萃分析。 为此,我使用相同的方法从已发布的分析中获取代码。但是,当使用来自已发布分析的数据运行此代码时,我无法复制他们的结果。事实上,结果无法收敛到任何一种合理
我有一个与称为 BUGS 的 R 代码相关的问题。我已经在 WinBUGS 中运行了模型,它运行良好,给了我预期的结果。下面是当我有 Y 的单一结果或单变量数据时使用的自动化代码。现在我想将它用于多种
我是 WinBUGS 的新手,无法使用下面的代码。型号为syntactically correct (它是具有随机效应的分层 logit 模型),但是当我单击 load data 时出现的错误信息是
我是统计分析领域的新手,最近对 BUGS/JAGS/STAN 建模语言产生了兴趣。真正令我惊讶的是,我没有看到任何定义新函数或发行版以避免代码重复的示例。例如,假设我经常使用泊松分布的平方,是否可以执
我使用 R 中的 R2WinBUGS 包在 WinBUGS 中运行了一次漫长的计算(百万次迭代): bugs.object <- bugs(...) 但是 R 崩溃了。 如何在不再次运行 winbug
正如这篇文章的标题所说,当我尝试使用 BRugsFit (使用 coda=T)从 R 运行在 WinBUGS 中正常工作的代码和数据时,我得到这些错误: Error in glm.fit(x = st
我正在尝试在 JAGS 中实现为 WinBUGS 编写的以下模型: model { for (i in 1:N) { wtp[i] ~ dw
我有一个关于在 JAGS 和 BUGS 中运行模型的细节的快速问题。 假设我使用 n.burnin=5000、n.iter=5000 和 thin=2 运行模型。这是否意味着该程序将: 运行 5,00
我是一名优秀的程序员,十分优秀!