Skip to content

ENH: Add additional options for pacf ols - #5153

Merged
bashtage merged 3 commits into
statsmodels:masterfrom
bashtage:nikhase-bugfix-pacf-ols
Apr 30, 2019
Merged

bashtage merged 3 commits into
statsmodels:masterfrom
bashtage:nikhase-bugfix-pacf-ols

Conversation

@bashtage

@bashtage bashtage commented Sep 9, 2018

Copy link
Copy Markdown
Member

Rebase #3862 and change to enhancement
Clean up docs for pacf functions
Add option to use through pacf()

return pacf, sigma2


#NOTE: this is incorrect.

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 comment has been a huge bother. Very glad to see it go.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

It is tested to clearly correct

pacf[0] = 1.0
if efficient:
xlags, x0 = lagmat(x, nlags, original='sep')
xlags = add_constant(xlags)

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.

It took me a minute to figure out why de-meaning on line 701 doesn't affect the outcome. Maybe for the sake of future readers only de-mean in the not-efficient case?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I figured it just keeps the code simpler, but moved it anyway.

Comment thread statsmodels/tsa/stattools.py Outdated

if method == 'ols':
ret = pacf_ols(x, nlags=nlags)
if method.startswith('ols'):

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.

Do we want to deny invalid strings starting with "ols"?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I changed this

@jbrockmendel

Copy link
Copy Markdown
Contributor

Couple comments, generally looks quite nice.

@bashtage
bashtage force-pushed the nikhase-bugfix-pacf-ols branch from e7624ef to 24edcb0 Compare September 9, 2018 16:17
@coveralls

coveralls commented Sep 9, 2018 •

Copy link
Copy Markdown

Coverage Status

Coverage increased (+0.03%) to 84.126% when pulling 34cfa3e on bashtage:nikhase-bugfix-pacf-ols into 074c8d2 on statsmodels:master.

@bashtage
bashtage force-pushed the nikhase-bugfix-pacf-ols branch from 24edcb0 to 55aa411 Compare September 9, 2018 20:36
@codecov

codecov Bot commented Sep 9, 2018 •

Copy link
Copy Markdown

Codecov Report

Merging #5153 into master will increase coverage by <.01%.
The diff coverage is 85.1%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #5153      +/-   ##
==========================================
+ Coverage   82.03%   82.03%   +<.01%     
==========================================
  Files         588      588              
  Lines       93062    93094      +32     
  Branches    10317    10322       +5     
==========================================
+ Hits        76345    76372      +27     
- Misses      14355    14358       +3     
- Partials     2362     2364       +2
Impacted Files Coverage Δ
statsmodels/tsa/tests/test_stattools.py 98.83% <100%> (+0.03%) ⬆️
statsmodels/tsa/stattools.py 87.2% <77.41%> (-0.53%) ⬇️

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 6de5f3e...fa49fce. Read the comment docs.

@josef-pkt

Copy link
Copy Markdown
Member

question (I didn't compare with #3862)

Is the new version close to pacf_yd and pacf_ld?
Should there be a unit test that is is close to them? (i.e. not as different as the old ols version)

(I read only roughly over the algorithm, old unit tests pass.)

@josef-pkt josef-pkt added this to the 0.10 milestone Sep 11, 2018
@bashtage

Copy link
Copy Markdown
Member Author

Ran a small MC using a range of AR, MA and ARMA models.

Ranks

                          Lowest bias  Top 3 Bias  Lowest RMSE  Top 3 RMSE
burg                               10          28            5          42
ols                                 7          25            0           7
ols-inefficient                     4          16            0           3
ols-unbisaed                        6          13            0           0
ols-unbiased-inefficient            4          10            0           0
yule-walker                         0           3            0           1
yule-walker-mle                     4          17           14          41
ld_unbiased                         1           5            0           0
ld_biased                           3          17           11          41

Suggests that this method may be reasonable if bias is the main concern. LD and YW unbiased are no good.

@bashtage
bashtage force-pushed the nikhase-bugfix-pacf-ols branch 2 times, most recently from 5985bfe to 34cfa3e Compare September 17, 2018 15:13
ld_ = levinson_durbin(acv, nlags=nlags, isacov=True)
#print 'ld', ld_
ret = ld_[2]
# inconsistent naming with ywmle

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.

add TODO/FIXME to this comment?

elif method in ('ywm', 'ywmle', 'yw_mle'):
ret = pacf_yw(x, nlags=nlags, method='mle')
elif method in ['ld', 'ldu', 'ldunbiase', 'ld_unbiased']:
elif method in ('ld', 'ldu', 'ldunbiased', 'ld_unbiased'):

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.

Closes #5212.

@bashtage
bashtage force-pushed the nikhase-bugfix-pacf-ols branch from 34cfa3e to 0d52dfc Compare April 30, 2019 09:26
Niklas H and others added 3 commits April 30, 2019 13:14
* For pacf with "method=ols", results differ quite a lot from
"method={yw, ld}" (biased and unbiased setting)

* Demeaning and minor changes in the OLS parameters improves the
result for smaller time series (emprirically evaluated)

* Added "unbiased" parameter for ols

* Added reference in docstring
Add option to use text book estiamtor

closes statsmodels#3839
closes statsmodels#3862
Add a recommendation to pacf
Small doc clean ups
@bashtage
bashtage force-pushed the nikhase-bugfix-pacf-ols branch from 0d52dfc to fa49fce Compare April 30, 2019 12:19
@bashtage
bashtage merged commit 303747f into statsmodels:master Apr 30, 2019
@bashtage
bashtage deleted the nikhase-bugfix-pacf-ols branch April 30, 2019 12:20
@josef-pkt josef-pkt modified the milestones: 0.10, 0.9 Apr 30, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants