knitr::opts_knit$set(
        stop_on_error = 2L
)
knitr::opts_chunk$set(
        fig.path="man/figures/"
)

spatialWeights

Build Status Coverage Status

This package makes it easy to calculate monadic spatial weights. Its focus is on weights in time-series cross-sectional data. It can find spatial weights and test statistics for spatial autocorrelation (Moran's I) on a per-time interval basis. It can be important to test for spatial autocorrelation on a per-time interval basis in order to assess if a spatial autocorrelation process is temporally bounded.

Examples

Data with spatial clustering

Here is a simple example with fake data with spatial clustering:

library(spatialWeights)

# Create fake time series data
faked1 <- expand.grid(ID = letters, year = 2010:2015)
faked1$located_continuous <- nrow(faked1):1
faked1$y <- nrow(faked1):1 - 200

# Find weights for continuous data
df_weights_cont1 <- monadic_spatial_weights(df = faked1, id_var = 'ID',
                                         time_var = 'year',
                                         location_var = 'located_continuous',
                                         y_var = 'y', mc_cores = 1)

head(df_weights_cont1)

Data that is not spatial clustered

Unlike in the first example, the units in the following data are independent of one another, i.e. not spatially clustered.

# Create fake time series data
faked2 <- expand.grid(ID = letters, year = 2010:2015)
faked2$located_continuous <- rnorm(nrow(faked2))
faked2$y <- nrow(faked2):1 - 200

# Find weights for continuous data
df_weights_cont2 <- monadic_spatial_weights(df = faked2, id_var = 'ID',
                                         time_var = 'year',
                                         location_var = 'located_continuous',
                                         y_var = 'y', mc_cores = 1)

Temporally Lagged Spatial Lags

By default monadic_spatial_weights creates a spatially lagged variable. Using the arguement tlsl = TRUE will lag this variable in time by one period creating an additional time lag spatial lag. For example:

# Create fake time series data
faked1 <- expand.grid(ID = letters, year = 2010:2015)
faked1$located_continuous <- nrow(faked1):1
faked1$y <- nrow(faked1):1 - 200

# Find weights for continuous data
df_weights_cont_tlsl <- monadic_spatial_weights(df = faked1, id_var = 'ID',
                                         time_var = 'year',
                                         location_var = 'located_continuous',
                                         y_var = 'y', mc_cores = 1, tlsl = TRUE)

head(df_weights_cont_tlsl)

Parallelisation

The argument mc_cores allows you to specify the number of cores you would like to use to find the spatial weights in parellel. Parallel computation can lead to substantial speed improvements depending on how many cores you have available and how your data set is organised. To determine how many cores you have available use: parallel::detectCores().

Install

The package can be installed with:

devtools::install_github("christophergandrud/spatialWeights")

See also

Neumayer and Plumper (2010)



christophergandrud/spatialWeights documentation built on May 13, 2019, 7:04 p.m.