问候我正在使用南非shapefile,我转换为边界地图对象,使用R2BayesX将其链接到区域变量,使用马尔可夫随机场优先进行空间结构化(相关)效果,但我收到错误。
这是我的代码:
Code:
library("R2BayesX")
shpname <- file.path(find.package("R2BayesX"), "examples", "SA")
sa_map <- shp2bnd(shpname = shpname, regionnames = "ID_2")
plot(sa_map)
dat <- read.csv("Adult.csv",header = T,sep=",")
attach(dat)
ctr <- bayesx.control(model.name = "OrdRes",outfile = "C:/OrdRes",family
="cumlogit",method = "REML")
m1 <- health ~ sx(districts,bs="mrf",map=sa_map)
sm <- bayesx(m1,data = dat,control = ctr)
I get an error:
bayesx_logfile(sm)
NOTE: created directory C:\OrdRes11\temp
NOTE: created directory C:\OrdRes11\output
logopen using C:/OrdRes11/OrdRes.input.prg.log
remlreg b
map saIi11iImap
saIi11iImap.infile using C:/OrdRes11/saIi11iImap.bnd
NOTE: 52 regions read from file C:/OrdRes11/saIi11iImap.bnd
dataset d
d.infile using C:/OrdRes11/OrdRes.data.raw
NOTE: 3 variables with 16449 observations read from file
C:/OrdRes11/OrdRes.data.raw
b.outfile = C:/OrdRes11/OrdRes
b.regress health = districts(spatial,map=saIi11iImap),
family=cumlogit eps=1e-05 lowerlim=0.001 maxit=400
maxchange=1e+06 using d
*"ERROR: map is disconnected, spatial effect cannot be estimated"*
logclose
NOTE: log-file C:/OrdRes11/OrdRes.input.prg.log closed
这是地图对象的区域级别:
->levels(as.factor(samap$DC_MN_C))
"1" "2" "3" "4" "5" "6" "7" "8" "9" "10" "12"
"13" "14" "15" "16" "17" "18" "19" "20" "21" "22" "23"
"24" "25" "26" "27" "28" "29" "30" "31" "32" "33" "34"
"35" "36" "37" "38" "39" "40" "42" "43" "44" "76" "81"
"82" "83" "84" "88" "171" "275" "572" "773" "774"
这是我数据中的地区级别:
->levels(as.factor(district2001_01))
"1" "2" "3" "4" "5" "6" "7" "8" "9" "10" "12"
"13" "14" "15" "16" "17" "18" "19" "20" "21" "22" "23"
"24" "25" "26" "27" "28" "29" "30" "31" "32" "33" "34"
"35" "36" "37" "38" "39" "40" "42" "43" "44" "76" "81"
"82" "83" "84" "88" "171" "275" "572" "773" "774"
这就是为什么我不知道为什么会收到错误的原因。请帮助解决这个问题。 这是shapefile的变量
->cbind(samap$DC_MDB_C,samap$DC_NAME,samap$DC_MN_C,
samap$ORGUNIT,samap$DISTRICT,samap$OUTYPE,samap$OUAUTHOR)
[,1] [,2] [,3] [,4] [,5] [,6] [,7]
[1,] 1 13 171 50 10 2 13
[2,] 2 24 81 43 24 1 24
[3,] 3 26 82 16 26 1 26
[4,] 4 36 83 38 36 1 36
[5,] 5 4 84 34 4 1 4
[6,] 6 51 88 18 51 1 51
[7,] 7 50 1 53 50 1 50
[8,] 8 8 10 3 9 1 8
[9,] 9 3 12 2 3 1 3
[10,] 10 12 13 4 8 1 12
[11,] 11 42 14 7 42 1 42
[12,] 12 33 15 6 33 1 33
[13,] 13 52 16 12 52 1 52
[14,] 14 28 17 9 28 1 28
[15,] 15 25 18 8 25 1 25
[16,] 16 40 19 11 40 1 40
[17,] 17 6 2 48 6 1 6
[18,] 18 32 20 10 29 1 32
[19,] 19 41 21 23 41 1 41
[20,] 20 43 22 24 43 1 43
[21,] 21 46 23 27 46 1 46
[22,] 22 45 24 26 45 1 45
[23,] 23 2 25 19 2 1 2
[24,] 24 53 26 29 53 1 53
[25,] 25 44 27 25 44 1 44
[26,] 26 47 28 28 47 1 47
[27,] 27 22 29 21 22 1 22
[28,] 28 34 3 52 34 1 34
[29,] 29 21 30 36 21 1 21
[30,] 30 31 31 37 32 1 31
[31,] 31 17 32 35 17 1 17
[32,] 32 27 33 31 27 1 27
[33,] 33 48 34 32 48 1 48
[34,] 34 9 35 30 11 1 9
[35,] 35 49 36 33 49 1 49
[36,] 36 5 37 44 5 1 5
[37,] 37 10 38 46 12 1 10
[38,] 38 7 39 45 7 1 7
[39,] 39 16 4 51 16 1 16
[40,] 40 39 40 47 39 1 39
[41,] 41 35 42 15 35 1 35
[42,] 42 37 43 22 37 1 37
[43,] 43 1 44 1 1 1 1
[44,] 44 11 5 49 13 1 11
[45,] 45 29 6 40 31 1 29
[46,] 46 23 7 39 23 1 23
[47,] 47 38 8 41 38 1 38
[48,] 48 20 9 42 20 1 20
[49,] 49 19 572 20 19 2 19
[50,] 50 18 773 14 18 2 18
[51,] 51 14 774 13 14 2 14
[52,] 52 30 275 5 30 2 30
[53,] 53 15 76 17 15 2 15
答案 0 :(得分:0)
当您在地图的主要区域之外有某些区域(例如岛屿)时,通常会发生此问题。结构化加性回归(STAR)模型中的MRF具有严格的条件,即所有区域均应至少具有一个邻居,这由使用shapefile时每个区域的相邻边界确定。如果您的某些区域没有邻居,则会收到错误消息:
错误:地图已断开连接,无法估算空间效果
有两种解决方案:
添加邻居后,可以使用get.neighbor()函数来确保所有区域都具有邻居。如果是这样,则您的STAR模型可能会起作用。为什么我说它可能起作用?因为STAR模型中存在很多收敛问题。即使地图数据中没有问题,也不能保证您的模型是可估计的。
STAR模型是进行空间分析的一种非常方便的方法,而软件“ BayesX”存在很多问题,手册中没有进一步解释。它的R软件包“ R2BayesX”不是运行STAR模型的独立软件包,而是依赖于计算机中预装的BayesX软件。因此,您可以假设R2BayesX软件包只是将R代码转换为BayesX的转换器。我花了几年时间来解决BayesX中的这些错误消息,并确实使用STAR模型发表了许多论文,但是这些代码最终被发送到BayesX软件以适合该模型,然后将输出返回给R。我仍然在软件中遇到很多未知的问题,该软件能否正常运行充满不确定性和运气。
我认识到您是在一年前发布的问题,因此我的回答可能未及时解决您的问题。但是,我仍然希望我的回答可以帮助使用该软件包时遇到相同问题的其他用户。