Built using Zelig version 5.1.4.90000


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()
## [[1]]
## (Intercept)      target        coop         mil 
## -0.91568588 -0.04129327  1.24000401 -0.73499112
# get coefficients with R coef method
coef(zqi.out)
## (Intercept)      target        coop         mil 
## -0.91568588 -0.04129327  1.24000401 -0.73499112

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)
## How to cite this model in Zelig:
##   R Core Team. 2007.
##   poisson: Poisson Regression for Event Count Dependent Variables
##   in Christine Choirat, Christopher Gandrud, James Honaker, Kosuke Imai, Gary King, and Olivia Lau,
##   "Zelig: Everyone's Statistical Software," http://zeligproject.org/
summary(zqi.out)
## Model: 
## 
## Call:
## z5$zelig(formula = num ~ target + coop + mil, data = sanction)
## 
## Deviance Residuals: 
##     Min       1Q   Median       3Q      Max  
## -7.9294  -1.2812  -0.2519  -0.2074  17.1719  
## 
## Coefficients:
##             Estimate Std. Error z value Pr(>|z|)
## (Intercept) -0.91569    0.17728  -5.165 2.40e-07
## target      -0.04129    0.05905  -0.699    0.484
## coop         1.24000    0.04641  26.718  < 2e-16
## mil         -0.73499    0.14630  -5.024 5.06e-07
## 
## (Dispersion parameter for poisson family taken to be 1)
## 
##     Null deviance: 1583.77  on 77  degrees of freedom
## Residual deviance:  690.17  on 74  degrees of freedom
## AIC: 915.69
## 
## Number of Fisher Scoring iterations: 6
## 
## Next step: Use 'setx' method
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.