Skip to content

Commit c581461

Browse files
committed
Review changes
1 parent 46ab7af commit c581461

File tree

3 files changed

+18
-14
lines changed

3 files changed

+18
-14
lines changed

src/StateSpaceModels.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ include("datasets.jl")
2222
include("hyperparameters.jl")
2323
include("systems.jl")
2424
include("kalman_filter_and_smoother.jl")
25-
include("kpss.jl") # For auto_arima
26-
include("canova_hensen.jl") # For auto_arima
25+
include("statistical_tests/kpss.jl")
26+
include("statistical_tests/canova_hensen.jl")
2727
include("filters/univariate_kalman_filter.jl")
2828
include("filters/multivariate_kalman_filter.jl")
2929
include("filters/scalar_kalman_filter.jl")

src/canova_hensen.jl renamed to src/statistical_tests/canova_hensen.jl

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,7 @@
1414
const CRIT_VALS_05 = [0.470, 0.749, 1.01, 1.24, 1.47, 1.68, 1.9, 2.11, 2.32, 2.54, 2.75, 2.96]
1515

1616
function crit_val_05_generalized_von_mises_distribution(s::Int)
17-
if s > 12
18-
return 0.269*s^0.928
19-
else
20-
return CRIT_VALS_05[s]
21-
end
17+
return s > 12 ? 0.269 * s^0.928 : CRIT_VALS_05[s]
2218
end
2319

2420
function π_statistic::Vector{Fl}, σ::Fl, T::Int) where Fl
@@ -38,25 +34,33 @@ function std_statistic(ε::Vector{Fl}, σ::Fl, T::Int, s::Int, j::Int) where Fl
3834
end
3935

4036
function test_statistic::Vector{Fl}, σ::Fl, T::Int, s::Int) where Fl
41-
# TODO we know this size a priori
42-
ω = Fl[]
43-
for j = 1:floor(Int, s/2) #check
44-
ω_j = j == s/2 ? π_statistic(ε, σ, T) : std_statistic(ε, σ, T, s, j)
45-
push!(ω, ω_j)
37+
# joint statistical test for all frequencies in
38+
# trigonometric pattern
39+
ω = 0
40+
# for each frequency in the trigonometric pattern
41+
for j = 1:floor(Int, s/2)
42+
ω += j == s/2 ? π_statistic(ε, σ, T) : std_statistic(ε, σ, T, s, j)
4643
end
47-
return sum(ω)
44+
return ω
4845
end
4946

5047
function build_std(T::Int, s::Int, j::Int)
48+
# add cossine and sine with frequency (2*pi*j)/s
49+
# to exogenous matrix X
5150
return hcat(cos.(λ(j, s)*(1:T)), sin.(λ(j, s)*(1:T)))
5251
end
5352

5453
function build_π(T::Int, s::Int, j::Int)
54+
# when j = s/2
55+
# add cossine with frequency pi and intercept
56+
# to exogenous matrix X
5557
return hcat(cos.(λ(j, s)*(1:T)), ones(T))
5658
end
5759

5860
function build_X(s::Int, T::Int, Fl::Type)
61+
# create the exogenous matrix
5962
X = Array{Fl, 2}(undef, T, s)
63+
# for each frequency in the trigonometric pattern
6064
for j = 1:floor(Int, s/2)
6165
X[:,[2*j-1, 2*j]] = j == s/2 ? build_π(T, s, j) : build_std(T, s, j)
6266
end
@@ -77,7 +81,7 @@ function seasonal_stationarity_test(y::Vector{Fl}, s::Int) where Fl
7781
res = ω - crit_val
7882
res > 0 ? println("Rejected seasonal stationarity at 5% significance level"*
7983
" Test Statistic: - Critical Value: $crit_val") :
80-
println("Didn't rejected seasonal stationarity at 5% significance level"*
84+
println("Didn't reject seasonal stationarity at 5% significance level"*
8185
" Test Statistic: - Critical Value: $crit_val")
8286
return res > 0 ? false : true
8387
end
File renamed without changes.

0 commit comments

Comments
 (0)