Lecture 1
Lecture 1
Universidad de Talca
October 7, 2020
1 Introduction to Spatial Econometric
Goals and Mandatory Reading
Why do We Need Spatial Econometric?
Spatial Heterogeneity and Dependence
Spatial Autocorrelation
2 Spatial Weight Matrix
Definition
Weights Based on Boundaries
From Contiguity to the W Matrix
Weights Based on Distance
Row Standardization
Spatial Lag
Higher-Order Spatial Neighbors
3 Examples of Weight Matrices in R
Creating Contiguity Neighbors
Creating Distance-Based
4 Testing for Spatial Autocorrelation
Indicators of spatial association
Moran’s I
1 Introduction to Spatial Econometric
Goals and Mandatory Reading
Why do We Need Spatial Econometric?
Spatial Heterogeneity and Dependence
Spatial Autocorrelation
2 Spatial Weight Matrix
Definition
Weights Based on Boundaries
From Contiguity to the W Matrix
Weights Based on Distance
Row Standardization
Spatial Lag
Higher-Order Spatial Neighbors
3 Examples of Weight Matrices in R
Creating Contiguity Neighbors
Creating Distance-Based
4 Testing for Spatial Autocorrelation
Indicators of spatial association
Moran’s I
Goals
(A) - Chapter 2
(LK)-Sections 1.1-1.2
(A)-Chapter 3
(AR)-Chapter 3 and 4.
Anselin, L. (1995). Local Indicators of Spatial Association- LISA.
Geographical analysis, 27(2), 93-115.
Dall’Erba, S. (2005). Distribution of regional income and regional funds
in Europe 1989-1999: an exploratory spatial data analysis.The Annals of
Regional Science, 39(1), 121-148.
Celebioglu, F., & Dall’erba, S. (2010). Spatial disparities across the
regions of Turkey: an exploratory spatial data analysis. The Annals of
Regional Science, 45(2), 379-400.
1 Introduction to Spatial Econometric
Goals and Mandatory Reading
Why do We Need Spatial Econometric?
Spatial Heterogeneity and Dependence
Spatial Autocorrelation
2 Spatial Weight Matrix
Definition
Weights Based on Boundaries
From Contiguity to the W Matrix
Weights Based on Distance
Row Standardization
Spatial Lag
Higher-Order Spatial Neighbors
3 Examples of Weight Matrices in R
Creating Contiguity Neighbors
Creating Distance-Based
4 Testing for Spatial Autocorrelation
Indicators of spatial association
Moran’s I
Why do We Need Spatial Econometric?
R1 R2 R3 R4 R5
Distance Matters
Key Point:
First law of geography of Waldo Tobler: “everything is related to everything
else”, but near things are more related than distant things
yi = f (xi )i + i =⇒ yi = βi xi + i
Lack of stability over the geographical space.
Why do We Need Spatial Econometric?
yi = f (yi , yj ) + i , ∀i 6= j.
Spatial Dependence
R1 R2 R3 R4 R5
Spatial Dependence
1 1
1 1
Spatial Autocorrelation
1 1
1 1
Spatial Autocorrelation: Another Example
Positive Spatial Autocorrelation Negative Spatial Autocorrelation
Spatial Autocorrelation
Important ideas:
First Law of Geography Again
Important ideas:
Existence of Spatial Dependence.
First Law of Geography Again
Important ideas:
Existence of Spatial Dependence.
Structure of Spatial Dependence
First Law of Geography Again
Important ideas:
Existence of Spatial Dependence.
Structure of Spatial Dependence
Distance decay.
First Law of Geography Again
Important ideas:
Existence of Spatial Dependence.
Structure of Spatial Dependence
Distance decay.
Closeness = Similarities.
1 Introduction to Spatial Econometric
Goals and Mandatory Reading
Why do We Need Spatial Econometric?
Spatial Heterogeneity and Dependence
Spatial Autocorrelation
2 Spatial Weight Matrix
Definition
Weights Based on Boundaries
From Contiguity to the W Matrix
Weights Based on Distance
Row Standardization
Spatial Lag
Higher-Order Spatial Neighbors
3 Examples of Weight Matrices in R
Creating Contiguity Neighbors
Creating Distance-Based
4 Testing for Spatial Autocorrelation
Indicators of spatial association
Moran’s I
Spatial Weight Matrix
Question?
What would be a good criteria to define closeness in space? Or, in other
words, how to determine which other units in the system influence the one
under consideration?
Spatial Weight Matrix
The device typically used in spatial analysis is the so-called spatial weight
matrix, or simply W matrix.
Impose a structure in terms of what are the neighbors for each location.
Assigns weights that measure the intensity of the relationship among pair
of spatial units.
Not necessarily symmetric.
Spatial Weight Matrix
Definition (W Matrix)
Let n be the number of spatial units. The spatial weight matrix, W, a n × n
positive symmetric and non-stochastic matrix with element wij at location
i, j. The values of wij or the weights for each pair of locations are assigned by
some preset rules which defines the spatial relations among locations. By
convention, wij = 0 for the diagonal elements.
1 Binary Contiguity:
Rook criterion (Common Border)
Bishop criterion (Common Vertex)
Queen criterion (Either common border or vertex)
Rook Contiguity
1 2 3
4 5 6
7 8 9
Rook Contiguity
1 2 3
4 5 6
7 8 9
Rook Contiguity
1 2 3
4 5 6
7 8 9
Common border: 2, 4, 5, 6
Bishop Contiguity
1 2 3
4 5 6
7 8 9
Bishop Contiguity
1 2 3
4 5 6
7 8 9
Common vertex: 1, 3, 7, 9
Queen Contiguity
1 2 3
4 5 6
7 8 9
Queen Contiguity
1 2 3
4 5 6
7 8 9
0 1 0 1 0 0 0 0 0
1 2 3 1 0 1 0 1 0 0 0 0
0 1 0 0 0 1 0 0 0
1 0 0 0 1 0 1 0 0
4 5 6 0
W= 1 0 1 0 1 0 1 0
0 0 1 0 1 0 0 0 1
0 0 0 1 0 0 0 1 0
0 0 0 0 1 0 1 0 1
7 8 9 0 0 0 0 0 1 0 1 0
Bishop Contiguity
0 0 0 0 1 0 0 0 0
1 2 3 0 0 0 1 0 1 0 0 0
0 0 0 0 1 0 0 0 0
0 1 0 0 0 0 0 1 0
4 5 6 1
W= 0 1 0 0 0 1 0 1
0 1 0 0 0 0 0 1 0
0 0 0 0 1 0 0 0 0
0 0 0 1 0 1 0 0 0
7 8 9 0 0 0 0 1 0 0 0 0
1 Introduction to Spatial Econometric
Goals and Mandatory Reading
Why do We Need Spatial Econometric?
Spatial Heterogeneity and Dependence
Spatial Autocorrelation
2 Spatial Weight Matrix
Definition
Weights Based on Boundaries
From Contiguity to the W Matrix
Weights Based on Distance
Row Standardization
Spatial Lag
Higher-Order Spatial Neighbors
3 Examples of Weight Matrices in R
Creating Contiguity Neighbors
Creating Distance-Based
4 Testing for Spatial Autocorrelation
Indicators of spatial association
Moran’s I
W based on distance
dm
ij = |xi − xj | + |yi − yj | . (5)
Distance Metric
Euclidean distance is not necessarily the shortest distance if you take into
account the curvature of the earth.
where r is the Earth’s radius. The arc distance is obtained in miles with
r = 3959 and in kilometers with r = 6371.
W based on distance
Inverse distance: (
1
dα if i 6= j
wij = ij (7)
0 if i = j
Typically, α = 1 or α = 2.
Negative exponential model:
dij
wij = exp − (8)
α
W based on distance
This ensures that all weights are between 0 and 1 and facilities the
interpretation of operation with the weights matrix as an averaging of
neighboring values.
Row standardization
This ensures that all weights are between 0 and 1 and facilities the
interpretation of operation with the weights matrix as an averaging of
neighboring values.
Under row-standardization, the element of each row sum to unity.
Row standardization
This ensures that all weights are between 0 and 1 and facilities the
interpretation of operation with the weights matrix as an averaging of
neighboring values.
Under row-standardization, the element of each row sum to unity.
The row-standardized weights matrix also ensures that the spatial
parameter in many spatial stochastic processes are comparable between
models.
Row standardization
This ensures that all weights are between 0 and 1 and facilities the
interpretation of operation with the weights matrix as an averaging of
neighboring values.
Under row-standardization, the element of each row sum to unity.
The row-standardized weights matrix also ensures that the spatial
parameter in many spatial stochastic processes are comparable between
models.
Under row-standardization the matrices are not longer symmetric!.
Row standardization
R1 R2 R3 R4 R5
R1 R2 R3 R4 R5
1 Introduction to Spatial Econometric
Goals and Mandatory Reading
Why do We Need Spatial Econometric?
Spatial Heterogeneity and Dependence
Spatial Autocorrelation
2 Spatial Weight Matrix
Definition
Weights Based on Boundaries
From Contiguity to the W Matrix
Weights Based on Distance
Row Standardization
Spatial Lag
Higher-Order Spatial Neighbors
3 Examples of Weight Matrices in R
Creating Contiguity Neighbors
Creating Distance-Based
4 Testing for Spatial Autocorrelation
Indicators of spatial association
Moran’s I
Examples in R
If the shape file mr_chile.shp is in the same folder, then we can load it into R using the
command readShapeSpatial:
setwd("~/Dropbox/Mis Clases/Spatial Econometrics/Children")
mr <- readShapeSpatial("mr_chile.shp")
class(mr)
## [1] "SpatialPolygonsDataFrame"
## attr(,"package")
## [1] "sp"
The function readShapeSpatial reads data from the shapefile into a Spatial object of class
“sp”. The function names give us the name of the variables in the .dbf file associated with
the shape file.
names(mr)
Metropolitan Region−Chile
−33.0
−33.5
−34.0
−34.5
summary(queen.w)
# Rook W
rook.w <- poly2nb(mr, row.names = mr$NAME, queen = FALSE)
summary(rook.w)
## [,1] [,2]
## 0 -70.65599 -33.45406
## 1 -70.71742 -33.50027
## 2 -70.74504 -33.42278
## 3 -70.67735 -33.38372
## 4 -70.67640 -33.56294
The function coords extract the spatial coordinates from the shape file, whereas the
function knearneigh return a matrix with the indices of points belonging to the set of
the k-nearest neighbors of each other.
The argument k indicates the number of nearest neighbors to be returned.
If point coordinates are longitude-latitude decimal degrees, then distances are
measured in kilometers if longlat = TRUE, if TRUE great circle distances are used.
objects k1neigh and k2neigh are of class knn.
W in R
Weight matrices based on inverse distance can be computed in the following way:
## 0 1 2 3 4
## 0 0.00000000 0.07687010 0.09438408 0.07350782 0.11078109
## 1 0.07687010 0.00000000 0.08226867 0.12324109 0.07489489
## 2 0.09438408 0.08226867 0.00000000 0.07814455 0.15606360
## 3 0.07350782 0.12324109 0.07814455 0.00000000 0.17922003
## 4 0.11078109 0.07489489 0.15606360 0.17922003 0.00000000
## 0 1 2 3 4
## 0 0.000000 13.008960 10.595007 13.603994 9.026811
## 1 13.008960 0.000000 12.155295 8.114177 13.352046
## 2 10.595007 12.155295 0.000000 12.796797 6.407644
## 3 13.603994 8.114177 12.796797 0.000000 5.579733
## 4 9.026811 13.352046 6.407644 5.579733 0.000000
W in R
n z0 Wz
I= (16)
S0 z0 z
where z = x − x̄. If the W matrix is row standardized, then:
z0 W s z
I= (17)
z0 z
because S0 = n. Values range from -1 (perfect dispersion) to +1 (perfect
correlation). A zero value indicates a random spatial pattern.
Moran Scatterplot
A very useful tool for understanding the Moran’s I test
3
2
Quadrant II Quadrant I
Wx
Quadrant III
0
Quadrant IV
4:2
−1
4:1
5:4
−3 −2 −1 0 1 2 3 4
Moran’s I
Note that: P
i (x− x̄)(yi − ȳ)
βbOLS = Pi 2
i i − x̄)
(x
Therefore?
Moran’s I
Note that: P
i (x− x̄)(yi − ȳ)
βbOLS = Pi 2
i i − x̄)
(x
Therefore?
Remark
I is equivalent to the slope coefficient of a linear regression of the spatial lag
Wx on the observation vector x measured in deviation from their means. It
is, however, not equivalent to the slope of x on Wx which would be a more
natural way.
Moran’s I
I − E(I)
TI = p (18)
Var(I)
2
n2 − 3n + 3 S1 − nS2 + 3S02 − b2 n2 − n S1 − 2nS2 + 6S02
n
E I =
(n − 1)(n − 2)(n − 3)S02
Pn Pn Pn Pn (23)
where S0 = i=1 j=1 wij , S1 = i=1 j=1 (wij + wji )2 /2,
Pn Pn Pn
S2 = i=1 (wi. + w.i )2 , where wi. = j=1 wij and wi. = j=1 wji .Then:
2
Var (I) = E I 2 − E (I)
(24)
Inference:
If I > E(I), then a spatial unit tends to be connected by locations with
similar attributes: Spatial clustering (low/low or high/high). The
strength of positive spatial autocorrelation tends to increase with
I − E(I).
If I < E(I) observations will tend to have dissimilar values from their
neighbors: Negative spatial autocorrelation (low/high or high/low)
Application
Lab1A.R
Lab1B.R