library(dplyr)
pelt <- tsibbledata::pelt
train <- pelt %>%
dplyr::filter( Year < 1930 )
test <- pelt %>%
dplyr::filter( Year >= 1930 )
model <- fabletools::model(pelt, tbats = TBATS(Lynx) )
test_that("Utilities for TBATS work", {
# residuals
expect_equal( sum(residuals(model[[1]][[1]][["fit"]])),
115493.1,
tolerance = 0.05
)
# fitted
expect_equal( sum(fitted(model[[1]][[1]][["fit"]])),
2463137,
tolerance = 0.05
)
# glance
expect_equal( sum(unlist(fabletools::glance(model)[,2:7])),
57386873,
tolerance = 0.05
)
})
test_that( "Forecasts for TBATS work", {
fcsts <- fabletools::forecast(model, h = 3)$.mean
expect_equal( fcsts,
c(36004, 31556, 24992),
tolerance = 0.1)
})
test_that( "Refitting a TBATS works", {
model <- fabletools::model(train, tbats = TBATS(Lynx) )
expect_equal( as.character(model[[1]][[1]][["fit"]][["fit"]]),
"TBATS(0.025, {0,0}, 0.8, {<10,4>})")
model <- refit(model, pelt)
expect_equal( as.character(model[[1]][[1]][["fit"]][["fit"]]),
"BATS(0.43, {3,2}, 0.879, -)")
})
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.