swh:1:snp:3a44eb759780145deea094ac2a25c5049546a085
Tip revision: c2f8f5dad0723f8b0e85fd9fe7602962777136ef authored by Han Lin Shang on 04 June 2010, 13:24:11 UTC
version 1.8
version 1.8
Tip revision: c2f8f5d
ndiffs.r
ndiffs = function (x, alpha = 0.05)
{
require(tseries)
x <- c(na.omit(c(x)))
d <- 0
oldwarn <- options(warn = -1)
p.v <- kpss.test(x)$p.value
if (is.na(p.v)) {
options(warn = oldwarn$warn)
return(d)
}
while (p.v < alpha & d < 2) {
x <- diff(x)
d <- d + 1
p.v <- kpss.test(x)$p.value
if (is.na(p.v))
return(d - 1)
}
options(warn = oldwarn$warn)
return(d)
}