Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- library(tseries)
- #test if y contains always unit-root
- sum(sapply(c(1:1000), function(z){
- alpha = 0.02
- data = cumsum(rnorm(1000, mean = 2))
- res_adf = adf.test(data)$p.value
- res_kpss = kpss.test(data)$p.value
- if (res_adf < alpha) {
- plot(data, type = 'l', main = z)
- #print(res_adf)
- }
- return(res_adf < alpha)
- }))
- generate_test_data_set <- function(with_unit_root = FALSE, n_lags=1, len = 200) {
- temp = 0.7*2/((1+n_lags)*n_lags)
- koef = sapply(c(1:n_lags), function(x) return(temp*x))
- arima.sim(list(order = c(n_lags, as.numeric(with_unit_root), 0), ar = koef), n = len)
- }
- stationary.data <- generate_test_data_set(with_unit_root = FALSE)
- plot(stationary.data)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement