setx {Zelig} | R Documentation |
The setx
command 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(object, ...) ## Default S3 method: setx(object, fn = list(numeric = mean, ordered = median, other = mode), data = NULL, cond = FALSE, counter = NULL, ... )
object |
the saved output from |
fn |
a list of functions to apply to three types of variables:
In the special case |
data |
a new data frame used to set the values of
explanatory variables. If |
cond |
a logical value indicating whether unconditional
(default) or conditional (choose |
counter |
a deprecated parameter |
... |
user-defined values of specific variables
overwriting the default values set by the function |
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]])
For conditional prediction, x.out
includes the model matrix
and the dependent variables. For multiple analyses (when choosing
the by
option in zelig
), setx
returns the
observed explanatory variables in each subset.
Kosuke Imai <kimai@princeton.edu>; Gary King <king@harvard.edu>; Olivia Lau <olau@fas.harvard.edu>
The full Zelig manual may be accessed online at http://gking.harvard.edu/zelig.
# Unconditional prediction: data(turnout) z.out <- zelig(vote ~ race + educate, model = "logit", data = turnout) x.out <- setx(z.out) s.out <- sim(z.out, x = x.out) # Unconditional prediction with all observations: x.out <- setx(z.out, fn = NULL) s.out <- sim(z.out, x = x.out) # Unconditional prediction with out of sample data: z.out <- zelig(vote ~ race + educate, model = "logit", data = turnout[1:1000,]) x.out <- setx(z.out, data = turnout[1001:2000,]) s.out <- sim(z.out, x = x.out) # Using a user-defined function in fn: ## Not run: quants <- function(x) quantile(x, 0.25) x.out <- setx(z.out, fn = list(numeric = quants)) ## End(Not run) # Conditional prediction: ## Not run: library(MatchIt) data(lalonde) match.out <- matchit(treat ~ age + educ + black + hispan + married + nodegree + re74 + re75, data = lalonde) z.out <- zelig(re78 ~ distance, data = match.data(match.out, "control"), model = "ls") x.out <- setx(z.out, fn = NULL, data = match.data(match.out, "treat"), cond = TRUE) s.out <- sim(z.out, x = x.out) ## End(Not run)