Stochastic processes I

The ASTA team

Introduction to stochastic processes

Data examples

CBEdata <- read.table("https://asta.math.aau.dk/eng/static/datasets?file=cbe.dat", header = TRUE)
CBE <- ts(CBEdata[,3])
plot(CBE, ylab="GWh",main="Electricity production")

dat<-ts(co2)
plot(co2)

Stochastic processes

Important stochastic processes

Example 1: White noise

x = rnorm(1000,0,1) 
ts.plot(x, main = "Simulated Gaussian white noise process")

Example 2: Random walk

x = matrix(0,1000,5)
for (i in 1:5) x[,i] = cumsum(rnorm(1000,0,1))
ts.plot(x,col=1:5)

Example 3: First order autoregressive process

w = ts(rnorm(1000))
x1 = filter(w,0.5,method="recursive")
x2 = filter(w,0.9,method="recursive")
x3 = filter(w,0.99,method="recursive")
ts.plot(x1,x2,x3,col=1:3)

Mean, autocovariance and stationarity

Mean function

plot(CBE,main="Electricity production")

Autocovariance/autocorrelation functions

Stationarity

Stationarity and autocorrelation - example

h = 0:20
acf1 = 0^h  # AR(1) with alpha = 0 (or white noise)
acf2 = 0.5^h  # AR(1) with alpha = 0.5
acf3 = 0.9^h  # AR(1) with alpha = 0.9
plot(matrix(rep(h,3),3),cbind(acf1,acf2,acf3),col=rep(1:3,each=length(h)),
     pch=rep(1:3,each = length(h)),xlab="h",ylab="ACF")

Estimation

Estimation

The correlogram

White noise:

w = ts(rnorm(100))
par(mfrow=c(1,2))
plot(w)
acf(w)

w = ts(rnorm(100))
x1 = filter(w,0.9,method="recursive")
par(mfrow=c(1,2))
plot(x1)
acf(x1)

Non-stationary data

Check for stationarity

Correlograms for non-stationary data

w = ts(rnorm(100))
x1 = 5*sin(0.5*(1:100)) + w
par(mfrow=c(1,2))
plot(x1)
acf(x1)

w = ts(rnorm(100))
x1 = 0.1*(1:100) + w
par(mfrow=c(1,2))
plot(x1)
acf(x1)

par(mfrow=c(1,2))
plot(CBE)
acf(CBE)

Detrending data

CBE <- ts(CBE,frequency=12)
plot(decompose(CBE))

logCBE <- ts(log(CBEdata[,3]),frequency=12)
plot(decompose(logCBE))

random<-decompose(logCBE)$random[7:382]
acf(random, main="Random part of CBE data")