Built using Zelig version r packageVersion("Zelig")

knitr::opts_knit$set(
    stop_on_error = 2L
)
knitr::opts_chunk$set(
    fig.height = 11,
    fig.width = 7
)

options(cite = FALSE)

Zelig has a number of utilities available to easily extract items of interest from all the results stored in the Zelig object. These are called "getters".

Getters in Zelig 5 vs standard R syntax

Most of the getters can be accessed either through a get Zelig 5 reference class method or via a more traditional R method or function. For example, you could use either the get_coef Zelig 5 reference method or the more tradiational R coef method to extract coefficients from an estimated model:

library(Zelig)

# load data and estimate model
data(sanction)
zqi.out <- zelig(num ~ target + coop + mil,
                 model = "poisson", data = sanction, cite = FALSE)

# get coefficients with Zelig 5 reference class method
zqi.out$get_coef()

# get coefficients with R coef method
coef(zqi.out)

List of getters

As of Zelig 5.1-1 there are the following getters:

| R method/function | Zelig 5 method | | -------------------- | ------------------ | | coef() | get_coef | | combine_coef_se() | | | df.residual() | get_df_residual | | fitted() | get_fitted | | from_zelig_model() | from_zelig_model | | get_qi() | get_qi | | | get_model_data | | names() | get_names | | predict() | get_predicted | | get_pvalue | get_pvalue | | qi_slimmer() | | | residuals() | get_residuals | | get_se() | get_se | | vcov() | get_vcov | | zelig_qi_to_df() | |

Getting quantities of interest

As a key example, the get_qi() method extracts simulated quantities of interest. It has two arguments. The first qi is the name of quantity of interest desired, typically, "ev" for expected values, "pv" for predicted values or "fd" for first differences. The second argument xvalue states which of the set values of x should be used for getting the quantity of interest. The values of x are typically "x" or "x1". If you supply an argument value that does not exist in the Zelig object, Zelig will give you a warning message listing all the names present.

Here is the example from the Poisson model:

library(dplyr)
set.seed(1234)

data(sanction)
zqi.out <- zelig(num ~ target + coop + mil, model = "poisson", data = sanction)
summary(zqi.out)

zqi.out <- zqi.out %>%
            setx(coop = 1) %>%
            setx1(coop = 4) %>%
            sim()

To extract the quantities of interest that have been simulated we can use the getter as:

my.pv.lowcoop <- zqi.out$get_qi(qi ="pv", xvalue = "x")
my.ev.lowcoop <- zqi.out$get_qi(qi = "ev", xvalue = "x")
my.ev.highcoop <- zqi.out$get_qi(qi = "ev", xvalue = "x1")
my.fd <- zqi.out$get_qi(qi = "fd", xvalue = "x1")

The qi argument is the name of any quantity of interest simulated in the object by sim. Depending on the model, this will generally be "ev", "pv", or "fd" for expected values, predicted values, or first differences, respectively. The xvalue argument is the level of x for which that quantity of interest was simulated, either "x" or "x1". Note that first differences, the difference between expected values with covariates at "x" and with covariates at "x1" are associated with the xvalue of "x1".

You can use the get_qi() function as an alternative to the get_qi method. For example:

my.pv.lowcoop <- get_qi(zqi.out, qi =  "pv", xvalue = "x")

Average Treatment Effects on the Treated

Average treatment effects on the treated (ATT) are a quantity of interest that can be generated with the ATT() method/function, for any zelig model that can construct expected values. These can similarly be retrieved with get_qi()

library(dplyr) # load %>% pipe operator
z.att <- zqi.out %>%
             ATT(treatment = "mil") %>%
             get_qi(qi = "ATT", xvalue = "TE")

For more information see the ATT Article.



IQSS/Zelig documentation built on Dec. 11, 2023, 1:51 a.m.