# A random walk ? What else ?

Consider the following time series,

What does it look like ? I know, this is a stupid game, but I keep using it in my time series courses. It does look like a random walk, doesn’t it ? If we use Philipps-Perron test, yes, it does,

> PP.test(x)

Phillips-Perron Unit Root Test

data:  x
Dickey-Fuller = -2.2421, Truncation lag parameter = 6, p-value = 0.4758

If we look at the autocorrelation function, we do observe some persistence,

> acf(x,100)

Perhaps this persistence can be related to long range dependence, or to some fractional random walk. A natural idea could be estimate Hurst parameter, using for instance Beran (1992) estimator – based on Whittle (1956) – where we assume that the autocorrelation function satisfies

$\rho(h)=\text{cor}(X_t,X_{t-h})\sim \alpha |h|^{2H-2}$

as $h\rightarrow\infty$ for some $H\in(1/2,1)$ (the so called Hurst index). But here, we start to observe unexpected ouputs,

> library(longmemo)
> (d  <- WhittleEst(x))
'WhittleEst' Whittle estimator for  fractional Gaussian noise ('fGn');	 call:
WhittleEst(x = x)
time series of length  n = 759.

H = 0.9899335
coefficients 'eta' =
Estimate Std. Error z value   Pr(>|z|)
H 0.98993350 0.02468323 40.1055 < 2.22e-16
<==> d := H - 1/2 = 0.49 (0.025)

$vcov : num [1, 1] 0.000609 ..- attr(*, "dimnames")=List of 2 .. ..$ : chr "H"
.. ..$: chr "H"$ periodogr.x: num [1:379] 1479.3 1077.3 371.7 287.2 51.2 ...
\$ spec       : num [1:379] 62.5 31.7 21.3 16.1 12.9 ...

or more precisely some non-expected values for Hurst parameter, which should be in $(1/2,1)$

> confint(d)
2.5 %   97.5 %
H 0.9415553 1.038312

Oops, perhaps, we did miss something, because it looks like there is extremely strong persistence on our time series,

> plot(d)

It is probablty time to ask where I found that series… To be honest, I did borrow  it from a great canadian website http://climate.weatheroffice.gc.ca/climateData/. For instance, it you want the temperature we did experience a few days ago, you can use

> Y=2013
> M=1
> D=25
> url=paste(
"http://climate.weatheroffice.gc.ca/climateData/hourlydata_e.html?
timeframe=1&Prov=QC&StationID=5415&hlyRange=1953-01-01|2013-02-
01&Year=",Y,"&Month=",M,"&Day=",D,sep="")
> page=scan(url,what="character")

Yes, that series is the temperature we did experience in Montréal last month (hourly time seies). On the graph below, you can actually compare it with temperature experienced in Januarys over the past 60 years,

So it is not that surprising to see long range dependence models appearing (I did write a paper on that topic precisely a few years ago). What I found puzzeling is that persistence is large, extremely large. And the problem is that I do not see how we can explain ‘jumps’ that we do observe on that series. For instance the behavior of the series while I was in Europe, before January 20th: within 3 days, the temperature went down, from 0°C to -20°C, and up from -20°C to 0°C, and then down again, from 0°C to -20°C (a nice И if we use cyrillic letters). Or how can we explain the oscillating behavior observed the week after, where the temperature went up, from -25°C to (almost) +10°C in a few days. Within 10 days, we did observe also two ‘jumps’ (or ‘crashes‘ if we want to use the terminology of financial time series) with a decrease of 25 degrees in less than 24 hours ! Obviously, we need to find other classes of model to replicate that kind of behavior we observe on temperatures…

Cite this blog post
Arthur Charpentier (2013, February 2). A random walk ? What else ? Freakonometrics. Retrieved June 25, 2024, from https://doi.org/10.58079/ouou

## 7 thoughts on “A random walk ? What else ?”

1. Felix Dietrich says:

Hi Arthur!

I have done the same for a random walk:
x <- rnorm(1000)
y <- cumsum(x)
WhittleEst(y)

Gives me the same Hurst exponent… 0.9899413

2. KL says:

les bonds que tu mentionnes, c’est de ça que je voulais (maladroitement) parler l’autre fois, i.e. est-ce que le moment ou ils arrivent est totalement imprévisible; ici ça semble être le cas…peut-être si on avait une (ou plusieurs?) autre série corrélée

3. Ken Butler says:

My recollection is that failing to reject with the Dickey-Fuller test indicates problems with non-stationarity, and that could be the reason for the very slowly-decaying autocorrelations. Does your Montreal temperature data behave better if you take differences?

(I meant to try it myself, copying your code, but my variable “page” was full of html, and I didn’t see how you had extracted the data from that.)

1. Actually, one can easily play with html code, since the structure of the page is always (exactly) the same. With the following code, you can extract the temperature (I guess much more efficient codes can be produced)

> extracttemp=function(Y,M,D){
+ nom=paste("http://climate.weatheroffice.gc.ca/climateData/
hourlydata_e.html?timeframe=1&Prov=QC&StationID=5415&hlyRange=
1953-01-01|2013-02-01&Year=",Y,"&Month=
",M,"&Day=",D,sep="")
+ html=scan(nom,what="character")
+ html0=html[1850:length(html)]
+ nl=pmin(nchar(html0),27)
+ TEMP=html[1850+heure+1]
+ HEURE=0:23
+ sTEMP=strsplit(TEMP,">")
+ for(i in 1:24){
+ v=sTEMP[[i]]
+ TEMP[i]=as.numeric(substr(v[2],1,nchar(v[2])-4))
+ }
+ basejour=data.frame(Year=Y,Month=M,Day=D,
+ Hour=HEURE,Temp=as.numeric(TEMP))
+ return(basejour)}
> extracttemp(2013,1,19)

For instance,

> extracttemp(2013,1,23)
Year Month Day Hour  Temp
1  2013     1  23    0 -22.0
2  2013     1  23    1 -23.1
3  2013     1  23    2 -23.8
4  2013     1  23    3 -24.5
5  2013     1  23    4 -25.2
6  2013     1  23    5 -25.9
7  2013     1  23    6 -26.5
8  2013     1  23    7 -26.8
9  2013     1  23    8 -27.1
10 2013     1  23    9 -26.8
11 2013     1  23   10 -26.2
12 2013     1  23   11 -25.6
13 2013     1  23   12 -24.4
14 2013     1  23   13 -23.7
15 2013     1  23   14 -23.3
16 2013     1  23   15 -22.8
17 2013     1  23   16 -22.8
18 2013     1  23   17 -23.2
19 2013     1  23   18 -23.5
20 2013     1  23   19 -23.5
21 2013     1  23   20 -23.8
22 2013     1  23   21 -23.8
23 2013     1  23   22 -24.0
24 2013     1  23   23 -24.0

This site uses Akismet to reduce spam. Learn how your comment data is processed.