Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Broom support #192

Open
christophsax opened this issue Dec 24, 2016 · 2 comments
Open

Broom support #192

christophsax opened this issue Dec 24, 2016 · 2 comments

Comments

@christophsax
Copy link
Owner

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
Copy link
Owner Author

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
Copy link
Owner Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant