Extract simulated quantities of interest from a zelig object
zelig_qi_to_df(obj)
obj | a zelig object with simulated quantities of interest |
---|
For a discussion of tidy data see https://www.jstatsoft.org/article/view/v059i10.
A simulated quantities of interest in a tidy data formatted
data.frame
. This can be useful for creating custom plots.
Each row contains a simulated value and each column contains:
setx_value
whether the simulations are from the base x
setx
or the
contrasting x1
for finding first differences.
The fitted values specified in setx
including a by
column if
by
was used in the zelig
call.
expected_value
predicted_value
For multinomial reponse models, a separate column is given for the expected
probability of each outcome in the form expected_*
. Additionally, there
a is column of the predicted outcomes (predicted_value
).
#### QIs without first difference or range, from covariates fitted at ## central tendencies z.1 <- zelig(Petal.Width ~ Petal.Length + Species, data = iris, model = "ls")#> How to cite this model in Zelig: #> R Core Team. 2007. #> ls: Least Squares Regression for Continuous Dependent Variables #> in Christine Choirat, Christopher Gandrud, James Honaker, Kosuke Imai, Gary King, and Olivia Lau, #> "Zelig: Everyone's Statistical Software," http://zeligproject.org/#> setx_value Petal.Length Species expected_value predicted_value #> 1 x 3.76 virginica 1.63 1.93 #> 2 x 3.76 virginica 1.63 1.56 #> 3 x 3.76 virginica 1.76 1.48 #> 4 x 3.76 virginica 1.60 1.55 #> 5 x 3.76 virginica 1.59 1.56 #> 6 x 3.76 virginica 1.58 1.45#### QIs for first differences z.2 <- zelig(Petal.Width ~ Petal.Length + Species, data = iris, model = "ls")#> How to cite this model in Zelig: #> R Core Team. 2007. #> ls: Least Squares Regression for Continuous Dependent Variables #> in Christine Choirat, Christopher Gandrud, James Honaker, Kosuke Imai, Gary King, and Olivia Lau, #> "Zelig: Everyone's Statistical Software," http://zeligproject.org/z.2a <- setx(z.2, Petal.Length = 2) z.2b <- setx(z.2, Petal.Length = 4.4) z.2 <- sim(z.2, x = z.2a, x1 = z.2a) head(zelig_qi_to_df(z.2))#> setx_value Petal.Length Species expected_value predicted_value #> 1 x 2 virginica 1.32 1.26 #> 2 x 2 virginica 1.15 1.32 #> 3 x 2 virginica 1.30 1.22 #> 4 x 2 virginica 1.08 1.35 #> 5 x 2 virginica 1.06 1.10 #> 6 x 2 virginica 1.43 1.63#### QIs for first differences, estimated by Species z.3 <- zelig(Petal.Width ~ Petal.Length, by = "Species", data = iris, model = "ls")#> How to cite this model in Zelig: #> R Core Team. 2007. #> ls: Least Squares Regression for Continuous Dependent Variables #> in Christine Choirat, Christopher Gandrud, James Honaker, Kosuke Imai, Gary King, and Olivia Lau, #> "Zelig: Everyone's Statistical Software," http://zeligproject.org/z.3a <- setx(z.3, Petal.Length = 2) z.3b <- setx(z.3, Petal.Length = 4.4) z.3 <- sim(z.3, x = z.3a, x1 = z.3a) head(zelig_qi_to_df(z.3))#> setx_value by Petal.Length expected_value predicted_value #> 1 x setosa 2 0.290 0.163 #> 2 x setosa 2 0.377 0.263 #> 3 x setosa 2 0.399 0.367 #> 4 x setosa 2 0.392 0.366 #> 5 x setosa 2 0.341 0.364 #> 6 x setosa 2 0.333 0.422#### QIs for a range of fitted values z.4 <- zelig(Petal.Width ~ Petal.Length + Species, data = iris, model = "ls")#> How to cite this model in Zelig: #> R Core Team. 2007. #> ls: Least Squares Regression for Continuous Dependent Variables #> in Christine Choirat, Christopher Gandrud, James Honaker, Kosuke Imai, Gary King, and Olivia Lau, #> "Zelig: Everyone's Statistical Software," http://zeligproject.org/#> setx_value Petal.Length Species expected_value predicted_value #> 1 x 2 virginica 1.14 1.19 #> 2 x 2 virginica 1.17 1.07 #> 3 x 2 virginica 1.43 1.28 #> 4 x 2 virginica 1.20 1.24 #> 5 x 2 virginica 1.02 1.07 #> 6 x 2 virginica 1.27 1.45#### QIs for a range of fitted values, estimated by Species z.5 <- zelig(Petal.Width ~ Petal.Length, by = "Species", data = iris, model = "ls")#> How to cite this model in Zelig: #> R Core Team. 2007. #> ls: Least Squares Regression for Continuous Dependent Variables #> in Christine Choirat, Christopher Gandrud, James Honaker, Kosuke Imai, Gary King, and Olivia Lau, #> "Zelig: Everyone's Statistical Software," http://zeligproject.org/#> setx_value by Petal.Length expected_value predicted_value #> 1 x setosa 2 0.390 0.370 #> 2 x setosa 2 0.228 0.243 #> 3 x setosa 2 0.381 0.347 #> 4 x setosa 2 0.333 0.311 #> 5 x setosa 2 0.341 0.332 #> 6 x setosa 2 0.243 0.256#### QIs for two ranges of fitted values z.6 <- zelig(Petal.Width ~ Petal.Length + Species, data = iris, model = "ls")#> How to cite this model in Zelig: #> R Core Team. 2007. #> ls: Least Squares Regression for Continuous Dependent Variables #> in Christine Choirat, Christopher Gandrud, James Honaker, Kosuke Imai, Gary King, and Olivia Lau, #> "Zelig: Everyone's Statistical Software," http://zeligproject.org/z.6a <- setx(z.6, Petal.Length = 2:4, Species = "setosa") z.6b <- setx(z.6, Petal.Length = 2:4, Species = "virginica") z.6 <- sim(z.6, x = z.6a, x1 = z.6b) head(zelig_qi_to_df(z.6))#> setx_value Petal.Length Species expected_value predicted_value #> 1 x 2 setosa 0.383 0.243 #> 2 x 2 setosa 0.391 0.494 #> 3 x 2 setosa 0.373 0.574 #> 4 x 2 setosa 0.379 0.438 #> 5 x 2 setosa 0.318 0.349 #> 6 x 2 setosa 0.409 0.655