2017-05-03 3 views
0

Ich habe mat2listw{spdep} verwendet, um ein Gewichtungslistenobjekt zu erstellen, das ich später in einer räumlichen Regression verwenden werde. Ich möchte von diesem Gewichtungslisten-Objekt die IDs der Polygone abrufen, mit denen es erstellt wurde. Kann diese Information vom Objekt wiederhergestellt werden?Extrahieren Sie räumliche IDs aus dem Gewichtungslistenobjekt spdep. R

ist hier ein reproduzierbares Beispiel:

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 
+1

Dies könnte funktionieren: - 'Attribute (my_weights) $ region.id' – ahly

+0

@ahly, es funktioniert perfekt. Bitte, posten Sie Ihren Kommentar als Antwort, damit ich ihn akzeptieren kann. Vielen Dank. –

Antwort

1
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" 
Verwandte Themen