Extract simulated quantities of interest from a zelig object

zelig_qi_to_df(obj)

Arguments

obj

a zelig object with simulated quantities of interest

Source

For a discussion of tidy data see https://www.jstatsoft.org/article/view/v059i10.

Details

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).

See also

qi_slimmer

Examples

#### 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/
z.1 <- setx(z.1) z.1 <- sim(z.1) head(zelig_qi_to_df(z.1))
#> zelig_qi_to_df is an experimental function. #> Please report issues to: https://github.com/IQSS/Zelig/issues
#> setx_value Petal.Length Species expected_value predicted_value #> 1 x 3.758 virginica 1.533728 1.394808 #> 2 x 3.758 virginica 1.633713 2.258966 #> 3 x 3.758 virginica 1.442489 1.331573 #> 4 x 3.758 virginica 1.585821 1.679375 #> 5 x 3.758 virginica 1.648551 1.754997 #> 6 x 3.758 virginica 1.703332 1.541591
#### 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))
#> zelig_qi_to_df is an experimental function. #> Please report issues to: https://github.com/IQSS/Zelig/issues
#> setx_value Petal.Length Species expected_value predicted_value #> 1 x 2 virginica 1.421454 1.3304218 #> 2 x 2 virginica 1.077102 1.1938983 #> 3 x 2 virginica 1.013856 0.8398486 #> 4 x 2 virginica 1.085898 1.0688339 #> 5 x 2 virginica 1.233649 1.0056654 #> 6 x 2 virginica 1.127581 1.4032852
#### 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))
#> zelig_qi_to_df is an experimental function. #> Please report issues to: https://github.com/IQSS/Zelig/issues
#> setx_value by Petal.Length expected_value predicted_value #> 1 x setosa 2 0.3769370 0.4090966 #> 2 x setosa 2 0.3441451 0.3725846 #> 3 x setosa 2 0.3779441 0.2421895 #> 4 x setosa 2 0.3639800 0.4467564 #> 5 x setosa 2 0.3764422 0.3958439 #> 6 x setosa 2 0.3547684 0.2719568
#### 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/
z.4 <- setx(z.4, Petal.Length = 2:4) z.4 <- sim(z.4) head(zelig_qi_to_df(z.4))
#> zelig_qi_to_df is an experimental function. #> Please report issues to: https://github.com/IQSS/Zelig/issues
#> setx_value Petal.Length Species expected_value predicted_value #> 1 x 2 virginica 1.235274 0.9878925 #> 2 x 2 virginica 1.143378 1.2379151 #> 3 x 2 virginica 1.166633 1.2716201 #> 4 x 2 virginica 1.166410 1.1671186 #> 5 x 2 virginica 1.214761 1.0807178 #> 6 x 2 virginica 1.449047 1.4534318
#### 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/
z.5 <- setx(z.5, Petal.Length = 2:4) z.5 <- sim(z.5) head(zelig_qi_to_df(z.5))
#> zelig_qi_to_df is an experimental function. #> Please report issues to: https://github.com/IQSS/Zelig/issues
#> setx_value by Petal.Length expected_value predicted_value #> 1 x setosa 2 0.4105287 0.4423523 #> 2 x setosa 2 0.3653383 0.3875495 #> 3 x setosa 2 0.3153969 0.5046011 #> 4 x setosa 2 0.3849735 0.5070094 #> 5 x setosa 2 0.4221567 0.3339489 #> 6 x setosa 2 0.3365098 0.2982468
#### 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))
#> zelig_qi_to_df is an experimental function. #> Please report issues to: https://github.com/IQSS/Zelig/issues
#> setx_value Petal.Length Species expected_value predicted_value #> 1 x 2 setosa 0.3934336 0.53946577 #> 2 x 2 setosa 0.4162722 0.34092709 #> 3 x 2 setosa 0.3743606 0.06350679 #> 4 x 2 setosa 0.4481688 0.39779596 #> 5 x 2 setosa 0.2972800 0.30101922 #> 6 x 2 setosa 0.3760098 0.13159094