christophsax / seasonal

R interface to X-13ARIMA-SEATS
www.seasonal.website
120 stars 27 forks source link

Broom support #192

Open christophsax opened 7 years ago

christophsax commented 7 years ago

Picking up a thread from the broom package.

I can perfectly see why you want the output of a summary to be a data.frame, rather than a complex R object. Because of that I added an experimental data.frame argument to summary.seas and udg in seasonal 1.4, which is now on CRAN.

But I think it would be probably nicer to implement an as.data.frame method, so we could write:

m <- seas(AirPassengers)
as.data.frame(summary(m))

Are other packages doing that?

This seems to me so much simpler than using a huge specialised package to do just that?

christophsax commented 7 years ago

We have now as.data.frame() for output of seas and seas.summary. Would make it also easy to complete the broom methods, e.g.:


library(broom)
library(seasonal)

tidy.seas <- function (x, ...) {
  as.data.frame(summary(x, ...))
}

augment.seas <- function(x) {
  as.data.frame(x)
}

glance.seas <- function(x, ...){
  sx <- summary(x, ...)
  z <- list()
  z$adjustment <- if (!is.null(sx$spc$seats)) {
      ("SEATS")
  } else if (!is.null(sx$spc$x11)) {
      ("X11")
  } else {
      ("none")
  }

  z$arima <- sx$model$arima$model
  z$nobs <- sx$nobs
  z$transform <- sx$transform.function
  z$AICc <- sx$aicc
  z$BIC <- sx$bic
  z$qs <- unname(sx$qsv['qs'])
  z$qs.p.value <- unname(sx$qsv['p-val'])

  if (!is.null(sx$resid)) {
      bltest <- Box.test(sx$resid, lag = 24, type = "Ljung")
      z$box_ljung <- unname(bltest$statistic)
      swtest <- shapiro.test(sx$resid)
      z$shapiro <- unname(swtest$statistic)
  }

  as.data.frame(z)
}

m <- seas(AirPassengers)

tidy(m)
augment(m)
glance(m)
christophsax commented 3 years ago

Broom ticket was closed, but it may still be good idea.