正常 CAR u[22] 的邻接矩阵必须是对称的 - WINBUGS
Adjacency matrix of normal CAR u[22] must be symmetric - WINBUGS
我正在尝试为我的空间数据建立一个卷积模型,但它一直给我一个错误,提示“法线 CAR u[22] 的邻接矩阵必须是对称的”。谁能给我一个想法,我做错了什么?我认为问题与没有任何邻居的obs 42有关。
model
{
for (i in 1:N){
# Poisson likelihood for observed counts
O[i] ~ dpois(mu[i])
log(mu[i]) <- log(E[i]) + alpha + u[i] + v[i]
RR[i] <- exp(alpha + u[i] + v[i])
v[i] ~ dnorm(0, tau.v)
}
# CAR prior distribution for random effects:
u[1:N] ~ car.normal(adj[], weights[], num[], tau.u)
for(k in 1:sumNumNeigh){
weights[k] <- 1
}
# Other priors
alpha ~ dflat()
mean <- exp(alpha)
tau.u ~ dgamma(0.5, 0.0005)
tau.v ~ dgamma(0.5, 0.0005)
sigma.u <- 1/tau.u
sigma.v <- 1/tau.v
ratio <- sigma.u/sigma.v
}
# Data
list(E = c(
309.644702, 1743.709601, 711.804186, 2526.881056, 318.644541, 375.876925,
3078.079354, 479.665537, 611.054281, 578.794301, 263.825542, 443.047869,
1563.163287, 706.636964, 800.620723, 271.043082, 414.554323, 1276.548784,
499.220755, 625.658895, 455.259480, 1293.033647, 970.491142, 636.352367,
636.352367, 614.983914, 560.249202, 468.749744, 1136.010294, 443.047869,
766.793038, 443.221218, 1237.341543, 418.018262, 275.975567, 3.160066,
369.597694, 314.777270, 990.528173, 645.661892, 1205.130767, 278.188792,
1449.545851, 159.055131),
O = c(
345, 1325, 845, 2815, 705, 400, 3150, 485, 325, 405, 585, 410, 3555, 320, 1030, 310,
305,1185, 300, 710, 225, 600, 800, 335, 220, 385, 310, 165, 1190, 175, 840, 1075,
1155, 600, 225, 5, 400, 200, 1155, 850, 1215, 300, 1275, 160),
N = 44,
num = c(
2, 5, 3, 4, 6, 6, 3, 4, 6, 3,
6, 3, 6, 7, 8, 2, 3, 5, 5, 5,
6, 9, 4, 4, 2, 9, 5, 4, 5, 4,
7, 4, 5, 5, 7, 6, 5, 5, 4, 7,
4, 0, 2, 1),
adj = c(
5, 2,
6, 5, 4, 3, 1,
9, 4, 2,
9, 6, 3, 2,
11, 8, 7, 6, 2, 1,
15, 11, 9, 5, 4, 2,
13, 8, 5,
13, 11, 7, 5,
15, 14, 10, 6, 4, 3,
14, 12, 9,
19, 15, 13, 8, 6, 5,
16, 14, 10,
21, 19, 17, 11, 8, 7,
20, 18, 16, 15, 12, 10, 9,
24, 22, 19, 18, 14, 11, 9, 6,
14, 12,
23, 21, 13,
26, 24, 20, 15, 14,
22, 21, 15, 13, 11,
28, 26, 25, 18, 14,
27, 23, 22, 19, 17, 13,
31, 29, 27, 26, 24, 23, 21, 19, 15,
30, 27, 21, 17,
26, 22, 18, 15,
28, 20,
35, 33, 32, 29, 28, 24, 22, 20, 18,
31, 30, 23, 22, 21,
32, 26, 25, 20,
35, 34, 31, 26, 22,
39, 31, 27, 23,
40, 39, 34, 30, 29, 27, 22,
36, 33, 28, 26,
37, 36, 35, 32, 26,
40, 39, 35, 31, 29,
40, 38, 37, 34, 33, 29, 26,
43, 41, 38, 37, 33, 32,
38, 36, 35, 33, 26,
41, 40, 37, 36, 35,
40, 34, 31, 30,
44, 41, 39, 38, 35, 34, 31,
43, 40, 38, 36
,
41, 36,
40
),
sumNumNeigh = 206))
# initial value
list(alpha = 0.01, tau.v = 0.01, tau.u = 0.01, u = c(
0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01,
0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01,
0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01,
0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01
),
v = c(
0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01,
0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01,
0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01,
0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01,0.01
))
感谢您的宝贵时间!非常感谢。
u[22] 表示区域 22 有一个邻居,在 return 中没有区域 22 作为它自己的邻居,因此创建了一个非对称邻接矩阵。除了使用 winbugs 中的 'adjacency map' 工具手动检查之外,我不知道还有什么其他方法。
我正在尝试为我的空间数据建立一个卷积模型,但它一直给我一个错误,提示“法线 CAR u[22] 的邻接矩阵必须是对称的”。谁能给我一个想法,我做错了什么?我认为问题与没有任何邻居的obs 42有关。
model
{
for (i in 1:N){
# Poisson likelihood for observed counts
O[i] ~ dpois(mu[i])
log(mu[i]) <- log(E[i]) + alpha + u[i] + v[i]
RR[i] <- exp(alpha + u[i] + v[i])
v[i] ~ dnorm(0, tau.v)
}
# CAR prior distribution for random effects:
u[1:N] ~ car.normal(adj[], weights[], num[], tau.u)
for(k in 1:sumNumNeigh){
weights[k] <- 1
}
# Other priors
alpha ~ dflat()
mean <- exp(alpha)
tau.u ~ dgamma(0.5, 0.0005)
tau.v ~ dgamma(0.5, 0.0005)
sigma.u <- 1/tau.u
sigma.v <- 1/tau.v
ratio <- sigma.u/sigma.v
}
# Data
list(E = c(
309.644702, 1743.709601, 711.804186, 2526.881056, 318.644541, 375.876925,
3078.079354, 479.665537, 611.054281, 578.794301, 263.825542, 443.047869,
1563.163287, 706.636964, 800.620723, 271.043082, 414.554323, 1276.548784,
499.220755, 625.658895, 455.259480, 1293.033647, 970.491142, 636.352367,
636.352367, 614.983914, 560.249202, 468.749744, 1136.010294, 443.047869,
766.793038, 443.221218, 1237.341543, 418.018262, 275.975567, 3.160066,
369.597694, 314.777270, 990.528173, 645.661892, 1205.130767, 278.188792,
1449.545851, 159.055131),
O = c(
345, 1325, 845, 2815, 705, 400, 3150, 485, 325, 405, 585, 410, 3555, 320, 1030, 310,
305,1185, 300, 710, 225, 600, 800, 335, 220, 385, 310, 165, 1190, 175, 840, 1075,
1155, 600, 225, 5, 400, 200, 1155, 850, 1215, 300, 1275, 160),
N = 44,
num = c(
2, 5, 3, 4, 6, 6, 3, 4, 6, 3,
6, 3, 6, 7, 8, 2, 3, 5, 5, 5,
6, 9, 4, 4, 2, 9, 5, 4, 5, 4,
7, 4, 5, 5, 7, 6, 5, 5, 4, 7,
4, 0, 2, 1),
adj = c(
5, 2,
6, 5, 4, 3, 1,
9, 4, 2,
9, 6, 3, 2,
11, 8, 7, 6, 2, 1,
15, 11, 9, 5, 4, 2,
13, 8, 5,
13, 11, 7, 5,
15, 14, 10, 6, 4, 3,
14, 12, 9,
19, 15, 13, 8, 6, 5,
16, 14, 10,
21, 19, 17, 11, 8, 7,
20, 18, 16, 15, 12, 10, 9,
24, 22, 19, 18, 14, 11, 9, 6,
14, 12,
23, 21, 13,
26, 24, 20, 15, 14,
22, 21, 15, 13, 11,
28, 26, 25, 18, 14,
27, 23, 22, 19, 17, 13,
31, 29, 27, 26, 24, 23, 21, 19, 15,
30, 27, 21, 17,
26, 22, 18, 15,
28, 20,
35, 33, 32, 29, 28, 24, 22, 20, 18,
31, 30, 23, 22, 21,
32, 26, 25, 20,
35, 34, 31, 26, 22,
39, 31, 27, 23,
40, 39, 34, 30, 29, 27, 22,
36, 33, 28, 26,
37, 36, 35, 32, 26,
40, 39, 35, 31, 29,
40, 38, 37, 34, 33, 29, 26,
43, 41, 38, 37, 33, 32,
38, 36, 35, 33, 26,
41, 40, 37, 36, 35,
40, 34, 31, 30,
44, 41, 39, 38, 35, 34, 31,
43, 40, 38, 36
,
41, 36,
40
),
sumNumNeigh = 206))
# initial value
list(alpha = 0.01, tau.v = 0.01, tau.u = 0.01, u = c(
0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01,
0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01,
0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01,
0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01
),
v = c(
0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01,
0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01,
0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01,
0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01,0.01
))
感谢您的宝贵时间!非常感谢。
u[22] 表示区域 22 有一个邻居,在 return 中没有区域 22 作为它自己的邻居,因此创建了一个非对称邻接矩阵。除了使用 winbugs 中的 'adjacency map' 工具手动检查之外,我不知道还有什么其他方法。