Skip to content

Commit 1859591

Browse files
author
LuizFCDuarte
committed
✨ Change default seasonal statistical test to ocsb
1 parent 9a5cee1 commit 1859591

File tree

4 files changed

+17
-59
lines changed

4 files changed

+17
-59
lines changed

src/models/sarima.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1365,7 +1365,7 @@ function auto(
13651365
allowMean::Union{Bool,Nothing} = nothing,
13661366
allowDrift::Union{Bool,Nothing} = nothing,
13671367
integrationTest::String = "kpss",
1368-
seasonalIntegrationTest::String = "seas",
1368+
seasonalIntegrationTest::String = "ocsb",
13691369
objectiveFunction::String = "mse",
13701370
assertStationarity::Bool = true,
13711371
assertInvertibility::Bool = true,
@@ -1386,8 +1386,8 @@ function auto(
13861386
@assert maxD >= 0
13871387
@assert maxQ >= 0
13881388
@assert informationCriteria ["aic", "aicc", "bic"]
1389-
@assert integrationTest ["kpss", "kpssR"]
1390-
@assert seasonalIntegrationTest ["seas", "ch", "ocsb", "ocsbR"]
1389+
@assert integrationTest ["kpss"]
1390+
@assert seasonalIntegrationTest ["seas", "ch", "ocsb"]
13911391
@assert objectiveFunction ["mae", "mse", "ml", "bilevel", "lasso", "ridge"]
13921392
@assert searchMethod ["stepwise", "stepwiseNaive", "grid"]
13931393

src/utils.jl

Lines changed: 10 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -194,40 +194,7 @@ function selectSeasonalIntegrationOrder(
194194
elseif test == "ch"
195195
return StateSpaceModels.canova_hansen_test(y, seasonality)
196196
elseif test == "ocsb"
197-
try
198-
if !("PyCall" keys(Pkg.project().dependencies))
199-
# Warning message
200-
@warn "The PyCall package is not installed. Please install it to use the 'ocsb' test."
201-
@warn "Using the 'seas' test instead."
202-
return StateSpaceModels.seasonal_strength_test(y, seasonality)
203-
end
204-
205-
return Sarimax.seasonal_diffs(y, seasonality)
206-
catch e
207-
println(e)
208-
throw(
209-
Error(
210-
"It seems that the pmdarima package is not installed. Please install it to use the 'ocsb' test.",
211-
),
212-
)
213-
end
214-
elseif test == "ocsbR"
215-
try
216-
if !("RCall" keys(Pkg.project().dependencies))
217-
# Warning message
218-
@warn "The RCall package is not installed. Please install it to use the 'ocsbR' test."
219-
@warn "Using the 'seas' test instead."
220-
return StateSpaceModels.seasonal_strength_test(y, seasonality)
221-
end
222-
return Sarimax.seasonal_diffsR(y, seasonality)
223-
catch e
224-
println(e)
225-
throw(
226-
Error(
227-
"It seems that the R forecast package is not installed. Please install it to use the 'ocsbR' test.",
228-
),
229-
)
230-
end
197+
return ocsb_test(y;m=seasonality)["seasonal_difference"]
231198
end
232199
throw(ArgumentError("The test $test is not supported"))
233200
end
@@ -260,23 +227,13 @@ function selectIntegrationOrder(
260227
) where {Fl<:AbstractFloat}
261228
if test == "kpss"
262229
return StateSpaceModels.repeated_kpss_test(y, maxd, D, seasonality)
263-
elseif test == "kpssR"
264-
try
265-
if !("RCall" keys(Pkg.project().dependencies))
266-
# Warning message
267-
@warn "The RCall package is not installed. Please install it to use the 'kpssR' test."
268-
@warn "Using the 'kpss' test instead."
269-
return StateSpaceModels.repeated_kpss_test(y, maxd, D, seasonality)
230+
elseif test == "kpssSarimax"
231+
for d in 0:maxd
232+
diffSeries = differentiate(y, d, D, seasonality)
233+
result = kpss_test(diffSeries)
234+
if result["p_value"] <= 0.05
235+
return d
270236
end
271-
272-
return Sarimax.kpssR(y, maxd, D, seasonality)
273-
catch e
274-
println(e)
275-
throw(
276-
ArgumentError(
277-
"It seems that the R forecast package is not installed. Please install it to use the 'kpssR' test.",
278-
),
279-
)
280237
end
281238
end
282239

@@ -291,7 +248,7 @@ Automatically applies differentiation to each series in a TimeArray.
291248
# Arguments
292249
- `series::TimeArray`: The input TimeArray containing the time series data.
293250
- `seasonalPeriod::Int=1`: The seasonal period of the time series.
294-
- `seasonalIntegrationTest::String="seas"`: The test used to select the seasonal integration order.
251+
- `seasonalIntegrationTest::String="ocsb"`: The test used to select the seasonal integration order.
295252
- `integrationTest::String="kpss"`: The test used to select the integration order.
296253
- `maxd::Int=2`: The maximum order of differencing to consider.
297254
@@ -307,12 +264,12 @@ Throws an AssertionError if invalid test options or seasonal period are provided
307264
function automaticDifferentiation(
308265
series::TimeArray;
309266
seasonalPeriod::Int = 1,
310-
seasonalIntegrationTest::String = "seas",
267+
seasonalIntegrationTest::String = "ocsb",
311268
integrationTest::String = "kpss",
312269
maxd::Int = 2,
313270
)
314271
@assert integrationTest ["kpss"]
315-
@assert seasonalIntegrationTest ["seas", "ch"]
272+
@assert seasonalIntegrationTest ["seas", "ch", "ocsb"]
316273
@assert seasonalPeriod 1
317274

318275
diffSeriesVector::Array{TimeArray} = []

test/models/sarima.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
@test mean(modeloLog.ϵ) 0 atol = 1e-1
3030

3131
autoModelML = auto(airPassengersLog; seasonality = 12, objectiveFunction = "ml")
32-
@test autoModelML.d == 0 # Output of forecast package in R
33-
@test autoModelML.D == 1 # Output of forecast package in R
32+
@test autoModelML.d == 1 # Output of forecast package in R
33+
@test autoModelML.D == 0 # Output of forecast package in R
3434

3535
simulation = simulate(modeloLog, 10, 301)
3636
@test length(simulation) == 301

test/models/sarima_fit.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,8 @@ end
121121
showLogs = true,
122122
)
123123

124-
@test modelAutoExog.D != modelAuto.D
124+
@test modelAutoExog.D == 0
125+
@test modelAuto.D == 0
125126

126127
modelAutoFixedD = auto(
127128
airPassengersLog;

0 commit comments

Comments
 (0)