Пакет причинно-следственных связей: вычисление вероятности задней области хвоста по модельным оценкам - PullRequest
0 голосов
/ 13 февраля 2019

В настоящее время я использую пакет CausalImpact для некоторых исследований, и в этом контексте мне нужно знать и уметь объяснять, как рассчитывается вероятность задней области хвоста, чтобы воспроизвести это значение для целей проверки.Кто-нибудь знает, как это значение может быть воспроизведено с учетом данных и оценочных рядов, предоставленных моделью?Заранее спасибо!

1 Ответ

0 голосов
/ 14 февраля 2019

Я никогда не использовал эту библиотеку, но, просматривая код, кажется, что они вычисляют квантили (alpha/2, 1-alpha/2) выборок из апостериорного прогнозного распределения.

From соответствующий раздел кода (лицензия Apache v2.0)

ComputeCumulativePredictions <- function(y.samples, point.pred, y,
                                         post.period.begin, alpha = 0.05) {
  # Computes summary statistics for the cumulative posterior predictions over
  # the unobserved data points in the post-intervention period.
  #
  # Args:
  #   y.samples:         Matrix of simulated response trajectories, as returned
  #                      by \code{ComputeResponseTrajectories()}.
  #   point.pred:        Data frame of point predictions, as returned by
  #                      \code{ComputePointPredictions()}.
  #   y:                 Actual observed response, from the beginning of the
  #                      pre-period to the end of the observed period.
  #   post.period.begin: Index of the first data point of the post-period.
  #   alpha:             The resulting coverage of the posterior intervals will
  #                      be \code{1 - alpha}.
  #
  # Returns:
  #   data frame with 3 columns:
  #     cum.pred:       posterior predictive expectation
  #     cum.pred.lower: lower limit of a \code{(1 - alpha)*100}% interval
  #     cum.pred.upper: upper limit

  ... # [Computing the cum.pred.mean]

  prob.lower <- alpha / 2      # e.g., 0.025 when alpha = 0.05
  prob.upper <- 1 - alpha / 2  # e.g., 0.975 when alpha = 0.05
  cum.pred.lower.post <- as.numeric(t(apply(y.samples.cum.post, 2, quantile,
                                            prob.lower)))
  cum.pred.upper.post <- as.numeric(t(apply(y.samples.cum.post, 2, quantile,
                                            prob.upper)))
  cum.pred.lower <- c(cum.pred.lower.pre, cum.pred.lower.post)
  cum.pred.upper <- c(cum.pred.upper.pre, cum.pred.upper.post)

  # Put cumulative prediction together
  cum.pred <- data.frame(cum.pred = cum.pred.mean,
                         cum.pred.lower, cum.pred.upper)
  return(cum.pred)
}
...