Skip to content

Commit

Permalink
S3method exports added
Browse files Browse the repository at this point in the history
  • Loading branch information
robjhyndman committed Mar 1, 2024
1 parent 208768a commit a137e7b
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 3 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,5 @@ License: GPL-3
URL: https://pkg.robjhyndman.com/forecast/, https://github.com/robjhyndman/forecast
VignetteBuilder: knitr
Encoding: UTF-8
RoxygenNote: 7.2.3
RoxygenNote: 7.3.1
Config/testthat/edition: 3
12 changes: 12 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,21 @@ S3method(getResponse,lm)
S3method(getResponse,mforecast)
S3method(getResponse,tbats)
S3method(head,ts)
S3method(hfitted,Arima)
S3method(hfitted,default)
S3method(hfitted,ets)
S3method(logLik,ets)
S3method(modeldf,Arima)
S3method(modeldf,bats)
S3method(modeldf,default)
S3method(modeldf,ets)
S3method(modeldf,lagwalk)
S3method(modeldf,lm)
S3method(modeldf,meanf)
S3method(nobs,ets)
S3method(plot,Arima)
S3method(plot,ar)
S3method(plot,armaroots)
S3method(plot,bats)
S3method(plot,ets)
S3method(plot,forecast)
Expand Down Expand Up @@ -123,6 +132,7 @@ S3method(residuals,nnetar)
S3method(residuals,stlm)
S3method(residuals,tbats)
S3method(residuals,tslm)
S3method(scale,ts)
S3method(seasadj,decomposed.ts)
S3method(seasadj,mstl)
S3method(seasadj,seas)
Expand All @@ -136,6 +146,7 @@ S3method(simulate,lagwalk)
S3method(simulate,modelAR)
S3method(simulate,nnetar)
S3method(simulate,tbats)
S3method(subset,forecast)
S3method(subset,msts)
S3method(subset,ts)
S3method(summary,Arima)
Expand Down Expand Up @@ -212,6 +223,7 @@ export(is.stlm)
export(ma)
export(meanf)
export(modelAR)
export(modeldf)
export(monthdays)
export(mstl)
export(msts)
Expand Down
3 changes: 2 additions & 1 deletion R/arima.R
Original file line number Diff line number Diff line change
Expand Up @@ -965,6 +965,7 @@ fitted.ar <- function(object, ...) {
getResponse(object) - residuals(object)
}

#' @export
hfitted.Arima <- function(object, h, ...) {
# As implemented in Fable
if(h == 1){
Expand All @@ -979,7 +980,7 @@ hfitted.Arima <- function(object, h, ...) {
# Calculate regression component
xm <- y - yx
fits <- rep_len(NA_real_, length(y))

start <- length(mod$Delta) + 1
end <- length(yx) - h
idx <- if(start > end) integer(0L) else start:end
Expand Down
1 change: 1 addition & 0 deletions R/armaroots.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ maroots <- function(object) {
return(structure(list(roots = numeric(0), type = "MA"), class = "armaroots"))
}

#' @export
plot.armaroots <- function(x, xlab, ylab, main, ...) {
if (missing(main)) {
main <- paste("Inverse", x$type, "roots")
Expand Down
12 changes: 12 additions & 0 deletions R/checkresiduals.R
Original file line number Diff line number Diff line change
Expand Up @@ -127,35 +127,47 @@ checkresiduals <- function(object, lag, test, plot = TRUE, ...) {
}
}

#' Compute model degrees of freedom
#'
#' @param object A time series model
#' @param ... Other arguments currently ignored
#' @export
modeldf <- function(object, ...) {
UseMethod("modeldf")
}

#' @export
modeldf.default <- function(object, ...) {
warning("Could not find appropriate degrees of freedom for this model.")
NULL
}

#' @export
modeldf.ets <- function(object, ...) {
length(object$par)
}

#' @export
modeldf.Arima <- function(object, ...) {
sum(arimaorder(object)[c("p", "q", "P", "Q")], na.rm = TRUE)
}

#' @export
modeldf.bats <- function(object, ...) {
length(object$parameters$vect)
}

#' @export
modeldf.lm <- function(object, ...) {
length(object$coefficients)
}

#' @export
modeldf.lagwalk <- function(object, ...) {
as.numeric(object$par$includedrift)
}

#' @export
modeldf.meanf <- function(object, ...) {
1
}
1 change: 1 addition & 0 deletions R/forecast.R
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,7 @@ forecast.forecast <- function(object, ...) {
return(object)
}

#' @export
subset.forecast <- function(x, ...) {
tspx <- tsp(x$mean)
x$mean <- subset(x$mean, ...)
Expand Down
1 change: 1 addition & 0 deletions R/nnetar.R
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,7 @@ is.nnetarmodels <- function(x) {
}

# Scale a univariate time series
#' @export
scale.ts <- function(x, center=TRUE, scale=TRUE) {
tspx <- tsp(x)
x <- as.ts(scale.default(x, center = center, scale = scale))
Expand Down
1 change: 0 additions & 1 deletion man/forecast-package.Rd

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

14 changes: 14 additions & 0 deletions man/modeldf.Rd

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

0 comments on commit a137e7b

Please sign in to comment.