从权重列表对象中提取空间 ID,spdep R
Extract spatial ids from weights list object, spdep R
我已经使用 mat2listw{spdep}
创建了一个权重列表对象,我稍后将在空间回归中使用它。我想从此权重列表对象中检索用于创建它的多边形的 ID。
是否可以从对象中恢复此信息?
这是一个可重现的例子:
library(spdep)
library(UScensus2000tract)
# load data
data("oregon.tract")
# get coordinates of centroids
coords <- coordinates(oregon.tract)
# calculate a simple distance matrix between coordinates
d <- dist(coords)
d <- as.matrix(d)
# Calculate Spatial weights Matrix (travel time)
my_weights <- mat2listw(d, row.names = row.names(oregon.tract))
# Now I'd like to extract from my_weights the polygon ids
library(spdep)
library(UScensus2000tract)
# load data
data("oregon.tract")
# get coordinates of centroids
coords <- coordinates(oregon.tract)
# calculate a simple distance matrix between coordinates
d <- dist(coords)
d <- as.matrix(d)
# Calculate Spatial weights Matrix (travel time)
my_weights <- mat2listw(d, row.names = row.names(oregon.tract))
# Extract region ids from attributes of my_weights
region.ids <- attributes(my_weights)$region.id
head(region.ids)
[1] "oregon_0" "oregon_1" "oregon_2" "oregon_3" "oregon_4" "oregon_5"
我已经使用 mat2listw{spdep}
创建了一个权重列表对象,我稍后将在空间回归中使用它。我想从此权重列表对象中检索用于创建它的多边形的 ID。
是否可以从对象中恢复此信息?
这是一个可重现的例子:
library(spdep)
library(UScensus2000tract)
# load data
data("oregon.tract")
# get coordinates of centroids
coords <- coordinates(oregon.tract)
# calculate a simple distance matrix between coordinates
d <- dist(coords)
d <- as.matrix(d)
# Calculate Spatial weights Matrix (travel time)
my_weights <- mat2listw(d, row.names = row.names(oregon.tract))
# Now I'd like to extract from my_weights the polygon ids
library(spdep)
library(UScensus2000tract)
# load data
data("oregon.tract")
# get coordinates of centroids
coords <- coordinates(oregon.tract)
# calculate a simple distance matrix between coordinates
d <- dist(coords)
d <- as.matrix(d)
# Calculate Spatial weights Matrix (travel time)
my_weights <- mat2listw(d, row.names = row.names(oregon.tract))
# Extract region ids from attributes of my_weights
region.ids <- attributes(my_weights)$region.id
head(region.ids)
[1] "oregon_0" "oregon_1" "oregon_2" "oregon_3" "oregon_4" "oregon_5"