14
14
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 ]
15
15
16
16
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]
22
18
end
23
19
24
20
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
38
34
end
39
35
40
36
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)
46
43
end
47
- return sum (ω)
44
+ return ω
48
45
end
49
46
50
47
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
51
50
return hcat (cos .(λ (j, s)* (1 : T)), sin .(λ (j, s)* (1 : T)))
52
51
end
53
52
54
53
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
55
57
return hcat (cos .(λ (j, s)* (1 : T)), ones (T))
56
58
end
57
59
58
60
function build_X (s:: Int , T:: Int , Fl:: Type )
61
+ # create the exogenous matrix
59
62
X = Array {Fl, 2} (undef, T, s)
63
+ # for each frequency in the trigonometric pattern
60
64
for j = 1 : floor (Int, s/ 2 )
61
65
X[:,[2 * j- 1 , 2 * j]] = j == s/ 2 ? build_π (T, s, j) : build_std (T, s, j)
62
66
end
@@ -77,7 +81,7 @@ function seasonal_stationarity_test(y::Vector{Fl}, s::Int) where Fl
77
81
res = ω - crit_val
78
82
res > 0 ? println (" Rejected seasonal stationarity at 5% significance level" *
79
83
" 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" *
81
85
" Test Statistic: $ω - Critical Value: $crit_val " )
82
86
return res > 0 ? false : true
83
87
end
0 commit comments