IQSS / Zelig

A statistical framework that serves as a common interface to a large range of models
http://zeligproject.org
109 stars 43 forks source link

`by` sims and plots only applied to one section #220

Open christophergandrud opened 7 years ago

christophergandrud commented 7 years ago

In the following code, the model is estimated by whether the canton is majority or minority catholic. However the plots are only created for one model estimation.

swiss$maj_catholic <- cut(swiss$Catholic, breaks = c(0, 51, 100))

z5 <- zls$new()
z5$zelig(Fertility ~ Education, data = swiss, by = 'maj_catholic')
z5$setrange(Education = 5:15)
z5$sim()
z5$graph()
christophergandrud commented 7 years ago

I guess a temporary workaround is that zelig_qi_to_df returns the simulations for all of the by models, e.g.:

library(Zelig)
library(dplyr)

zelig(Petal.Width ~ Petal.Length, by = "Species", data = iris,
        model = "ls") %>%
setx(z.5, Petal.Length = 2:4) %>%
sim() %>%
zelig_qi_to_df() %>%
head()

##   setx_value     by Petal.Length expected_value predicted_value
## 1          x setosa            2      0.3711907       0.4449542
## 2          x setosa            2      0.3863161       0.2804666
## 3          x setosa            2      0.3756340       0.3544871
## 4          x setosa            2      0.4040592       0.3268610
## 5          x setosa            2      0.3811405       0.2781935
## 6          x setosa            2      0.3657079       0.3243758
tercer commented 7 years ago

Do you have an idea of what ideal plot behavior would be. Presently, we build up this panel of very many different plots, showing different ways of interpreting whatever qi's exist. Under that present logic, would you create all of these panels, and cycle through them? Create some higher level summary? Have a default panel to show, but allow the user to somehow specify any of the other by conditions?

(My sense is perhaps the latter makes sense, and then if a user wants to see all the panels, they cycle through the plot calls)

christophergandrud commented 7 years ago

I initially thought of just cycling through. But maybe an overview would be good. This could be easy with ci plots. Just put them in a grid.

jefunes commented 7 years ago

I am trying to obtain att.ev from sim output but i keep getting an error, please see code below:

z.m_b1 <- zelig(log(wy_yield_plot+1) ~ hhead_age + hh_education_mean + xx55 + w_c + perc_own_title + bean_area + dem, data=out_data_m_b1_control,model="ls")

x.out1 <- setx(z.m_b1,data=match.data(m_b1="treat"),cond=TRUE)

s.out1 <- sim(z.m_b1, x=x.out1)

Here i tried different ways to obtain att.ev values from sim output: s.out1$qi$att.ev Error in s.out1$qi$att.ev : object of type 'closure' is not subsettable

then i tried s.out1\$qi\$att.ev
Error: unexpected input in "s.out1\"

Please advice, Thanks so much for your support.

christophergandrud commented 7 years ago

Thanks for your issue @jefunes. This seems like a separate topic so I created a new issue over at: https://github.com/IQSS/Zelig/issues/243

Please follow progress there.