Skip to content

ENH: Zivot-Andrews unit-root test (issue 4746) - #5455

Closed
JimVaranelli wants to merge 20 commits into
statsmodels:masterfrom
JimVaranelli:issue4746
Closed

JimVaranelli wants to merge 20 commits into
statsmodels:masterfrom
JimVaranelli:issue4746

Conversation

@JimVaranelli

Copy link
Copy Markdown
Contributor

Initial commit for Zivot-Andrews structural-break unit-root test (issue 4746).

@JimVaranelli

Copy link
Copy Markdown
Contributor Author

Even after ensuring my fork was synced I still get this merge error. Very annoying.

@josef-pkt

Copy link
Copy Markdown
Member

my guess is that you didn't branch off current master. (github doesn't show the parent of a branch or commit anymore.)
Maybe you started with an outdated local master checkout, or/and didn't fetch from github in some time.

BTW it is better to also add the topic to the branch name instead of just the issue number. That makes it easier to keep track of branches locally.
e.g. my local branch of the White PR us white_spec_5452_rebased

@josef-pkt

Copy link
Copy Markdown
Member

Checking the history of this branch locally:
The branch of this PR is based on master from May 29, 2018, the same as the initial White spec PR

@JimVaranelli

Copy link
Copy Markdown
Contributor Author

OK I'll use the more informative branch name. I forced the most recent checkout of the two conflict files and merged in my changes and pushed the commit but I am still seeing the merge conflict. And the 'Resolve Conflicts' button just spins and never shows the conflict.

@josef-pkt

Copy link
Copy Markdown
Member

To resolve the merge conflicts and update to current master we use rebase. We avoid merging master into a feature branch because it makes the commit history messy and more difficult to work with.

>git rebase remotes/origin/master

where origin is my shortcut to statsmodels/statsmodels official repo

@josef-pkt

Copy link
Copy Markdown
Member

Also we are not using @ for dot yet. (It will be available after dropping 2.7 and 3.4)

@JimVaranelli

Copy link
Copy Markdown
Contributor Author

OK I will change the @ back to dot.

I rebased but it is still showing the conflict here???????

@JimVaranelli

Copy link
Copy Markdown
Contributor Author

It looks like the merge conflict is finally fixed with the @/dot change. The issue most likely traces back to cloning the incorrect version of master (5/29/18 instead of 1/9/19). What is the correct command to use when cloning a new branch to ensure the most recent commits are included?

@coveralls

coveralls commented Jan 10, 2019 •

Copy link
Copy Markdown

Coverage Status

Coverage increased (+0.05%) to 85.042% when pulling a8efc8d on JimVaranelli:issue4746 into 321619e on statsmodels:master.

@JimVaranelli

Copy link
Copy Markdown
Contributor Author

Finally got a clean build. The appveyor failure appears to be unrelated to this PR. Let me know if there is anything further I should do.

Comment thread statsmodels/tsa/stattools.py Resolved
Comment thread statsmodels/tsa/stattools.py Resolved
Comment thread statsmodels/tsa/stattools.py Resolved
@codecov

codecov Bot commented May 28, 2019 •

Copy link
Copy Markdown

Codecov Report

Merging #5455 into master will increase coverage by 0.03%.
The diff coverage is 96.89%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #5455      +/-   ##
==========================================
+ Coverage   82.46%   82.49%   +0.03%     
==========================================
  Files         595      595              
  Lines       93776    93894     +118     
  Branches    10353    10364      +11     
==========================================
+ Hits        77333    77462     +129     
+ Misses      14046    14031      -15     
- Partials     2397     2401       +4
Impacted Files Coverage Δ
statsmodels/tsa/tests/test_stattools.py 98.99% <100%> (+0.06%) ⬆️
statsmodels/tsa/stattools.py 90.38% <95.65%> (+2.37%) ⬆️
statsmodels/sandbox/distributions/extras.py 60.61% <0%> (-0.37%) ⬇️
statsmodels/miscmodels/tmodel.py 87.01% <0%> (-0.17%) ⬇️
...tsmodels/sandbox/nonparametric/densityorthopoly.py 0% <0%> (ø) ⬆️
statsmodels/discrete/tests/test_constrained.py 90.6% <0%> (ø) ⬆️
statsmodels/tsa/filters/_utils.py 42.5% <0%> (ø) ⬆️
statsmodels/sandbox/distributions/mv_normal.py 39.21% <0%> (ø) ⬆️
statsmodels/sandbox/distributions/genpareto.py 0% <0%> (ø) ⬆️
statsmodels/sandbox/tsa/example_arma.py 0% <0%> (ø) ⬆️
... and 19 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 321619e...a8efc8d. Read the comment docs.

