| Previous: Examples | Up: Zelig Commands | Next: Presenting Results |
The zelig() command estimates a selected statistical model given the specified data. You may name the output object (z.out above) anything you desire. You must include three required arguments, in the following order:
for a list
of currently supported models.
) in the
data frame as a subsetting variable. For each of the unique
strata defined in the by variable, zelig() does a
separate run of the specified model. The variable chosen should
not be in the formula, because there will be no variance in
the by variable in the subsets. If you have one data set for
all 191 countries in the UN, for example, you may use the by
option to run the same model 191 times, once on each country, all
with a single zelig() statement. You may also use the by option to run models on
MatchIt
subclasses.
The setx() command lets you choose values for the explanatory variables, with which sim() will simulate quantities of interest. There are two types of setx() procedures:
The setx() arguments for unconditional prediction are as follows:
> z.out <- zelig(vote ~ age + race, model = "logit", data = turnout) > x.out <- setx(z.out, age = 30)setx() sets the variables not explicitly listed to their mean if numeric, and their median if ordered factors, and their mode if unordered factors, logical values, or character strings. Alternatively, you may specify one explanatory variable as a range of values, creating one observation for every unique value in the range of values:4.2
> x.out <- setx(z.out, age = 18:95)This creates 78 observations with with age set to 18 in the first observation, 19 in the second observation, up to 95 in the 78th observation. The other variables are set to their default values, but this may be changed by setting fn, as described next.
> X.sd <- setx(z.out, fn = list(numeric = sd)) > X.mean <- setx(z.out, fn = list(numeric = mean)) > x.out <- X.mean - X.sd
If you wish to calculate risk ratios or first differences, call setx() a second time to create an additional set of the values for the explanatory variables. For example, continuing from the example above, you may create an alternative set of explanatory variables values one standard deviation above their mean:
> x.alt <- X.mean + X.sd
The required arguments for conditional prediction are as follows:
The sim() command simulates quantities of interest given the output objects from zelig() and setx(). This procedure uses only the assumptions of the statistical model. The sim() command performs either unconditional or conditional prediction depending on the options chosen in setx().
The arguments are as follows for unconditional prediction:
> s.out <- sim(z.out, x = x.out, x1 = x.alt)
For conditional prediction, sim() takes only two required arguments:
), sim() must impute
the uncensored dependent variables before calculating the average
treatment effect. Inputting the cond.data allows sim() to generate appropriate values.