Skip to content

timeseries: R/S (rescaled range) analysis

3 messages · Jeff Haferman, Christoph Helwig

#
Has anyone written utilities to do rescaled range analysis in R?

Jeff

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
Christoph,
Yes, thank you very much, this is exactly what I was
looking for.  Thanks also for the added bonus with the V/S test
and reference, this is the first I've seen of that.

[and for yet another method, see
http://nsr.bioeng.washington.edu/Software/NSR_SW_fractal.html
especially the "disp" link for "dispersion analysis]

Jeff

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
Jeff Haferman wrote:
What do you mean by R/S analysis? Testing for long memory, estimating H?
If you want to do tests, have a look at the functions below. They are
quite `raw' but were just written for my personal usage. So don?t be to
critical.

Hope that helps.

Christoph

## rs.test calculates the statistic of the modified R/S test
##
## x: time series
## q: number of lags included for calculation of covariances
##
## significance level: 0.05,     0.1
## critical value:     1.747,    1.62
##
## References: Lo (1991), Long-term Memory in Stock Market Prices,
Econometrica 59, 1279--1313
##
rs.test <- function(x, q, alpha)
{	
	xbar <- mean(x)
	N <- length(x)
	r <- max(cumsum(x-xbar)) - min(cumsum(x-xbar))
	kovarianzen <- NULL
	for (i in 1:q)
	{	
		kovarianzen <- c(kovarianzen,
sum((x[1:(N-i)]-xbar)*(x[(1+i):N]-xbar)))
	}
	if (q > 0)
		s <- sum((x-xbar)^2)/N + sum((1-(1:q)/(q+1))*kovarianzen)*2/N
	else
		s <- sum((x-xbar)^2)/N
	rs <- r/(sqrt(s)*sqrt(N))
	method <- "R/S Test for Long Memory"
	names(rs) <- "R/S Statistic"
	names(q) <- "Bandwidth q"
	structure(list(statistic = rs, parameter = q, method = method,
data.name=deparse(substitute(x))), class="htest")
}

## vs.test calculates the statistic of the modified V/S test
##
## x: time series
## q: number of lags included for calculation of covariances
## 
## significance level: 0.01,   0.05,     0.1
## critical value:     0.2685, 0.1869,   0.1518
##
## References: Giraitis, Kokoszka und Leipus (2000), Rescaled variance
and related tests for long memory in volatility and levels
##
vs.test <- function(x, q, alpha)
{	
	xbar <- mean(x)
	N <- length(x)
	v <- sum((cumsum(x-xbar))^2) - (sum(cumsum(x-xbar)))^2/N
	kovarianzen <- NULL
	for (i in 1:q)
	{	
		kovarianzen <- c(kovarianzen,
sum((x[1:(N-i)]-xbar)*(x[(1+i):N]-xbar)))
	}
	if (q > 0)
		s <- sum((x-xbar)^2)/N + sum((1-(1:q)/(q+1))*kovarianzen)*2/N
	else
		s <- sum((x-xbar)^2)/N
	vs <- v/(s*N^2)
	method <- "V/S Test for Long Memory"
	names(vs) <- "V/S Statistic"
	names(q) <- "Bandwidth q"
	structure(list(statistic = vs, parameter = q, method = method,
data.name=deparse(substitute(x))), class="htest")
}


-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-