1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326
|
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# A copy of the GNU General Public License is available via WWW at
# http://www.gnu.org/copyleft/gpl.html. You can also obtain it by
# writing to the Free Software Foundation, Inc., 59 Temple Place,
# Suite 330, Boston, MA 02111-1307 USA.
# Copyrights (C)
# for this R-port:
# 1999 - 2007, Diethelm Wuertz, GPL
# Diethelm Wuertz <wuertz@itp.phys.ethz.ch>
# info@rmetrics.org
# www.rmetrics.org
# for the code accessed (or partly included) from other R-ports:
# see R's copyright and license files
# for the code accessed (or partly included) from contributed R-ports
# and other sources
# see Rmetrics's copyright file
################################################################################
# FUNCTION: URCA INTERFACE [PFAFF] UNIT ROOT TESTS:
# urdfTest Performs Augmented Dickey-Fuller test for unit roots
# urersTest PerformsElliott-Rothenberg-Stock test for unit roots
# urkpssTest Performs KPSS unit root test for stationarity
# urppTest Performs Phillips-Perron test for unit roots
# urspTest Performs Schmidt-Phillips test for unit roots
# urzaTest Performs Zivot-Andrews test for unit roots
################################################################################
# NOTE, THIS INTERFACE REQUIRES THE URCA PACKAGE !
urdfTest =
function(x, lags = 1, type = c("nc", "c", "ct"), doplot = TRUE)
{ # A function implemented by Diethelm Wuertz
# Description:
# Dickey-Fuller test for unit roots
# Notes:
# Requires "urca" which is not part of this distribution
# Wraps -
# ur.df(y, type = c("none", "drift", "trend"), lags = 1)
# FUNCTION:
# Compute:
x = as.vector(x)
if (type[1] == "nc") Type = "none"
if (type[1] == "c") Type = "drift"
if (type[1] == "ct") Type = "trend"
urca = ur.df(x, type = Type, lags = lags)
output = capture.output(summary(urca))[-(1:4)]
for (i in 1:length(output)) output[i] = paste(" ", output[i])
output = output[-length(output)][-3]
# Test Results:
ans = list(
name = "ur.df",
test = urca,
output = output
)
# Plot:
if (doplot) plot(urca)
# Return Value:
new("fHTEST",
call = match.call(),
data = list(x = x),
test = ans,
title = "Augmented Dickey-Fuller Unit Root Test",
description = description()
)
}
# ------------------------------------------------------------------------------
urersTest =
function(x, type = c("DF-GLS", "P-test"), model = c("constant", "trend"),
lag.max = 4, doplot = TRUE)
{ # A function implemented by Diethelm Wuertz
# Description:
# Elliott-Rothenberg-Stock test for unit roots
# Notes:
# Requires "urca" which is not part of this distribution
# Wraps -
# ur.ers(y, type = c("DF-GLS", "P-test"),
# model = c("constant", "trend"), lag.max = 4)
# FUNCTION:
# Compute:
x = as.vector(x)
urca = ur.ers(x, type = type[1], model = model[1], lag.max = lag.max)
output = capture.output(summary(urca))[-(1:4)]
for (i in 1:length(output)) output[i] = paste(" ", output[i])
output = output[-length(output)]
if (type[1] == "DF-GLS") output = output[-(4:7)]
# Test Results:
ans = list(
name = "ur.ers",
test = urca,
output = output
)
# Plot:
if (doplot & type[1] == "DF-GLS") plot(urca)
# Return Value:
new("fHTEST",
call = match.call(),
data = list(x = x),
test = ans,
title = "Elliott-Rothenberg-Stock Unit Root Test",
description = description()
)
}
# ------------------------------------------------------------------------------
urkpssTest =
function(x, type = c("mu", "tau"), lags = c("short", "long", "nil"),
use.lag = NULL, doplot = TRUE)
{ # A function implemented by Diethelm Wuertz
# Description:
# KPSS unit root test for stationarity
# Notes:
# Requires "urca" which is not part of this distribution
# Wraps:
# ur.kpss(y, type = c("mu", "tau"), lags = c("short", "long", "nil"),
# use.lag = NULL)
# FUNCTION:
# Compute:
x = as.vector(x)
urca = ur.kpss(x, type = type[1], lags = lags[1], use.lag = use.lag)
output = capture.output(summary(urca))[-(1:4)]
output = output[-length(output)]
for (i in 1:length(output)) output[i] = paste(" ", output[i])
# Test Results:
ans = list(
name = "ur.kpss",
test = urca,
output = output
)
# Plot:
if (doplot) plot(urca)
# Return Value:
new("fHTEST",
call = match.call(),
data = list(x = x),
test = ans,
title = "KPSS Unit Root Test",
description = description()
)
}
# ------------------------------------------------------------------------------
urppTest =
function(x, type = c("Z-alpha", "Z-tau"), model = c("constant", "trend"),
lags = c("short", "long"), use.lag = NULL, doplot = TRUE)
{ # A function implemented by Diethelm Wuertz
# Description:
# Phillips-Perron test for unit roots
# Note:
# Requires "urca" which is not part of this distribution
# Wraps:
# ur.pp(x, type = c("Z-alpha", "Z-tau"), model = c("constant",
# "trend"), lags = c("short", "long"), use.lag = NULL)
# FUNCTION:
# Compute:
x = as.vector(x)
urca = ur.pp(x, type = type[1], mode = model[1], lags = lags[1],
use.lag = use.lag)
output = capture.output(summary(urca))[-c(1:4, 7:10)]
for (i in 1:length(output)) output[i] = paste(" ", output[i])
output = output[-length(output)]
# Test Results:
ans = list(
name = "ur.pp",
test = urca,
output = output
)
# Plot:
if (doplot) plot(urca)
# Return Value:
new("fHTEST",
call = match.call(),
data = list(x = x),
test = ans,
title = "Phillips-Perron Unit Root Test",
description = description()
)
}
# ------------------------------------------------------------------------------
urspTest =
function(x, type = c("tau", "rho"), pol.deg = c(1, 2, 3, 4),
signif = c(0.01, 0.05, 0.10), doplot = TRUE)
{ # A function implemented by Diethelm Wuertz
# Description:
# Schmidt-Phillips test for unit roots
# Note:
# Requires "urca" which is not part of this distribution
# Wraps:
# ur.sp(y, type = c("tau", "rho"), pol.deg = c(1, 2, 3, 4),
# signif = c(0.01, 0.05, 0.1))
# FUNCTION:
# Compute:
x = as.vector(x)
urca = ur.sp(x, type = type[1], pol.deg = pol.deg[1], signif = signif[1])
output = capture.output(summary(urca))[-(1:8)]
output = output[-length(output)]
for (i in 1:length(output)) output[i] = paste(" ", output[i])
# Test Results:
ans = list(
name = "ur.pp",
test = urca,
output = output
)
# Plot:
if (doplot) plot(urca)
# Return Value:
new("fHTEST",
call = match.call(),
data = list(x = x),
test = ans,
title = "Schmidt-Phillips Unit Root Test",
description = description()
)
}
# ------------------------------------------------------------------------------
urzaTest =
function(x, model = c("intercept", "trend", "both"), lag = 2, doplot = TRUE)
{ # A function implemented by Diethelm Wuertz
# Description:
# Zivot-Andrews test for unit roots
# Note:
# Requires "urca" which is not part of this distribution
# Wraps:
# ur.za(y, model = c("intercept", "trend", "both"), lag)
# FUNCTION:
# Compute:
x = as.vector(x)
urca = ur.za(x, model = model[1], lag = lag)
output = capture.output(summary(urca))[-(1:8)]
output = output[-length(output)]
for (i in 1:length(output)) output[i] = paste(" ", output[i])
# Test Results:
ans = list(
name = "ur.pp",
test = urca,
output = output
)
# Plot:
if (doplot) plot(urca)
# Return Value:
new("fHTEST",
call = match.call(),
data = list(x = x),
test = ans,
title = "Zivot & Andrews Unit Root Test",
description = description()
)
}
################################################################################
|