monadic_spatial_weights: Find monadic spatial weights for a cross-sectional...

Description Usage Arguments Details Value Source Examples

Description

Find monadic spatial weights for a cross-sectional time-series data set

Usage

1
2
3
4
monadic_spatial_weights(df, id_var, time_var, location_var, y_var,
  location_var_type, weight_name, method = "euclidean",
  row_standard = FALSE, tlsl = FALSE, mc_cores = 1, na_rm = TRUE,
  morans_i = "message", ...)

Arguments

df

a data frame containing the unit ID variable and time variables as well as location' and dependent variables.

id_var

a character string identifying the unit ID variable in df.

time_var

a character string identifying the time variable in df. If not specified, then all observations are assumed to be from the same time period.

location_var

a character string identifying the location of the units in df. This is used to create the weighting matrix. Note that the function finds the relative distance between the units by subtracting their 'location'.

y_var

a character string identifying the dependent variable in df. Note that an independent variable could also be supplied.

location_var_type

character string allowing you to hard code the measurement type of the location variable and thus how to determine the weighting method Can be either continuous or categorical If not specified, the type with be determined automatically.

weight_name

character string providing a custom weighting variable name.

method

the distance measure to be used. Only relevant for numeric location variables. This must be one of "euclidean", "maximum", "manhattan", "canberra", "binary" or "minkowski". Any unambiguous substring can be given. See dist for details.

row_standard

logical. Whether or not to row-standardize the adjacency matrix, i.e. dividing each neighbor weight for a feature by the sum of all neighbor weights for that feature.

tlsl

logical whether or not to create a temporally-lagged spatial lag by lagging the spatial weight one time unit. Note, Moran's I statistic refer to the non-lagged spatial weights.

mc_cores

The number of cores to use, i.e. at most how many child processes will be run simultaneously. The option is initialized from environment variable MC_CORES if set. Must be at least one, and parallelization requires at least two cores.

na_rm

logical whether or not to remove missing values.

morans_i

character. Whether to print the p-value of Moran's I Autocorrelation Index to the console (message), return only a table of p-values (table), or none. Note only relevant for continuous y_var. Join count analysis for categorical data not yet implemented.

...

arguments to pass to methods.

Details

Finds spatial effects in monadic data. See Neumayer and Plumper (2010, 591) for details.

The weights are found for each unit i given other units k at time t using ∑_{k}w_{kit}y_{kt}.

For continuous location_var w is the euclidean distance. You can choose an alternate method with the method argument. See dist for details.

For factor/character location_var w is 1 if they share the same location, 0 otherwise. The weight is further found by averaging over the number of units at t that share the location of i.

Value

A data frame with three columns, one each for id_var, time_var, and the newly created spatial weights.

Source

Neumayer, Eric, and Thomas Plumper. "Making spatial analysis operational: commands for generating spatial effect variables in monadic and dyadic data." Stata Journal 10.4 (2010): 585-605. http://eprints.lse.ac.uk/30750/1/Making%20spatial%20analysis%20operational(lsero).pdf.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# Create fake time series data
faked <- expand.grid(ID = letters, year = 2010:2015)
faked$located_continuous <- nrow(faked):1
faked$located_categorical <- sample(c('E', 'S', 'W', 'N'),
                                 nrow(faked), replace = TRUE)
faked$y <- nrow(faked):1 - 200

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

# Find row standardized weights for continuous data
df_weights_cont_st <- monadic_spatial_weights(df = faked, id_var = 'ID',
                                         time_var = 'year',
                                         row_standard = TRUE,
                                         location_var = 'located_continuous',
                                         y_var = 'y', mc_cores = 1)

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

# Find weights for character data
df_weights_cat <- monadic_spatial_weights(df = faked, id_var = 'ID',
                                         time_var = 'year',
                                         location_var = 'located_categorical',
                                         y_var = 'y', mc_cores = 1)

# Return a table of p-values from Moran's I spatial autocorrelation test statistic
moran_i_table <- monadic_spatial_weights(df = faked, id_var = 'ID',
                                         time_var = 'year',
                                         location_var = 'located_categorical',
                                         y_var = 'y', mc_cores = 1,
                                         morans_i = 'table')

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