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.x.out <- setx(object, fn = list(numeric = mean, ordered = median,
others = mode),
data = NULL, cond = FALSE, ...)
zelig
.numeric
variables are set to their mean by
default, but you may select any mathematical function to apply to
numeric variables.}
data = NULL
(the default), the
data frame called in zelig
is used.cond = TRUE
) prediction
should be performed. If you choose cond = TRUE
, setx
will coerce fn = NULL
and ignorfn
. For
example, adding var1 = mean(data$var1)
or x1 = 12
explicitly sets the value of x1
to 12. 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:
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.
# 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: quants <- function(x) quantile(x, 0.25) x.out <- setx(z.out, fn = list(numeric = quants))
# Conditional prediction: data(lalonde) match.out <- matchit(treat ~ age + educ + black + hispan + married + nodegree + re74 + re75, data = lalonde) z.out <- zelig(re78 ~ pscore, data = match.data(match, "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)