Tutorials › Econometrics (Graduate) › Spatial HAC and Network-Robust Standard Errors

Spatial and Network Econometrics · Tutorial 948 of 952

Spatial HAC and Network-Robust Standard Errors

Learn how spatial and network dependence enter robust covariance estimates, how to calculate these estimates, and when clustering is a better fit.

Advanced 12 min read

What You'll Learn

  • Define spatial and network HAC covariance estimators for regression coefficients.
  • Distinguish covariance estimates for the coefficient estimator from asymptotic covariance estimates for its square-root-n scaling.
  • Identify dependence and asymptotic conditions needed for distance- and graph-based weighting.
  • Calculate standard errors from spatial and network weighted residual products.
  • Compare HAC weighting with cluster-robust covariance estimation.
  • Recognize why robust standard errors do not repair endogeneity or model bias.

Why Dependence Changes Standard Errors

In spatial and network data, nearby locations or connected units may experience related shocks. Even when a regression coefficient is consistently estimated, treating all observations as independent can misstate its uncertainty. Spatial and network heteroskedasticity-and-autocorrelation-consistent (HAC) estimators address this by incorporating weighted products of regression scores for pairs of observations.

These estimators change the estimated covariance matrix, not the regression coefficients. They do not make an endogenous regressor exogenous, remove omitted-variable bias, or establish a causal interpretation. The regression model and the dependence assumptions supporting inference must be considered separately.

Definition: Let \(y_i=x_i'\beta+u_i\), for \(i=1,\ldots,n\), be a linear regression, where \(x_i\) is a \(k\)-component regressor vector and \(u_i\) is the disturbance. Define \(\hat\beta\) as the ordinary least squares estimator, \(\hat u_i=y_i-x_i'\hat\beta\), and \(\hat Q=n^{-1}\sum_i x_ix_i'\). A spatial or network HAC covariance estimator replaces the usual independent-observation “meat” of the sandwich covariance estimator with a weighted sum of products \(x_i\hat u_i\hat u_jx_j'\). The weights reflect spatial distance or network proximity.

A standard starting point is the linear conditional-mean restriction \(E[u_i\mid X]=0\), where \(X\) denotes the regressor data, together with a nonsingular probability limit for \(\hat Q\). For consistency of the coefficient estimator, suitable sampling and dependence conditions are also needed; robust covariance estimation alone does not guarantee consistency. The dependence-robust covariance targets uncertainty around a coefficient estimator that is valid under the model and asymptotic framework being used.

From Regression Scores to a Covariance Estimate

The score contribution for observation \(i\) in the least-squares moment equation is \(x_i u_i\). The OLS estimation error satisfies the exact identity

$$ \hat\beta-\beta = \hat Q^{-1}\left(\frac{1}{n}\sum_{i=1}^n x_i u_i\right). $$

For a fixed design, the covariance of the average score is

$$ \operatorname{Var}\left(\frac{1}{n}\sum_{i=1}^n x_i u_i\right) = \frac{1}{n^2}\sum_{i=1}^n\sum_{j=1}^n x_i x_j'\operatorname{Cov}(u_i,u_j\mid X). $$

This expression includes both the variance terms \(i=j\) and any cross-observation covariance terms \(i\ne j\). In an estimator, the unknown disturbances are replaced by residuals, and the cross-products are weighted to reflect which pairs may be dependent. The two factors of \(n\) in the denominator matter: this formula estimates the covariance of \(\hat\beta\), not the asymptotic covariance of \(\sqrt n(\hat\beta-\beta)\).

Key result: With \(\hat Q=n^{-1}\sum_i x_ix_i'\), a weighted covariance estimate for \(\hat\beta\) has the sandwich form $$ \widehat{\operatorname{Var}}(\hat\beta) = \hat Q^{-1} \left[ \frac{1}{n^2}\sum_{i=1}^n\sum_{j=1}^n w_{ij}x_i x_j'\hat u_i\hat u_j \right] \hat Q^{-1}. $$ The \(n^{-2}\) scaling corresponds to the covariance of \(\hat\beta\). An estimate of the asymptotic covariance of \(\sqrt n(\hat\beta-\beta)\) instead uses \(n^{-1}\) inside the brackets and must be divided by \(n\) to obtain the covariance of \(\hat\beta\).

The weights should be symmetric, \(w_{ij}=w_{ji}\), and usually include the diagonal, with \(w_{ii}=1\). Summing over all ordered pairs then produces a symmetric meat matrix. The resulting estimate can nevertheless fail to be positive semidefinite for some weight choices or samples; a negative estimated variance for a contrast signals a problem requiring investigation, not a valid standard error.

Distance-Based Spatial HAC

