Ankur Goel

On hunt of awesomeness!

Statsample - Wald Test

Hi everyone,
After completing and verifying the integrity of all tests and Ruby versions, I and Claudio started with implementation of Wald Test. He explained it pretty well and was very patient. :)

Wald test is used to test if a series of n acf or pacf indeces are equal to 0.
For acf, the distribution for a white noise sationary process are approximately independent and identically distributed normal random variables with mean 0 and variance n-1.

What that means is, if terms in an acf of a timeseries with k lags are squared and added (sum-of-squares), then that statistic is chi-square distributed over degree of freedom, directly dependent on the k number of lags.

I will demonstrate this with example:

1
2
3
4
5
6
7
8
9
10
11
12
#Create time series

require 'statsample'
include Statsample::TimeSeries
series = (1..30).map { rand(100) }.to_time_series

#find and stores it acf with specific lags
k = 10
series_acf = series.acf(k)

#find sum of squares for series_acf using powerful Ruby map and inject.
sum_of_sq = series_acf.map { |x| x ** 2 }.inject(:+)

So far, we have managed to find the sum of squares of a acf-series with k = 10 = number of lags.
Now, we will check whether or not it is less than quantile 0.95 of a chi-square with k degree of freedom.

For that, include Distribution as:

1
2
3
4
5
6
7
#continuing from last snippet

include Distribution
cdf = ChiSquare.cdf(sum_of_sq, k)

cdf >= 0.05
#=> True

This verifies the Wald test.

The tests can be found on Github repository at: https://github.com/AnkurGel/statsample/blob/master/test/test_wald2.rb

Cheers,
Ankur Goel