Learn R Programming

spacom (version 1.0-5)

aggregation functions: Aggregation functions provided by spacom

Description

Spacom provides a set of aggregation functions which can be used with the functions SpawAggregate and ExploreMLSpawAggregate. See Details for descriptions of each function. Note that you are not restricted to these.

User supplied aggregation functions can be used if they have the form $$x_w = f(x, w, ...)$$ where $x$ is the data to be aggregated, $w$ the weights to be applied. Any number of additional arguments may also be used (see argument additional.args in SpawAggregate for details on additional arguments. The return value $x_w$ must be a scalar value (i.e. not a vector).

Usage

wt.sd(data, weights=rep(1, length(data)))
wt.var(data, weights=rep(1, length(data)))
wt.gini(data, weights=rep(1, length(data)))
wt.gini.categ(data, weights=rep(1, length(data)))
wt.Theil(data, weights=rep(1, length(data)))
wt.RS(data, weights=rep(1, length(data)))
wt.Atkinson(data, weights=rep(1, length(data)))
wt.gini.group(data, weights=rep(1, length(data)), groups)

Arguments

data
A vector of data to be aggregated
weights
A vector of weights. These weights are computed by combining the spatial weights and design weights for each context.
groups
name of the column used to group data (only wt.group.gini)

Value

  • A scalar value of type numeric. For user-supplied aggregation functions, this can potentially be of a differenet type.

Details

  1. wt.var(data, weights)
{ Computes the weighted variance according to $${\rm Var}(x) = \frac{\sum_{i=1}^n (w_i\cdot(x_i - \mu)^2)} {\sum_{i=1}^n w_i}$$ where the weighted mean is $\mu$ $$\mu = \frac{\sum_{i=1}^n w_i\cdot x_i}{\sum_{i=1}^n w_i}$$ } wt.sd(data, weights){ Computes the weighted standard deviation according to $$\sigma = \sqrt{{\rm Var}(x)}$$ } wt.gini{ The weighted Gini coefficient is given by $$G = \frac{1}{2\mu}\sum_{i,j}w_iw_j\left|x_i-x_j\right|$$

where $\mu$ is $$\mu = \sum_{i}w_ix_i$$ } wt.gini.categ{ Spacom also allows for the computation of inequality indicators for categorical variables. In this case, one has no $x_i$ value but only the weighted frequencies $f_i$ for each category. For that case, the Gini becomes $$G = 1-\sum_if_i^2$$ The weighted frequencies are computed from data and weights } wt.gini.group{ get from guy }

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
## Creating indicators of spatially weighted inequalities 

## load individual level data and remove missings
data(traces_ind)
traces_ind <- na.exclude(traces_ind)

## create variable "simulated income" in the dataset
## the variable is created only in demonstrative purposes, 
## and it is not part of the TRACES dataset

traces_ind$sim_inc <- rnorm(nrow(traces_ind), 1000, 100)

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

## Step 2: Spatially weighted gini for simulated income
si.gini <- SpawAggregate(contextual.data=traces_ind,
                         context.id="area.name",
                         contextual.names="sim_inc",
                         contextual.weight.matrices=geow.50,
                         aggregation.functions="wt.gini",
                         design.weight.names=NULL,
                         nb.resamples=5)

## Step 2: Spatially weighted gini for groups (Spatially weighted inequalities
## in simulated income for men and women)  

si.gini.gr <- SpawAggregate(contextual.data=traces_ind,
                            context.id="area.name",
                            contextual.names="sim_inc",
                            contextual.weight.matrices=geow.50,
                            aggregation.functions="wt.gini.group",
                            additional.args="male",
                            design.weight.names=NULL,
                            nb.resamples=5)

Run the code above in your browser using DataLab