Description Usage See Also Examples
The spatial locations (SpatialPointsDataFrame) of the Beijing land price data. It is used to extract the spatial weights matrix among land parcels.
1 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | data(landSPDF)
library(spdep)
plot(landSPDF,col="red",pch=16,cex=0.7)
data(landprice)
library(classInt)
library(RColorBrewer)
# link the variables in the landprice to the spatial data
index.match <- match(landSPDF$obs,landprice$obs)
landSPDF@data <- data.frame(landSPDF@data,landprice[index.match,])
par(mar=c(0,0,0,0))
x <- landSPDF$lnprice
breaks <- classIntervals(x,4,"fisher")$brks
groups <- cut(x,breaks,include.lowest=TRUE,labels=FALSE)
palette <- brewer.pal(4, "Blues")
plot(landSPDF,pch=19,col=palette[groups],cex=0.8)
# extract a spatial weights matrix based on the distances between pairs of land parcels
nb.25 <- spdep::dnearneigh(landSPDF,0,2500)
# to a weights matrix
dist.25 <- spdep::nbdists(nb.25,landSPDF)
dist.25 <- lapply(dist.25,function(x) exp(-0.5 * (x / 2500)^2))
mat.25 <- spdep::nb2mat(nb.25,glist=dist.25,style="W")
W <- as(mat.25,"dgCMatrix")
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.