Gary King Homepage Previous: Hypothetical Data Up: Examples Next: Using WhatIf with Other

Using WhatIf with Zelig

We now illustrate how WHATIF can be easily used with Zelig. As an example, we first generate Zelig output from a simple logistic model using the hypothetical data set created in the prior example:

  > z.out <- zelig(t ~ x + y, data = sqdata, model = "logit")
We next create a counterfactual using the Zelig command setx:
  > x.out <- setx(z.out, x = 2, y = 3)
This is normally followed by a call to the Zelig command sim to compute quantities of interest, such as predicted values given these values of the explanatory variables. See, for example, http://gking.harvard.edu/zelig/docs/Quick_Overview.html. WHATIF enables you to evaluate the values to which you set the explanatory variables before simulating quantities of interest. We do this by calling whatif as follows:
  > summary(whatif(data = z.out, cfact = x.out))
The results indicate that this counterfactual is not in the convex hull of the data. In this situation, you may want to rethink whether or not you should proceed on to the sim stage of analysis. Note that if an intercept was fit as part of the original model, whatif automatically drops it from both the observed covariate data set extracted from the zelig output object z.out and the setx-generated counterfactual x.out.



Gary King 2010-08-12