Learn R Programming

spacom (version 1.0-5)

MLSpawExact: Standard multilevel analysis applied to spatially weighted context data

Description

Integrates spatially weighted context data as higher-level predictors in multilevel analysis and produces conventional statistical estimates.

Usage

MLSpawExact(individual.level.data, context.id, formula, precise.data=NULL, verbose=TRUE, ...)

Arguments

individual.level.data
A data.frame containing the individual level predictor and outcome variables. The data must be numeric (logical, integer, or plain numeric). There must not be any missing values, NaNs, NULLs or NAs.
context.id
The name of the context ID variable. This variable allows matching contextual units from different data sets (precise.data, individual.level.data). Values can by of any type but need to be defined consitently across data sets.
formula
Formula description of the model.The formula is handed down to lmer function of the package lme4. Refer to the documentation of lmer for details.
precise.data
A data.frame containing the precise contextual data.There must not be any missing values, NaNs, NULLs or NAs. By default set to NULL.
verbose
if TRUE, progress information and an estimate of the remaining computing time is shown at the screen. Defaults to TRUE
...
All additional named arguments are handed through to the function lme:lmer (for example, REML=TRUE).

Value

An object of class MLSpawExactOutput-class

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
## Spatially weighted multilevel analysis, with standard estimates of
## standard errors.
## It is step-3 function
## Model with two contextual predictors, treated as precise,
## predicting collective guilt acceptance.

## Data preparation
## load individual level data, remove collective guilt assignment from 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
data(d_geo)

## Step 1: Create spatial weights
geow.100 <- WeightMatrix(d_geo, bandwidth=100)

## Step 2: Create spatially weighted contextual indicators

## from micro-level survey data (treated as precise)
aggregate <- SpawAggregate(contextual.data=traces_event,
                           context.id="area.name",
                           contextual.names='w_all',
                           contextual.weight.matrices=geow.100,
                           aggregation.functions="weighted.mean",
                           design.weight.names="weight",
                           nb.resamples=0)

## from precise indicator
weighted.homog.census <- SpawExact(precise.data=homog_census,
                                   context.id="area.name",
                                   contextual.names="Homog_00",
                                   contextual.weight.matrices=geow.100)

## merge aggregated and weighted data
context.data <- merge(aggregate, weighted.homog.census, by="area.name")


## Step 3: Perform MLSpawExact with two spatially weighted indicators
acc_w_homog_100 <-
  MLSpawExact(individual.level.data=traces_ind,
              context.id="area.name",
              formula=cg_acc ~ victim_d + comb_d + male + age_1990 +
              high_school + higher_edu + (1|area.name) + w_all.1 + Homog_00.1,
              precise.data=context.data)

Run the code above in your browser using DataLab