Skip to content

[TST/MAINT] de-duplicate get_correction_factor code - #4988

Merged
bashtage merged 1 commit into
statsmodels:masterfrom
jbrockmendel:dtests
May 9, 2019
Merged

bashtage merged 1 commit into
statsmodels:masterfrom
jbrockmendel:dtests

Conversation

@jbrockmendel

Copy link
Copy Markdown
Contributor

ATM the get_robust_clu classmethod calculates a correction factor and then a bunch of classes have that code copy/pasted into their setup_class. A bunch of other classes have a slightly-changed variant of that calculation, with no documentation as to why the slight change was made (IIRC the answer is "to make it match Stata/R").

This de-duplicates all that code by implementing get_correction_factor.

@coveralls

Copy link
Copy Markdown

Coverage Status

Coverage decreased (-0.04%) to 83.816% when pulling f3cb08f on jbrockmendel:dtests into 8675b89 on statsmodels:master.

@coveralls

coveralls commented Aug 24, 2018 •

Copy link
Copy Markdown

Coverage Status

Coverage decreased (-0.004%) to 84.5% when pulling bb5d48d on jbrockmendel:dtests into 28609c0 on statsmodels:master.

@josef-pkt

josef-pkt commented Aug 24, 2018 •

Copy link
Copy Markdown
Member

most likely not. I will think about it when I'm in that code neighborhood

code duplication provides information locally where we need it, i.e. I want to see what correction factor is used in individual cases

@jbrockmendel

jbrockmendel commented Aug 24, 2018 •

Copy link
Copy Markdown
Contributor Author

Take a look at the affected code. No information is lost.

I should clarify that information is in fact gained, will do so,when at a real keyboard.

@codecov-io

Copy link
Copy Markdown

Codecov Report

Merging #4988 into master will decrease coverage by 0.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #4988      +/-   ##
==========================================
- Coverage   81.33%   81.32%   -0.02%     
==========================================
  Files         582      582              
  Lines       90026    90001      -25     
  Branches    10093    10094       +1     
==========================================
- Hits        73224    73190      -34     
- Misses      14507    14513       +6     
- Partials     2295     2298       +3
Impacted Files Coverage Δ
statsmodels/discrete/discrete_model.py 88.12% <ø> (ø) ⬆️
statsmodels/discrete/tests/test_sandwich_cov.py 98.01% <100%> (-0.14%) ⬇️
statsmodels/regression/mixed_linear_model.py 88.97% <0%> (-0.8%) ⬇️

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 8675b89...f3cb08f. Read the comment docs.

@jbrockmendel

Copy link
Copy Markdown
Contributor Author

I should clarify that information is in fact gained, will do so when at a real keyboard.

Consider the perspective of a new reader. Unless you know ex-ante that there are only two versions of this code, the natural assumption is that the similar-looking code is duplicated for a reason, i.e. that there are small differences between the many versions. This eliminates that confusion and the accompanying cognitive overhead.

The big thing that needs to be documented in the affected code is "Why does class A use implementation X while class B uses implementation Y?" This PR doesn't answer that question, but puts a big TODO note in place, and minimizes the number of places where the question needs answering.

Another non-obvious thing that makes the two versions look more different than they are is the inversion:

        corr_fact = (nobs) / float(nobs - 1.)
        cls.corr_fact = np.sqrt(1./corr_fact)    # <-- inverting is not done in the other version

which this PR much more clearly writes as

        corr_fact = (nobs - 1.) / nobs
        cls.corr_fact = np.sqrt(corr_fact)

making it clear that the only difference between the two versions is the subtraction of k_params in the denominator of the other version.

Last, reducing code duplication is about forward-looking bug-prevention. As we see all over the code-base, one version of duplicated code get missed, and by the time someone realizes other versions were missed, its an archaeological adventure to sort out "are these slightly different on purpose? It must be on purpose right?"

@bashtage care to weigh in?

@jbrockmendel

jbrockmendel commented Sep 16, 2018 •

Copy link
Copy Markdown
Contributor Author

@josef-pkt besides being good code hygiene, this is a move toward parameterization/fixturization, which will allow us to systematically cover “method” etc args.

@codecov

codecov Bot commented May 3, 2019

Copy link
Copy Markdown

Codecov Report

Merging #4988 into master will decrease coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #4988      +/-   ##
==========================================
- Coverage      82%   81.99%   -0.01%     
==========================================
  Files         588      588              
  Lines       93061    93036      -25     
  Branches    10313    10314       +1     
==========================================
- Hits        76311    76286      -25     
  Misses      14378    14378              
  Partials     2372     2372
Impacted Files Coverage Δ
statsmodels/discrete/discrete_model.py 87.46% <ø> (ø) ⬆️
statsmodels/discrete/tests/test_sandwich_cov.py 98.01% <100%> (-0.14%) ⬇️

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 28609c0...bb5d48d. Read the comment docs.

1 similar comment
@codecov

codecov Bot commented May 3, 2019

Copy link
Copy Markdown

Codecov Report

Merging #4988 into master will decrease coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #4988      +/-   ##
==========================================
- Coverage      82%   81.99%   -0.01%     
==========================================
  Files         588      588              
  Lines       93061    93036      -25     
  Branches    10313    10314       +1     
==========================================
- Hits        76311    76286      -25     
  Misses      14378    14378              
  Partials     2372     2372
Impacted Files Coverage Δ
statsmodels/discrete/discrete_model.py 87.46% <ø> (ø) ⬆️
statsmodels/discrete/tests/test_sandwich_cov.py 98.01% <100%> (-0.14%) ⬇️

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 28609c0...bb5d48d. Read the comment docs.

@bashtage
bashtage merged commit 51498a4 into statsmodels:master May 9, 2019
@jbrockmendel
jbrockmendel deleted the dtests branch May 9, 2019 13:34
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.

5 participants