Learn R Programming

spacom (version 1.0-5)

SpawAggregate: Create and describe spatially weighted survey estimates for contextual indicators

Description

This step-2 function should be used to create spatially weighted context data when contextual indicators are aggregate estimates derived from available micro-level survey data. Aggregation functions can be user-defined or chosen among predefined options, which include indicators of central tendency (e.g., spatially weighted mean), dispersion (e.g., spatially weighted standard deviation) and inter-group variability (e.g., spatially weighted Gini coefficient for group inequality). Point estimates can be adjusted by user-defined design weights. Descriptive confidence intervals are computed by way of an ad hoc bootstrap resampling procedure.

Usage

SpawAggregate(contextual.data,
 context.id,
 contextual.names,
 contextual.weight.matrices=NULL,
 nb.resamples = 1000,
 aggregation.functions = "weighted.mean",
 confidence.intervals = 0.95,
 design.weight.names = NULL,
 sample.seed = NULL,
 additional.args = NULL,
 verbose = TRUE)

Arguments

contextual.data
A data.frame consisting of micro-level data to generate contextual indicators by aggregation and containing a column named context.id with the context ID variable. This is an individual level dataframe. The data mu
context.id
The name of the context ID variable. This variable allows matching contextual units from different data sets (contextual.data, contexutal.weight.matrix). Values can by of any type but need to be defined consitently across d
contextual.names
A list of names of contextual variables to be aggregated.
contextual.weight.matrices
A list of weights to be applied to each variable specified in contextual.names. A weight may be a weights matrix as, for instance computed by WeightMatrix, or NU
nb.resamples
A number of resamples to be evaluated. By default set to 1000.
aggregation.functions
A list of aggregation functions. Functions take either
  1. 1 argument in which case the corresponding individual design weight isNULL,
  2. 2 arguments in which case the second argument is taken from the co
confidence.intervals
A vector of confidence intervals. Defaults to 0.95 which corresponds to 95 %.
design.weight.names
a list of optional design weights at the individual level used for aggregation (for example, for a weighted mean). List must have same length as contextual.names. May contain NULLs for variables which should not be we
sample.seed
Is one of three things
  1. NULL, in which case whatever the current random seed is is used
  2. aninteger, which will be used to set the random seed. This allows reproducible random samples
  3. a saved<
additional.args
For aggregation functions which take additional arguments (that is in addition to the data to aggregate and design weights), they can be specified here. additional.args defaults to NULL
verbose
if TRUE, progress information and an estimate of the remaining computing time is shown at the screen. Defaults to TRUE

Value

  • An object of class SpawAggregateOutput-class if nb.resamples is different than 0, a data.frame in the contrary case.

Details

SpawAggregate can be used for two similar, yet distinct, purposes:
  1. Aggregate contextual data and weight it spatially. For this, make sure to setnb.resamples=0
  2. To resample thecontextual data repeatedly (bootstrap) and generate a series of aggregated and spatially weighteddata.frames. For this, make sure to use a large number of resamples.
The function SpawAggregate works exactly the same way in either case, but the output changes. See return value for this

Examples

Run this code
## Creating spatially weighted aggregated contextual indicator - spatially weighted 
## risk of war victimization across TRACES areas.
## This is step-2 function

## Step 1: Load distance matrix and create weights
data(d_geo)
geow.50 <- WeightMatrix(d_geo, bandwidth=50)

## Step 2: Load dataframe with micro-level data for aggregation and create 
## spatially weighted contextual indicator (risk of war victimization weighted by geow.50)

data(traces_event)
traces_event=traces_event[seq(1, nrow(traces_event), by=100),]

wv.g50 <- SpawAggregate(contextual.data=traces_event,
                           context.id="area.name",
                           contextual.names="w_all",
                           contextual.weight.matrices=geow.50,
                           aggregation.functions="weighted.mean",
                           design.weight.names="weight",
                           nb.resamples=5)

## To create non-weighted and spatially weighted (by geow.50) risk of war victimization 

wv.nw.g50 <- SpawAggregate(contextual.data=traces_event,
                           context.id="area.name",
                           contextual.names=c("w_all","w_all"),
                           contextual.weight.matrices=list(NULL,geow.50),
                           aggregation.functions="weighted.mean",
                           design.weight.names="weight",
                           nb.resamples=5)

Run the code above in your browser using DataLab