Learn R Programming

spacom (version 0.9-3)

SpawMLResidMoran: Testing the (residual) spatial dependency

Description

Test of spatial dependency in contextual level residuals from (spatially weighted) multilevel models. The spatial dependency is operationalized by Moran's I coefficient for spatial auto-correlation.

Usage

SpawMLResidMoran(srawe.obj, distance.matrix, bandwidths,
  kernel = NULL, confidence.intervals = c(0.95))

Arguments

srawe.obj
ResampledSpawMLOutput, or a vector of residuals from a SpawMLOutput or matrix of residuals from a ResampleExactSpawMLOutput
distance.matrix
square matrix of dimension $n\times 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 $\mathbf{W}
confidence.intervals
vector of conficence intervals. Defaults to c(.95) which corresponds to 95 %.

Value

    Examples

    Run this code
    # Residual spatial autocorrelation
    
    ## for residuals from ResampleAggregateSpawML
    # 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 and create weights
    data(d_geo) 
    geow_100 <- WeightMatrix(d_geo, bandwidth=100)
    
    # perform ResampleAggregateSpawML
    acc_w_homog_100 <-
    ResampleAggregateSpawML(individual.level.data=traces_ind,
      contextual.names=c("w_all", "Homog_00"), context.id="area",
      formula=cg_acc ~ victim_d + comb_d + male + age_1990 + high_school +
      higher_edu + (1|area), contextual.data=traces_event,
      precise.data=homog_census, contextual.weight.matrices=list(geow_100,
      geow_100), individual.weight.names="weight",
      aggregation.functions="weighted.mean", nb.resamples=10)
    
    
    # perform SpawMLResidMoran for bandwidths 25, 50, 100, 200 
    
    MI_acc <- SpawMLResidMoran(srawe.obj=acc_w_homog_100,
      distance.matrix=d_geo, bandwidths=c(25,50,100,200))

    Run the code above in your browser using DataLab