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”. Each getter is a method that begins with “get”.
As a key example, the getqi() 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:
data(sanction)
z.out <- zelig(num ~ target + coop, model = "poisson", data = sanction)
## Warning in readLines(zeligmixedmodels): incomplete final line found on
## '/usr/lib64/R/library/ZeligMultilevel/JSON/zelig5mixedmodels.json'
## How to cite this model in Zelig:
## R Core Team. 2007.
## poisson: Poisson Regression for Event Count Dependent Variables
## in Christine Choirat, James Honaker, Kosuke Imai, Gary King, and Olivia Lau,
## "Zelig: Everyone's Statistical Software," http://zeligproject.org/
summary(z.out)
## Model:
##
## Call:
## z5$zelig(formula = num ~ target + coop, data = sanction)
##
## Deviance Residuals:
## Min 1Q Median 3Q Max
## -7.2127 -1.1831 -0.2080 -0.1856 17.6514
##
## Coefficients:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) -0.96772 0.17545 -5.516 3.48e-08
## target -0.02102 0.05823 -0.361 0.718
## coop 1.21082 0.04662 25.970 < 2e-16
##
## (Dispersion parameter for poisson family taken to be 1)
##
## Null deviance: 1583.77 on 77 degrees of freedom
## Residual deviance: 720.84 on 75 degrees of freedom
## AIC: 944.35
##
## Number of Fisher Scoring iterations: 6
##
## Next step: Use 'setx' method
z.out$setx(coop=1)
z.out$setx1(coop=4)
z.out$sim()
To extract the quantities of interest that have been simulated we can use the getter as:
my.pv.lowcoop <- z.out$getqi(qi="pv", xvalue="x")
my.ev.lowcoop <- z.out$getqi(qi="ev", xvalue="x")
my.ev.highcoop <- z.out$getqi(qi="ev", xvalue="x1")
my.fd <- z.out$getqi(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”.
If one asks the getter for a qi or xvalue that does not exist in the zelig object, then the error message will result, which will also list all the values that are present that the getter can extract.
my.fd <- z.out$getqi(qi="fa", xvalue="x1")
## Error in z.out$getqi(qi = "fa", xvalue = "x1"): qi must be ev or pv or fd.
my.fd <- z.out$getqi(qi="fd", xvalue="x2")
## Error in z.out$getqi(qi = "fd", xvalue = "x2"): xvalue must be x or x1.