Skip to content

Commit

Permalink
Merge branch 'bugfix/fix-argname'
Browse files Browse the repository at this point in the history
  • Loading branch information
gretl-project committed Aug 4, 2020
2 parents 4a15c0b + 7adda74 commit 16ad24b
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 27 deletions.
46 changes: 34 additions & 12 deletions src/auto_arima.gfn
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,15 @@ Changelog:
- v0.6, August 2020:
+ Fix bug in print_table_and_row_labels(): wrong models where highlighted
as best ones.
+ Fix bug in get_auto_arima_parameters(): wrong n-th best model was retrieved.
+ Fix bug in get_auto_arima_parameters(): wrong n-th best model was
retrieved.
+ Fix minor bug in final_model_options_string(): verbosity option did not
work right.
+ Catch error when trying to retrieve information criteria in case model did
not converge and verbose == 0.
+ Add name of endogenous and xlist members when calling gui function.
+ Fix typos in help file.
+ Print name of endogenous and number of exogenous in summary printout
+ Unit-tests added and improved.

- v0.52, August 2020:
Expand Down Expand Up @@ -281,12 +288,11 @@ return cmd
<param name="with_intercept" type="bool" default="1" const="true">
<description>With intercept</description>
</param>
<param name="verbose" type="bool" default="1" const="true">
<param name="verbose" type="bool" default="0" const="true">
<description>Print details</description>
</param>
</params>
<code>/* Wrapper for GUI access. */
bundle model = null
bundle self = null
scalar self.verbose = verbose
scalar self.with_intercept = with_intercept
Expand Down Expand Up @@ -314,6 +320,8 @@ bundle model = auto_arima(y, xlist, self)
if model.error == TRUE
printError(&quot;something went wrong.&quot;)
else
string model.name_yseries = argname(y) # overwrite &quot;y&quot;
string model.name_xlist = (nelem(xlist)) ? argname(xlist) : &quot;&quot;
print_auto_arima_results(model)
endif
return model
Expand Down Expand Up @@ -586,6 +594,8 @@ print &quot;is, minimized) values of the respective information criteria, AIC =
print &quot;criterion, AICC = corrected AIC, BIC = Schwarz Bayesian criterion and&quot;
print &quot;HQC = Hannan-Quinn criterion across all ARIMA model specification.&quot;
printf &quot;\nCommon sample used for all models: %s to %s&quot;, self.sample_start, self.sample_end
printf &quot;\nName of endogenous: '%s'\n&quot;, self.name_yseries
printf &quot;Number of exogenous: %d\n&quot;, nelem(self.xlist)
</code>
</gretl-function>
<gretl-function name="print_table_border" type="void" private="1">
Expand Down Expand Up @@ -671,9 +681,14 @@ endloop
<params count="1">
<param name="self" type="bundle" const="true"/>
</params>
<code>/* code description
return: type, description */
return (self.verbose == 0) ? self.arima_model_options_string : (self.verbose == 1 ? &quot;--quiet&quot; : &quot;--verbose&quot;)
<code>/* Compile string with options for arima command. */
string s = self.arima_model_options_string
if self.verbose == 0
s += &quot; --quiet&quot;
elif self.verbose == 2
s += &quot; --verbose&quot;
endif
return s
</code>
</gretl-function>
<gretl-function name="arima_estimation_get_info_crits" type="matrix" private="1">
Expand All @@ -700,7 +715,10 @@ else
loop foreach i criteria_names
if criteria_names[i] != &quot;aicc&quot;
string crit = sprintf(&quot;$%s&quot;, criteria_names[i])
criteria_values[i] = @crit
catch criteria_values[i] = @crit
if $error
criteria_values[i] = NA
endif
else
criteria_values[i] = aicc($model)
endif
Expand All @@ -714,10 +732,14 @@ return criteria_values
<param name="model" type="bundle" const="true"/>
</params>
<code>/* Compute the corrected AIC criteria. */
scalar aic = model.aic
scalar n = model.T
scalar k = model.ncoeff
return aic + (2 * k * (k+1)) / (n-k-1)
scalar aicc = NA
if inbundle(model, &quot;aic&quot;) == TRUE
scalar aic = model.aic
scalar n = model.T
scalar k = model.ncoeff
aicc = aic + (2 * k * (k+1)) / (n-k-1)
endif
return aicc
</code>
</gretl-function>
<gretl-function name="set_sarima_parameters_to_nan" type="void" private="1">
Expand Down Expand Up @@ -874,7 +896,7 @@ if EXAMPLE == 1
list L = foo # add an exogenous

# Set &quot;max_p&quot; manually to 2
bundle Bout = auto_arima(lg, L, defbundle(&quot;verbose&quot;, 1, &quot;max_p&quot;, 2))
bundle Bout = auto_arima(lg, L, defbundle(&quot;verbose&quot;, 0, &quot;max_p&quot;, 2))

elif EXAMPLE == 2
series y = ldiff(gdp)
Expand Down
42 changes: 32 additions & 10 deletions src/auto_arima.inp
Original file line number Diff line number Diff line change
Expand Up @@ -309,13 +309,17 @@ function void print_summary_intro (const bundle self)
print "criterion, AICC = corrected AIC, BIC = Schwarz Bayesian criterion and"
print "HQC = Hannan-Quinn criterion across all ARIMA model specification."
printf "\nCommon sample used for all models: %s to %s", self.sample_start, self.sample_end