For spatial observations, let \(s_i\) denote the location of unit \(i\), and let \(d_{ij}\) be a specified distance between \(s_i\) and \(s_j\), such as Euclidean or great-circle distance. A spatial HAC weight can take the form \(w_{ij}=K(d_{ij}/h_n)\), where \(K\) is a kernel and \(h_n\) is a bandwidth. A common compact-support choice is the Bartlett taper \(K(r)=\max(1-r,0)\). It gives full weight to a unit's own score and gradually reduces the weight on score products as the separation approaches the bandwidth.

Spatial HAC is justified when disturbances or regression scores may be correlated across nearby locations, while dependence between sufficiently distant locations is negligible or declines sufficiently fast. A typical framework is increasing-domain asymptotics: the observed region expands as \(n\) grows, dependence is weak enough for the relevant covariance sums to be controlled, and the bandwidth grows to include more nearby pairs while remaining small relative to the spatial domain. Precise sufficient conditions depend on the sampling design, distance metric, kernel, and dependence process. A bandwidth is not a substitute for a defensible account of how dependence decays.

Worked Example: A Spatial HAC Standard Error for an Intercept

Consider a hypothetical regression with an intercept only, \(y_i=\beta+u_i\), at three sites on a line. The fitted residuals are \((-1,0,1)\), so they sum to zero as required by OLS with an intercept. The distances between consecutive sites are 1, and the distance between the first and third sites is 2. Use a Bartlett weight with bandwidth \(h_n=2\), so \(w_{ij}=\max(1-d_{ij}/2,0)\).

The diagonal weights are 1, the two consecutive-site weights are \(1-1/2=0.5\), and the weight between the first and third sites is 0. The intercept regressor is \(x_i=1\), so \(\hat Q=n^{-1}\sum_i 1=1\). The weighted residual-product sum, including ordered pairs, is

$$ \sum_{i=1}^3\sum_{j=1}^3 w_{ij}\hat u_i\hat u_j = (1+0+1)+2(0.5)(-1)(0)+2(0)(-1)(1)+2(0.5)(0)(1) =2. $$

Thus the covariance estimate for the intercept is

$$ \widehat{\operatorname{Var}}_{\mathrm{sp}}(\hat\beta) = 1^{-1}\left(\frac{2}{3^2}\right)1^{-1} = \frac{2}{9} \approx 0.2222, \qquad SE_{\mathrm{sp}}(\hat\beta)=\sqrt{\frac{2}{9}}\approx 0.4714. $$

This is a hypothetical standard error in the units of the outcome. The calculation assumes that the chosen distance and bandwidth are appropriate for representing relevant spatial dependence; three observations alone do not establish that assumption.

Graph-Based Network-Robust Covariance

For network observations, represent the specified links by a graph and let \(d^G_{ij}\) be the shortest-path distance between nodes \(i\) and \(j\). A graph-based HAC estimator uses weights determined by this distance. For example, \(w_{ij}=\lambda^{d^G_{ij}}\), for \(0<\lambda<1\), assigns decreasing weight to score products for nodes farther apart. Disconnected node pairs can be assigned weight zero. Another option is to retain pairs only up to a chosen graph-distance radius.

This approach requires a substantive assumption: the graph must capture the pathways through which relevant score dependence travels. It is often motivated by local network dependence, where dependence is strongest among linked units or units connected by short paths and weakens with graph distance. A graph-based estimator is not automatically valid merely because network data are available. For consistency, one also needs a suitable sequence of networks, enough observations for the weighted score sums to stabilize, controlled dependence as network size grows, and appropriate conditions on regressors and \(\hat Q\). If important common shocks connect distant nodes in ways the graph misses, graph-distance weights may not capture the covariance.

Worked Example: A Graph-Weighted Intercept Covariance

Suppose a hypothetical network has four nodes, with links only between nodes 1 and 2, and between nodes 3 and 4. A regression with an intercept only has residuals \((-1,-1,1,1)\), which sum to zero. Use \(w_{ii}=1\), \(w_{ij}=0.25\) for linked pairs, and zero for pairs in different connected components.

Here \(\hat Q=1\). The diagonal residual products sum to \(1+1+1+1=4\). Each linked pair has residual product 1; since the double sum includes both orders, each link contributes \(2(0.25)(1)=0.5\). The two links therefore contribute 1, giving a weighted sum of \(4+1=5\). The covariance and standard error are

$$ \widehat{\operatorname{Var}}_{\mathrm{net}}(\hat\beta) = 1^{-1}\left(\frac{5}{4^2}\right)1^{-1} = \frac{5}{16} = 0.3125, \qquad SE_{\mathrm{net}}(\hat\beta) = \sqrt{\frac{5}{16}} \approx 0.5590. $$

The estimate has the units of the outcome squared, and its square root has the units of the outcome. The chosen weights encode a particular dependence pattern; another graph, weighting rule, or network-dependence assumption could lead to a different estimate.

Bandwidths, Clustering, and Interpretation

Spatial and network HAC estimators use a weighting rule to summarize potentially many pairwise covariances. A narrow bandwidth or graph radius can omit relevant dependence and understate uncertainty. A very broad one can add many noisy residual products, increasing estimation variability. Kernel and bandwidth choices should be reported and justified in terms of the spatial or network dependence being modeled. Sensitivity to reasonable choices is informative, but does not by itself validate the assumed dependence structure.

