Learn R Programming

spacom (version 0.9-4)

SpawML: 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

SpawML(individual.level.data,
 contextual.names,
 context.id,
 formula,
 contextual.data = NULL,
 precise.data = NULL,
 contextual.weight.matrices = NULL,
 individual.weight.names = NULL,
 aggregation.functions = "mean")

Arguments

individual.level.data
A data.frame containing the individual level data. The data must be numeric (logical, integer, or plain numeric). There may not be any missing values, NaNs, NULLs or
contextual.names
A list of names of contextual variables to be weighted.
context.id
The name of the context ID variable.
formula
Formula description of the model.
contextual.data
A data.frame containing the micro-level data to generate contextual indicators by aggregation. May be NULL, in which case the individual data is used. The data must be numeric (logical, integer,
precise.data
A data.frame containing the precise contextual data. May be NULL, but may not contain any missing values, like NaNs, NULLs or NAs. By default set to NULL, except for
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
individual.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
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

Value

    Examples

    Run this code
    # Spatially weighted multilevel analysis, with standard estimates of
    # standard errors. Model with two contextual predictors, treated as
    # precise, predicting collective guilt acceptance. 
    # load individual level data, remove collective guilt assignment for 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 and create weights
    data(d_geo)
    geow_100 <- WeightMatrix(d_geo, bandwidth=100)
    
    # perform SpawML
    acc_w_homog_100 <- SpawML(individual.level.data=traces_ind,
      contextual.names=c("w_all", "Homog_00"), context.id="area",
      formula=cg_acc ~ victim_d + comb_d + male + age_1990 + high_school +
      higher_edu + (1|area), contextual.data=traces_event,
      precise.data=homog_census, contextual.weight.matrices=geow_100,
      individual.weight.names="weight", aggregation.functions="weighted.mean")

    Run the code above in your browser using DataLab