inst/tests/testthat/test-prediction-errors.R

library(bsts)
library(testthat)

test_that("Scaled prediction errors are reasonable.", {
  data(AirPassengers)
  y <- log(AirPassengers)
  ss <- AddLocalLinearTrend(list(), y)
  ss <- AddSeasonal(ss, y, nseasons = 12)
  model <- bsts(y, state.specification = ss, niter = 500)
  errors <- bsts.prediction.errors(model, burn = 100)
  se <- bsts.prediction.errors(model, burn = 100, standardize = TRUE)

  ## The scaled and unscaled errors should be the same size.
  expect_equal(dim(se[[1]]), dim(errors[[1]]))

  ## The errors should be highly but not perfectly correlated.
  expect_gt(cor(se[[1]][30, ], errors[[1]][30, ]), .8)
  expect_lt(cor(se[[1]][30, ], errors[[1]][30, ]), 1.0)
})
michelletran/bsts documentation built on March 29, 2020, 12:58 a.m.