Skip to content

Conversation

@luciferous
Copy link

@luciferous luciferous commented Jul 25, 2021

construct.model is a function that takes modeling data (NA in
post.period) and returns a bsts model.

This invocation:

go <- function(data) {
  y <- data[, 1]
  sdy <- sd(y, na.rm = TRUE)
  sd.prior <- SdPrior(sigma.guess = 0.01 * sdy,
                      upper.limit = sdy,
                      sample.size = 32)
  ss <- AddLocalLevel(list(), y, sigma.prior = sd.prior)
  bsts.model <- bsts(y, state.specification = ss, niter = 100,
                     seed = 1, ping = 0)
}

impact <- CausalImpact(data, pre.period, post.period,
                       construct.model = go)

is equivalent to:

model.args <- list(niter = 100)
impact <- CausalImpact(data, pre.period, post.period, model.args)

. This change provides an interface that has RunWithData's flexibility
with pre- and post-period, and RunWithBstsModel's full configurability
of the model. For example, the caller can now specify a custom model
where the post-period is before the end of the data, or with a gap
between the pre-period and post-period, either of which aren't possible
with the previous interface.

@luciferous luciferous force-pushed the construct-model-impl branch from fdf2936 to 2c14583 Compare July 25, 2021 17:25
@luciferous
Copy link
Author

plot(impact) from the added test case.

Rplot construct-model

@luciferous
Copy link
Author

Hi @alhauser,

This proposal changes the API but in a backwards-compatible way. Let me know if you'd be open to it, I'm happy to chat about other ways to get the same outcome.

@luciferous luciferous marked this pull request as ready for review July 25, 2021 17:31
@luciferous luciferous force-pushed the construct-model-impl branch from 2c14583 to f10b556 Compare July 26, 2021 07:43
construct.model is a function that takes modeling data (NA in
post.period) and returns a bsts model.

This invocation:

    go <- function(data) {
      y <- data[, 1]
      sdy <- sd(y, na.rm = TRUE)
      sd.prior <- SdPrior(sigma.guess = 0.01 * sdy,
                          upper.limit = sdy,
                          sample.size = 32)
      ss <- AddLocalLevel(list(), y, sigma.prior = sd.prior)
      bsts.model <- bsts(y, state.specification = ss, niter = 100,
                         seed = 1, ping = 0)
    }

    impact <- CausalImpact(data, pre.period, post.period,
                           construct.model = go)

is equivalent to:

    model.args <- list(niter = 100)
    impact <- CausalImpact(data, pre.period, post.period, model.args)

. This change provides an interface that has RunWithData's flexibility
with pre- and post-period, and RunWithBstsModel's full configurability
of the model. For example, the caller can now specify a custom model
where the post-period is before the end of the data, or with a gap
between the pre-period and post-period, either of which aren't possible
with the previous interface.
@luciferous luciferous force-pushed the construct-model-impl branch from f10b556 to b27f4c0 Compare July 26, 2021 07:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant