也就是说,使用spdep包中nb类的region.id,而不是像spdep::nb2INLA那样忽略它?
我一直试图将包含这些区域的数据中的一列作为一个因素链接到INLA模型,并提供描述它们的空间排列的图表。
#something like this
f(rgn16cd,
model = "bym2",
graph = inla_graphs$gb_regions)如果我强迫rgn16cd从一个因子变成一个数字,它就会起作用。有办法将区域名称输入图形文件吗?
发布于 2022-08-10 13:38:14
其中nbs是一个nb类的列表,它使用具有row.names的空间多边形对象,从空间多边形对象的@数据槽的一列中给定值。
这段代码应该返回一个有命名元素的图形,如图所示。

inla_graphs <- purrr::imap(nbs, ~ {
spdep::nb2INLA(file = glue::glue("{.y}.graph"), nb = .x$nb)
x <- INLA::inla.read.graph(glue::glue("{.y}.graph"))
x$nbs <- lapply(x$nbs, FUN = function(X) {
row.names(.x$mat)[X]
})
names(x$nbs) <- row.names(.x$mat)
unlink(glue::glue("{.y}.graph"))
x
})https://stackoverflow.com/questions/73224090
复制相似问题