Skip to content

Instantly share code, notes, and snippets.

@chrisvoncsefalvay
Created May 14, 2015 19:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrisvoncsefalvay/c80140a7f5b63b6036cc to your computer and use it in GitHub Desktop.
Save chrisvoncsefalvay/c80140a7f5b63b6036cc to your computer and use it in GitHub Desktop.
Useful R functions
# Simple little suite for testing
test_stationarity <- function(Ts){
# First, display ACF.
message("Rendering ACF. Does it look like a random walk to you?")
acf(Ts)
# Calculate Ljung-Box
box <- Box.test(Ts, lag = 3, type = "Ljung-Box")
message(sprintf("The Ljung-Box statistic was %f.", box$p.value))
message("This indicates that the distribution of values is ", appendLF = FALSE)
if(box$p.value <= 0.05){
message("not random.\nConsider differencing or scaling.")
}
else {
message("random.")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment