setx with arima returns error, but not setx1
christophergandrud opened this issue · comments
Looking into an issue reported in #298 by @mbsabath , it seems like plot
for arima
models--specifically when creating acf
plots doesn't recognise setx
simulations, but does find setx1
:
library(zeligverse)
data(seatshare)
subset <- seatshare[seatshare$country == "UNITED KINGDOM",]
ts.out <- zarima$new()
ts.out$zelig(unemp ~ leftseat, order = c(1, 0, 1), data = subset)
ts.out$setx(leftseat = 0.25)
ts.out$sim()
plot(ts.out)
## Error in obj$get_qi("acf", xvalue = "x1") : xvalue must be x.
But
ts.out <- zarima$new()
ts.out$zelig(unemp ~ leftseat, order = c(1, 0, 1), data = subset)
ts.out$setx1(leftseat = 0.25)
ts.out$sim()
plot(ts.out)
returns the expected plot:
I'm working on this issue, and I fixed the issues in the plotting wrapper that lead to the initial error, but the issue remains that qi
isn't generated when only setx
is run. I have a theory on how to fix this, but I want to get feedback on my pseudocode before going forward.
If setx
has been called, but setx1
has not:
- generate
mm
type object based on the algorithm used inset
for an argument lesssetx
(mostly average) - generate
qi
using average asmm
and the counterfactual asmm1
Do we anticipate any errors from this, or do we think this would be fine?
I have a fix that's working on my computer. see commit 8b8868d.
All checks are currently passing on the branch
Thanks for this @mbsabath. Could you bring this branch up-to-date with master? There seem to be some merge conflicts when brought up to speed with master.
Yup. I branched it off of the branch implementing the wrapper for time series. I'll merge things on my machine and get things into that pull request?
sounds good
Just updated the pull request
That seems to work great @mbsabath. Thanks so much for your work on this!
My only question now is what (if anything) is setx1
supposed to do with plot
for arima
? The following produces the same plot (e.g. there are no first differences for the second example) for the version in #289:
library(Zelig)
library(dplyr)
data(seatshare)
subset <- seatshare[seatshare$country == "UNITED KINGDOM",]
# Example 1
zelig(unemp ~ leftseat, data = subset, model = "arima",
order = c(2,0,1)) %>%
setx(leftseat = 0.75) %>%
sim() %>%
plot()
# Example 2
zelig(unemp ~ leftseat, data = subset, model = "arima",
order = c(2,0,1)) %>%
setx(leftseat = 0.75) %>%
setx1(leftseat = 0.25) %>%
sim() %>%
plot()
Relatedly summary
for an arima
Zelig object with setx1
returns:
s.out <- zelig(unemp ~ leftseat, data = subset, model = "arima",
order = c(2,0,1)) %>%
setx(leftseat = 0.75) %>%
setx1(leftseat = 0.25) %>%
sim()
summary(s.out)
## Error in apply(qi, 2, quantile, c(0.5, 0.025, 0.975), na.rm = TRUE) :
## dim(X) must have a positive length
Question
Should setx1
be useable for arima
models?
-
If not we could throw an error when using
setx1
. -
If yes, then we should fix the
summary
error and have a meaningful change to theplot
.
Any thoughts @tercer?
That summary error is persistent, I haven't quite figured out how to fix that yet. The issue is that qi
for time series are not easily printed out. The lack of difference is definitely a bug, I can go into the code today to figure out where the issue is coming from (Probably just a mis-specified if
condition).
My personal feelings on what setx1
should do are this: if only setx1
is called, and not setx
:we throw an error saying setx
hasn't been called. But if setx
has been called, we use the values in it as the base values, with setx1
as the shock values.
Thanks for looking into this. Let's talk about this in the call today.