Skip to content

Commit

Permalink
Chanegd kpss default lag selection to match urca and tseries
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchelloharawild committed Feb 5, 2019
1 parent 3341689 commit 6c86c63
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 6 deletions.
6 changes: 1 addition & 5 deletions R/unitRoot.R
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,11 @@ ndiffs <- function(x,alpha=0.05,test=c("kpss","adf","pp"), type=c("level", "tren
approx(urca_test@cval[1,], as.numeric(sub("pct", "", colnames(urca_test@cval)))/100, xout=urca_test@teststat[1], rule=2)$y
}

kpss_wrap <- function(..., use.lag = trunc(3*sqrt(length(x))/13)){
ur.kpss(..., use.lag = use.lag)
}

runTests <- function(x, test, alpha){
tryCatch(
{suppressWarnings(
diff <- switch(test,
kpss = urca_pval(kpss_wrap(x, type=c("mu","tau")[type], ...)) < alpha,
kpss = urca_pval(ur.kpss(x, type=c("mu","tau")[type], ...)) < alpha,
adf = urca_pval(ur.df(x, type=c("drift","trend")[type], ...)) > alpha,
pp = urca_pval(ur.pp(x, type="Z-tau", model=c("constant","trend")[type], ...)) > alpha,
stop("This shouldn't happen"))
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-newarima2.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ if (require(testthat)) {

test_that("test parallel = TRUE and stepwise = FALSE for auto.arima()", {
skip_on_travis()
expect_equal(auto.arima(WWWusage, parallel = TRUE, stepwise = FALSE)$arma, c(3L, 0L, 0L, 0L, 1L, 1L, 0L))
expect_equal(auto.arima(WWWusage, parallel = TRUE, stepwise = FALSE)$arma, c(4L, 0L, 0L, 0L, 1L, 0L, 0L))
})


Expand Down

6 comments on commit 6c86c63

@davidreilly007
Copy link

@davidreilly007 davidreilly007 commented on 6c86c63 Feb 7, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Mitchell, interesting change. Was this done for compatibility or were studies done that showed improved performance?

@mitchelloharawild
Copy link
Collaborator Author

@mitchelloharawild mitchelloharawild commented on 6c86c63 Feb 7, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi David,

The change has been made to match the truncation lag parameter from the original KPSS formulae. The package originally used tseries::kpss.test to perform the test, which had the default lag set to trunc(3*sqrt(length(x))/13). When we converted the tests to use urca::ur.kpss, it used a different default lag of trunc(4 * (n/100)^0.25). For consistency with previous versions of the package, we retained the default lag of the tseries package.

Recently (18-11-2018) the tseries package changed their default lag parameter to trunc(4 * (n/100)^0.25). So other than consistency across forecast package versions, there is no reason to keep the old (and incorrect) truncation lag parameter.

@davidreilly007
Copy link

@davidreilly007 davidreilly007 commented on 6c86c63 Feb 8, 2019 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mitchelloharawild
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes - incorrect is a bit strong. I meant incorrect in reproducing the original KPSS formulae.

@davidreilly007
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, thanks for clarifying! Reasonable to stick with the original paper.

@davidreilly007
Copy link

@davidreilly007 davidreilly007 commented on 6c86c63 Feb 8, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mitchell, I remember now why this default is problematic. If you run the Log AirPassengers you get:

(2,0,0) (0,1,1) instead of the textbook (0,1,1) (0,1,1).

It’s only one data set but it’s a very important dataset, so you might want to discuss with Rob. Maybe an easy way to switch?

Please sign in to comment.