Cluster-robust covariance estimation instead divides observations into clusters and permits arbitrary dependence within each cluster, while relying on independence across clusters under its standard justification. Its meat is built from the outer products of cluster-level summed scores. Clustering is a natural choice when units fall into meaningful, non-overlapping groups and within-group dependence is unrestricted. HAC weighting is useful when dependence varies with physical distance or graph proximity, so a partition into independent clusters would discard meaningful relationships or impose an implausible boundary.

Neither method is universally more robust. Clustering assumes a credible cluster structure and enough independent clusters for its asymptotic justification. Spatial or network HAC assumes a credible proximity measure, a defensible decay or locality pattern, and suitable asymptotic conditions. When the dependence pattern is genuinely block-like, cluster-robust inference may be clearer. When it is graded by distance or network paths, a HAC construction can represent that structure more directly.

Worked Example: Checking the Sandwich Scaling

Consider a hypothetical regression through the origin with \(n=3\), regressors \(x=(1,2,1)\), and outcomes \(y=(3,3,3)\). OLS gives \(\hat\beta=(1\cdot3+2\cdot3+1\cdot3)/(1^2+2^2+1^2)=12/6=2\), with residuals \(\hat u=(1,-1,1)\). Suppose the spatial weighting rule retains only diagonal terms, so \(w_{ii}=1\) and \(w_{ij}=0\) for \(i\ne j\).

The regressor moment is \(\hat Q=(1/3)(1+4+1)=2\). The weighted score-product sum is \(\sum_i x_i^2\hat u_i^2=1+4+1=6\). Applying the covariance formula for \(\hat\beta\) gives

$$ \widehat{\operatorname{Var}}(\hat\beta) = 2^{-1}\left(\frac{6}{3^2}\right)2^{-1} = \frac{1}{4}\cdot\frac{2}{3} = \frac{1}{6} \approx 0.1667, \qquad SE(\hat\beta)=\sqrt{\frac{1}{6}}\approx 0.4082. $$

The result can also be checked directly: with diagonal weights, the scalar sandwich is \(\sum_i x_i^2\hat u_i^2/(\sum_i x_i^2)^2=6/36=1/6\). This confirms that the score-product sum is divided by \(n^2\) when \(\hat Q\) is defined with the \(1/n\) normalization.

Common Mistakes and Practical Limits

  • Using the wrong scaling. Combining \(\hat Q=n^{-1}\sum_i x_ix_i'\) with an \(n^{-1}\) weighted sum estimates the asymptotic covariance on the \(\sqrt n\) scale. For the covariance of \(\hat\beta\), use \(n^{-2}\), or divide the asymptotic covariance estimate by \(n\).
  • Treating a weight matrix as a dependence model. A distance taper cannot establish that distant observations are independent or that the graph captures all relevant dependence. Those claims require substantive and asymptotic justification.
  • Assuming robust means unbiased or causal. HAC standard errors address estimated uncertainty under specified conditions. They do not correct endogeneity, omitted variables, invalid instruments, or misspecified spatial feedback.
  • Equating proximity with clustering. Clusters are disjoint groups; distance- and graph-based dependence can cross arbitrary group boundaries and decay gradually.

After forming the covariance matrix, the standard error for coefficient \(\hat\beta_r\) is the square root of its estimated variance, the \(r\)th diagonal element. For a linear contrast \(a'\hat\beta\), its estimated variance is \(a'\widehat{\operatorname{Var}}(\hat\beta)a\). Large-sample tests and confidence intervals then require the relevant asymptotic approximation to be credible. A small number of spatial units or networks can make conventional large-sample approximations unreliable, regardless of how carefully the covariance matrix is constructed.

Key takeaway: Spatial HAC weights score products by geographic separation; network HAC weights them by graph proximity. Both estimate coefficient uncertainty through a sandwich, but their reliability depends on the assumed dependence structure, the weighting choices, and the asymptotic regime. Keep the \(n^{-2}\) scaling when reporting the covariance of \(\hat\beta\).

Check Your Understanding

Answer each question by referring to the covariance target, the dependence structure, and the stated units where relevant.

  1. Why does the covariance estimator for \(\hat\beta\) use \(n^{-2}\) with \(\hat Q=n^{-1}\sum_i x_ix_i'\)? What does an \(n^{-1}\) factor estimate instead?
  2. In a distance-based spatial HAC estimator, what roles do the distance metric, kernel, and bandwidth play?
  3. State one dependence assumption needed to justify graph-based network HAC, and explain why a graph alone does not guarantee that assumption.
  4. How does the standard cluster-robust dependence assumption differ from a distance-weighted HAC assumption?
  5. Do spatial HAC or network HAC standard errors remove endogeneity bias? Explain briefly.
Clinical Biostats