@pep8speaks

pep8speaks commented May 28, 2019 •

Copy link
Copy Markdown

Hello @JimVaranelli! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻

Comment last updated at 2019-05-31 18:44:34 UTC

@JimVaranelli

Copy link
Copy Markdown
Contributor Author

Fixed the Codacy white space issue. Should have a clean merge now.

@josef-pkt

Copy link
Copy Markdown
Member

this might still need a clean rebase on current master (with possibly some squashing)
I didn't check locally how the commits look like.

Comment thread statsmodels/tsa/stattools.py Outdated
self._za_critical_values['t'] = np.asarray(self._t)
# constant + trend model
self._ct = ((0.001, -38.17800), (0.100, -6.43107), (0.200, -6.07279),
(0.300, -5.95496), (0.400, -5.86254), (0.500, -5.77081),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check indentation. if you're not familiar with the convention, you can run flake8 --isolated statsmodels/tsa/stattools.py and ignore all the alerts for the rest of the module.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are these actually needed as attributes of self?

If these attributes are identical across all instances and never edited, no need to bother with __init__, just put them as class attributes

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. I fixed the indentation although there seems to be some ambiguity between the different style parsers. The form I used (which seems to be the most preferred) is:
    list = (
    (x1,y1), ...
    (x2,y2), ...
    )

  2. I originally used init for the CV list specifically in case there is ever a desire/need to split out the routine as a base class then inherit for different distributions. The question of class attribute vs object attribute is not too important here since the use model (in a single-threaded context) is to instantiate once then re-use the object for multiple runs as opposed to instantiating a new object for each run. I left it as is for now but can certainly update if there is a strong preference.

Comment thread statsmodels/tsa/stattools.py Outdated
cv = [1.0, 5.0, 10.0]
crit_value = np.interp(cv, y, x)
cvdict = {"1%" : crit_value[0], "5%" : crit_value[1],
"10%" : crit_value[2]}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no space before colon

are there other names besides x, y that might be more informative? one-letter names make it tough to search a file for all-places-this-is-used

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed the colon spacing and renamed to (pcnts, stats) rather than (x, y).

raise ValueError(
'ZA: auxiliary exog matrix is not full rank.\n \
cols (exc intercept) = {} rank = {}'.format(
exog.shape[1] - 1, o.df_model))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using modern string formatting here is nice, can you do the same above?

Also can you avoid the backslash and instead put single-quotes on both lines

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the other string formatting commands and removed the '' as above.

'ZA: trim value must be a float in range [0, 0.333]')
x = np.asarray(x)
if x.ndim > 2 or (x.ndim == 2 and x.shape[1] != 1):
raise ValueError(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

quick tests for the failure modes?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added failure mode tests to test_stattools.py.

exog[:, 1] = t_const[(baselags + 2):(nobs + 1)]
exog[:(cutoff-1), 2] = 0
exog[(cutoff-1):, 2] = t_const[0:(nobs - bp + 1)]
# check exog rank on first iteration

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this method is doing a lot. are there any reasonable sub-scopes it could be split into?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Split off the endog/exog creation/updating into two separate helper functions.

Comment thread statsmodels/tsa/tests/test_stattools.py Resolved
Comment thread statsmodels/tsa/tests/test_stattools.py Resolved
Comment thread statsmodels/tsa/tests/test_stattools.py Outdated
assert_almost_equal(res[0], -3.48223, decimal=3)
assert_almost_equal(res[1], 0.69111, decimal=3)
assert_equal(res[3], 25)
assert_equal(res[4], 7071)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these should probably be 5 separate tests in a test class

for scalars assert_equal(res[3], 25) can just be assert res[3] == 25

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to a test class and switched to assert_allclose (see below).

Comment thread statsmodels/tsa/tests/test_stattools.py Outdated
else:
res = zivot_andrews(mdl, regression='c', autolag='t-stat')
assert_almost_equal(res[0], -3.48223, decimal=3)
assert_almost_equal(res[1], 0.69111, decimal=3)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

im pretty sure assert_allclose is preferred to assert_almost_equal

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now using assert_allclose.

@JimVaranelli

Copy link
Copy Markdown
Contributor Author

Looks like the merge should be OK now. Not sure why the Mac 2.7 pytest failed as the log was empty. I'll crank the rest of these out today.

@JimVaranelli

Copy link
Copy Markdown
Contributor Author

Fixed the Codacy whitespace issue. Very surprised the IDE didn't catch this one.

@bashtage bashtage mentioned this pull request Jul 25, 2019
4 tasks done
@bashtage bashtage added the rejected Used for PRs with changes that are not acceptable label Jul 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

rejected Used for PRs with changes that are not acceptable

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants