setx: Setting Explanatory Variable Values

Description Usage Arguments Details Value Author(s) See Also Examples


The setx function uses the variables identified in the formula generated by zelig and sets the values of the explanatory variables to the selected values. Use setx after zelig and before sim to simulate quantities of interest.


setx(obj, fn = NULL, data = NULL, cond = FALSE, ...)



output object from zelig


a list of functions to apply to the data frame


a new data frame used to set the values of explanatory variables. If data = NULL (the default), the data frame called in zelig is used


a logical value indicating whether unconditional (default) or conditional (choose cond = TRUE) prediction should be performed. If you choose cond = TRUE, setx will coerce fn = NULL and ignore the additional arguments in .... If cond = TRUE and data = NULL, setx will prompt you for a data frame.


user-defined values of specific variables for overwriting the default values set by the function fn. For example, adding var1 = mean(data\$var1) or x1 = 12 explicitly sets the value of x1 to 12. In addition, you may specify one explanatory variable as a range of values, creating one observation for every unique value in the range of values


This documentation describes the setx Zelig 4 compatibility wrapper function.


The output is returned in a field to the Zelig object. For unconditional prediction, x.out is a model matrix based on the specified values for the explanatory variables. For multiple analyses (i.e., when choosing the by option in zelig, setx returns the selected values calculated over the entire data frame. If you wish to calculate values over just one subset of the data frame, the 5th subset for example, you may use: x.out <- setx(z.out[[5]])


Matt Owen, Olivia Lau and Kosuke Imai

See Also

The full Zelig manual may be accessed online at


# Unconditional prediction:
z.out <- zelig(vote ~ race + educate, model = 'logit', data = turnout)
x.out <- setx(z.out)
s.out <- sim(z.out, x = x.out)

Search within the Zelig package
Search all R packages, documentation and source code

Questions? Problems? Suggestions? or email at

Please suggest features or report bugs with the GitHub issue tracker.

All documentation is copyright its authors; we didn't write any of that.