Learn R Programming

spacom (version 1.0-5)

MLSpawResidMoran: Testing the (residual) spatial dependency

Description

This step-4 function uses the contextual residuals of (spatially weighted) multilevel models to estimate the spatial dependency left unexplained by the model. The spatial dependency is operationalised by Moran's I coefficient for spatial auto-correlation, which can be recalculated for a range of different bandwidth values (which, in a similar way to spatial weights used for the creation of the context data, allow to parametrise the scale at which spatial dependency is being estimated). The part of explained spatial dependency can be obtained by comparison with the spatial dependency of the intercept-only, or with any other reference model, at the same bandwidth value.

Usage

MLSpawResidMoran(ml.spaw.obj, distance.matrix, bandwidths, kernel = NULL, confidence.intervals = c(0.95), verbose = TRUE)

Arguments

ml.spaw.obj
ResampleMLSpawOutput, MLSpawExactOutput, or matrix of residuals
distance.matrix
square matrix of dimension $n by n$, where $n$ is the number of contextual units.
bandwidths
vector of bandwidths for which to compute Moran's I.
kernel
function applied to the distance matrix. By default NULL, in which case the kernel function $$w_{ij}=f(d,h) = \left(\frac{1}{2}\right)^{d_{ij}^2/h^2}$$ is used, where $w_ij, d_ij, h$ are elements of the weight matrix $W$, of the distance matrix $W$ and the bandwidth $h$. User-supplied kernel functions have to take 2 arguments and return a matrix of the same dimension as the first argument.
confidence.intervals
vector of conficence intervals. Defaults to c(.95) which corresponds to 95 %.
verbose
if TRUE, progress information and an estimate of the remaining computing time is shown at the screen. Defaults to TRUE

Value

A matrix containing Moran's I's

References

Elcheroth, G., Penic, S., Fasel, R., Giudici, F., Glaeser, S., Joye, D., Le Goff, J.-M., Morselli, D., & Spini, D. (2012). Spatially weighted context data: a new approach for modelling the impact of collective experiences. LIVES Working Papers, 19.

Examples

Run this code
# Residual spatial autocorrelation
## It is step-4 function
## for residuals from ResampleAggregateSpawML

## Data preparation

## load individual level data, remove collective guilt assignment for the
## data frame, and remove NA's
data(traces_ind)
traces_ind <- traces_ind[,-7]
traces_ind <- na.exclude(traces_ind)

## load contextual indicator for aggregation
data(traces_event)


## load precise contextual indicator
data(homog_census)

## load distance matrix
data(d_geo)

## Step 1: Create spatial weights
geow.100 <- WeightMatrix(d_geo, bandwidth=100)


## Step 2: Compute spatially weighted aggregated contextual indicator
wv.agg.100 <- SpawAggregate(
              contextual.data = traces_event,
              context.id="area.name",
              contextual.names = "w_all",
              contextual.weight.matrices=geow.100,
              nb.resamples=5,
              aggregation.functions="weighted.mean",
              design.weight.names="weight",
              sample.seed=1)

## rename weighted variable name so it reflects the used weighting
## matrix
names(wv.agg.100) <- "w_all.100"

## Step 3: Perform ResampleMLSpawAggregate
acc_w_100 <-
ResampleMLSpawAggregate(
  individual.level.data=traces_ind,
  context.id="area.name",
  formula=cg_acc ~ victim_d + comb_d + male + age_1990 + high_school +
  higher_edu + (1|area.name) + w_all.100,
  aggregates=wv.agg.100,
  precise.data=NULL)

## Step 4: Perform MLSpawResidMoran for bandwidths 25, 50, 100, 200 

## Not run: 
# MI_acc <- MLSpawResidMoran(ml.spaw.obj=acc_w_100,
#   distance.matrix=d_geo,
#   bandwidths=c(25,50,100,200)) ## End(Not run)

  
## The results can be used for plotting spatial variogram
## See plot() and par() for details 
## Not run: 
# plot(MI_acc[,1], xaxt="n", xlab="Bandwidth values", ylab="Moran's I", type="b")
# axis(side=1, at=1:nrow(MI_acc), labels=rownames(MI_acc)) ## End(Not run)
  

Run the code above in your browser using DataLab