Skip to content

Commit

Permalink
scaffolding modelling/checking
Browse files Browse the repository at this point in the history
  • Loading branch information
tmelliott committed May 23, 2024
1 parent 9626272 commit fdabd23
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ iNZightTS.Rproj
*.Rcheck
*.tar.gz
CRAN-SUBMISSION
inst/doc
5 changes: 4 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ Imports:
urca
Suggests:
covr,
knitr,
rmarkdown,
testthat
Description: Provides a collection of functions for working with time series data, including functions for drawing, decomposing, and forecasting. Includes capabilities to compare multiple series and fit both additive and multiplicative models. Used by 'iNZight', a graphical user interface providing easy exploration and visualisation of data for students of statistics, available in both desktop and online versions. Holt (1957) <doi:10.1016/j.ijforecast.2003.09.015>, Winters (1960) <doi:10.1287/mnsc.6.3.324>, Cleveland, Cleveland, & Terpenning (1990) "STL: A Seasonal-Trend Decomposition Procedure Based on Loess".
BugReports: https://github.com/iNZightVIT/iNZightTS/issues
Expand All @@ -48,9 +50,10 @@ LazyData: true
License: GPL-3
Encoding: UTF-8
Language: en-GB
RoxygenNote: 7.2.3
RoxygenNote: 7.3.1
Config/Needs/dependencies:
rcmdcheck,
curl
Config/Needs/coverage:
covr
VignetteBuilder: knitr
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ S3method(plot,inz_frct)
S3method(plot,inz_ts)
S3method(plot,seas_ts)
S3method(predict,inz_ts)
S3method(print,inzts_fit)
S3method(print,summary_inz_frct)
S3method(seasonplot,inz_ts)
S3method(summary,inz_frct)
export(decomp)
export(fit_model)
export(ggplotable)
export(inzightts)
export(log_if)
Expand Down
2 changes: 1 addition & 1 deletion R/iNZightTS2-package.R → R/iNZightTS-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#' @importFrom rlang ':='
#'
#' @name iNZightTS-package
NULL
"_PACKAGE"


utils::globalVariables(c(
Expand Down
22 changes: 22 additions & 0 deletions R/model.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#' @export
fit_model <- function(data, x, method = c("arima", "ets"), ...) {
method <- match.arg(method)
fit <- switch(method,
"arima" = fabletools::model(data, fit = fable::ARIMA(rlang::enquo(x), ...)),
"ets" = fabletools::model(data, fit = fable::ETS(rlang::enquo(x), ...))
)
attr(fit, "method") <- method
attr(fit, "checked") <- FALSE
class(fit) <- c("inzts_fit", class(fit))
fit
}

#' @export
print.inzts_fit <- function(x, ...) {
cat("Model: ", attr(x, "method"), "\n")
print.default(x, ...)

if (!attr(x, "checked")) {
cat("Warning: model has not been checked for assumptions.\n")
}
}
3 changes: 2 additions & 1 deletion man/iNZightTS-package.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions vignettes/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.html
*.R
34 changes: 34 additions & 0 deletions vignettes/model-checking.Rmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
title: "model-checking"
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{model-checking}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---

```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>"
)
```

```{r setup}
library(iNZightTS)
```

```{r tsObject}
visitors_ts <- inzightts(visitorsQ)
plot(visitors_ts, "Australia")
```

```{r model-checking, eval=FALSE}
visitors_fit <- fit_model(visitors_ts, ~Australia, method = "arima")
visitors_fit
plot(visitors_fit)
```

Without any model checking, outputs show warnings.

To check the model, we can use the `check_model` function. This will launch an interactive process where we can check the model assumptions are satisfied.

0 comments on commit fdabd23

Please sign in to comment.