spacegraph {cem}R Documentation

Randomly compute many different matching solutions

Description

Randomly compute many different matching solutions

Usage

spacegraph(treatment=NULL, data = NULL, 
     R=list("cem"=50,"psm"=0,"mdm"=0,"matchit"=0),
     grouping = NULL, drop=NULL, 
     L1.breaks = NULL, L1.grouping=NULL, fixed = NULL, 
     minimal = 1, maximal = 15, M=100, 
     raw.profile=NULL, keep.weights=FALSE, progress=TRUE,
     rgrouping=FALSE, groups=NULL, psmpoly=1, mdmpoly=1, 
     other.matches=NULL, heuristic=FALSE, linear.pscore=FALSE,
     verbose=1) 

Arguments

treatment

character, name of the treatment variable

data

a data.frame

drop

a vector of variable names in the data frame to ignore during matching.

R

a named list that gives the number of of possible random solutions for each matching method. Allowed methods are cem, psm, mdm, and matchit.

grouping

named list, each element of which is a list of groupings for a single categorical variable. For more details see cem.

L1.breaks

list of cutpoints for the calculation of the L1 measure.

L1.grouping

as grouping but only needed in the calculation of the L1 measure not in matching.

fixed

vector of variable names which will not be relaxed.

minimal

the minimal number of intervals acceptable after relaxation. Should be a named list of positive integers or if a number, this is applied to all variables.

maximal

the maximal number of intervals acceptable after relaxation. Should be a named list of positive integers or if a number, this is applied to all variables.

M

number of possible random coarsening for the L1 measure

raw.profile

an object of class L1profile. If passed, the L1.breaks are ignored and set to median cutpoints of L1 profile.

keep.weights

if TRUE, for each matching solutions the CEM-weights are stored.

rgrouping

Boolean, specifies whether levels of categorical variables should be randomly grouped together by CEM.

groups

named list, each element of which is a list of allowable groupings for a single categorical variable.

psmpoly

numeric, specifying the order of polynomials to include in the propensity score models. At the moment, only psmpoly=1 is available and other values will throw warnings.

mdmpoly

numeric, specifying the order of polynomials to include in Mahalanobis matching. At the moment, only mdmpoly=1 is available and other values will throw warnings.

other.matches

This argument allows plotting of user-specified matching solutions. The solutions must be supplied in a specific format: as a list of data frames, where each data frame contains the observation IDs, observations weights, and the method. These must be provided in three columns of the data frame, with names (exactly) "id", "weight", "method". See the example.

heuristic

Boolean, if TRUE spacegraph uses a heuristic method to randomly select covariates for MDM and PSM rather than sampling from all possible combinations of covariates. The heuristic tends to select most of the main effects and a small number of interactions. This method is automatically applied with large numbers of covariates.

progress

show progress bars.

linear.pscore

does linear.pscore

verbose

integer, controls the level of output.

Details

Spacegraph is a tool to help the user to the search for optimal matching solutions by generating many matching solutions from a variety of matching algorithms (currently CEM, Mahalanobis distance matching, and propensity score matching are supported). The resulting object can be plotted with plot() to show where each solution falls along the bais-variance tradeoff.

The spacegraph function currently calculates two measures of balance for each solution: the L1 metric (see L1.meas ) and the difference in means of the covariates. Typically, analyists look at the difference in means seperately for each variable, but this can't be plotted on a two-dimensional graph. We summarize the difference in means by calculating the average difference in means for all of the covariates. Specifically, we calculate the difference in means for each variable as mean(treated)-mean(control)/sd(treated) and then average across all covariates.

Value

val

an object of class spacegraph that can be used directly with plot() to produce a spacegraph.

Author(s)

Richard Nielsen, Stefano Iacus, Gary King, and Giuseppe Porro

See Also

combine.spacegraphs

Examples


data(LL)
set.seed(123)
sp <- spacegraph("treated", LL, drop="re78", M=5,
                  R=list(cem=5,psm=5, mdm=5))

plot(sp)
## ABOUT THE PLOTTING TOOL:
## The circled solution is the current selection.
## Solutions that are strictly better are also circled.
## The gui provides the exact call to re-run the selected matching solution.
## The call can also be edited, re-run by clicking the button, and 
## automatically added to the existing spacegraph.
## CEM solutions can also be adjusted variable by variable and re-run.


## Some plotting parameters can be changed
plot(sp, main="Comparison of Matching Methods",
  ylab="L1", xlim=c(300,50), ylim=c(0,.7))

## You can specify whether the x-axis shows treated units, 
## control units, or all units using the argument N, which 
## can take the values "treated", "control", or "all".
## Default is "treated".

plot(sp, N="all")

## You can specify how the x-axis is scaled.  Setting scale.var=T
## gives you the scaling as 1/sqrt(n).  Setting scale.var=F gives
## scales it linearly.  Default is scale.var=TRUE.

plot(sp, scale.var=FALSE)

## You can also specify which measure of balance to use
## by specifying the argument "balance.metric" as
## "L1", "mdiff" (Avg. standardized difference in means), 
## or "mdisc" (Average Malanobis Discrepancy).  Default is "L1".

plot(sp, balance.metric="mdiff")
plot(sp, balance.metric="mdisc")


## Matching solutions from other methods can be included in
## a spacegraph by using the argument "other.matches".
## First, Run a matching method.  Here, propensity scores from MatchIt.
library(MatchIt)
m.out <- matchit(formula=treated ~ education+age, data=LL, method = "nearest")

## Put the required information into a list of data frames.
## Note, there are many ways to do this.
mymatches <- list(data.frame(names(m.out$w)))
names(mymatches[[1]])[1] <- "id"
mymatches[[1]]$weight <- m.out$w
mymatches[[1]]$method <- "matchit psm"

sp <- spacegraph("treated", LL, drop="re78", M=5,
 R=list(cem=5,psm=5, mdm=5), other.matches=mymatches)
plot(sp)



[Package cem version 1.1.29 Index]