printf "\nName of endogenous: '%s'\n", self.name_yseries
printf "Number of exogenous: %d\n", nelem(self.xlist)
end function


function void print_table_border (void)
printf "\n**********************************************************************************\n"
end function


function void print_table_header (void)
strings criteria_names = get_info_criteria_names()

Expand All @@ -330,6 +334,7 @@ function void print_table_header (void)
printf "\n----------------------------------------------------------------------------------\n"
end function


function void print_auto_arima_results (const bundle self)
/* Summarize parameter results for each information criteria. */

Expand Down Expand Up @@ -436,10 +441,17 @@ end function


function string final_model_options_string (const bundle self)
/* code description
return: type, description */
/* Compile string with options for arima command. */

return (self.verbose == 0) ? self.arima_model_options_string : (self.verbose == 1 ? "--quiet" : "--verbose")
string s = self.arima_model_options_string

if self.verbose == 0
s += " --quiet"
elif self.verbose == 2
s += " --verbose"
endif

return s
end function


Expand Down Expand Up @@ -468,7 +480,10 @@ function matrix arima_estimation_get_info_crits (const series y,
loop foreach i criteria_names
if criteria_names[i] != "aicc"
string crit = sprintf("$%s", criteria_names[i])
criteria_values[i] = @crit
catch criteria_values[i] = @crit
if $error
criteria_values[i] = NA
endif
else
criteria_values[i] = aicc($model)
endif
Expand All @@ -482,11 +497,17 @@ end function
function scalar aicc (const bundle model)
/* Compute the corrected AIC criteria. */

scalar aic = model.aic
scalar n = model.T
scalar k = model.ncoeff
scalar aicc = NA

if inbundle(model, "aic") == TRUE
scalar aic = model.aic
scalar n = model.T
scalar k = model.ncoeff

aicc = aic + (2 * k * (k+1)) / (n-k-1)
endif

return aic + (2 * k * (k+1)) / (n-k-1)
return aicc
end function


Expand Down Expand Up @@ -634,10 +655,9 @@ function bundle auto_arima_gui (const series y "Endogenous",
const int min_Q[0::0] "min. seas. MA order parameter, Q",
const int max_Q[0::0] "max. seas. MA order parameter, Q",
const bool with_intercept[1] "With intercept",
const bool verbose[1] "Print details")
const bool verbose[0] "Print details")
/* Wrapper for GUI access. */

bundle model = null
bundle self = null
scalar self.verbose = verbose
scalar self.with_intercept = with_intercept
Expand Down Expand Up @@ -668,6 +688,8 @@ function bundle auto_arima_gui (const series y "Endogenous",
if model.error == TRUE
printError("something went wrong.")
else
string model.name_yseries = argname(y) # overwrite "y"
string model.name_xlist = (nelem(xlist)) ? argname(xlist) : ""
print_auto_arima_results(model)
endif

Expand Down
9 changes: 8 additions & 1 deletion src/auto_arima_help.txt
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,15 @@ Changelog:
- v0.6, August 2020:
+ Fix bug in print_table_and_row_labels(): wrong models where highlighted
as best ones.
+ Fix bug in get_auto_arima_parameters(): wrong n-th best model was retrieved.
+ Fix bug in get_auto_arima_parameters(): wrong n-th best model was
retrieved.
+ Fix minor bug in final_model_options_string(): verbosity option did not
work right.
+ Catch error when trying to retrieve information criteria in case model did
not converge and verbose == 0.
+ Add name of endogenous and xlist members when calling gui function.
+ Fix typos in help file.
+ Print name of endogenous and number of exogenous in summary printout
+ Unit-tests added and improved.

- v0.52, August 2020:
Expand Down
2 changes: 1 addition & 1 deletion src/auto_arima_sample.inp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ if EXAMPLE == 1
list L = foo # add an exogenous

# Set "max_p" manually to 2
bundle Bout = auto_arima(lg, L, defbundle("verbose", 1, "max_p", 2))
bundle Bout = auto_arima(lg, L, defbundle("verbose", 0, "max_p", 2))

elif EXAMPLE == 2
series y = ldiff(gdp)
Expand Down
8 changes: 5 additions & 3 deletions tests/run_tests.inp
Original file line number Diff line number Diff line change
Expand Up @@ -395,19 +395,19 @@ function void test_final_model_options_string (void)
scalar B.verbose = 0
string B.arima_model_options_string = "some_string"
string r = final_model_options_string(B)
assert_equal_str(strstrip(r), "some_string")
assert_equal_str(strstrip(r), "some_string --quiet")

bundle B = null
scalar B.verbose = 1
string B.arima_model_options_string = "some_string"
string r = final_model_options_string(B)
assert_equal_str(strstrip(r), "--quiet")
assert_equal_str(strstrip(r), "some_string")

bundle B = null
scalar B.verbose = 2
string B.arima_model_options_string = "some_string"
string r = final_model_options_string(B)
assert_equal_str(strstrip(r), "--verbose")
assert_equal_str(strstrip(r), "some_string --verbose")
end function
test_final_model_options_string()

Expand Down Expand Up @@ -809,6 +809,8 @@ function void test_print_summary_intro (void)
print "Start testing print_summary_intro()"

bundle B = null
string B.name_yseries = "endog"
list B.xlist = null
string B.sample_start = "2020-01-01"
string B.sample_end = "2020-07-31"

Expand Down

0 comments on commit 16ad24b

Please sign in to comment.