Skip to content

ENH/BUG: add FTestPowerF2 as corrected version of FTestPower - #8656

Merged
josef-pkt merged 3 commits into
statsmodels:mainfrom
josef-pkt:ftestpower_f2
Feb 8, 2023
Merged

josef-pkt merged 3 commits into
statsmodels:mainfrom
josef-pkt:ftestpower_f2

Conversation

@josef-pkt

@josef-pkt josef-pkt commented Feb 7, 2023 •

Copy link
Copy Markdown
Member

closes #8646
closes #8624

this adds a new class as replacement for the FTestPower class.
also adds the corresponding function ftest_power_f2

two differences

  • corrected names df_num, df_denom
  • effect size is f2 instead of f

old class is not (yet) deprecated

unit test just uses a copy of the old unit tests with the new power class

@josef-pkt josef-pkt added this to the 0.14 milestone Feb 7, 2023
@josef-pkt

Copy link
Copy Markdown
Member Author

doc build error

I need to check what the pattern for See Also entries is when explanation is added.

Extension error (numpydoc.numpydoc):
Handler <function mangle_signature at 0x7fac51a9ab00> for event 'autodoc-process-signature' threw an exception (exception: Error parsing See Also entry "`FTestPowerF2` : Power class with same functionality but uses Cohen's" in the docstring of FTestPower in /opt/hostedtoolcache/Python/3.10.9/x64/lib/python3.10/site-packages/statsmodels/stats/power.py.)

@josef-pkt

josef-pkt commented Feb 8, 2023 •

Copy link
Copy Markdown
Member Author

azure results are weird

on windows:
worker 'gw0' crashed while running 'statsmodels/stats/tests/test_power.py::TestFtestPowerF2::test_roots

macos and 3 linux environments timed out (60 min)

4 linux environments are all green

???

@josef-pkt

Copy link
Copy Markdown
Member Author

It's likely that scipy 1.10.0 is buggy.
AFAICS, all environments that have problems use scipy 1.10.0
The linux environments with older scipy all pass

Unfortunately, all windows environment use the same scipy version.

@josef-pkt

josef-pkt commented Feb 8, 2023 •

Copy link
Copy Markdown
Member Author

maybe ncf is still buggy
scipy/scipy#15763
edit that's an old issue from last year. So, it's unlikely that we have problems from this now.

I guess we can use some old, pre-boost versions of the nc distributions until the dust settles, if we need to.

The power unit tests pass on my windows computer with older scipy.
But I don't know why the test problems show up now on azure testing.
Azure runs after previous merge (doc fixes) had only unrelated test failures.

@josef-pkt

Copy link
Copy Markdown
Member Author

The new unit test for FTestPowerF2 treats the same case as the old test FTestPower.
One possible difference is in the starting values or range for the root finder. E.g. values for effect_size are squares of the ones in the old unit test.

AFAICS, We don't impose that we have valid values, except for using a positive range. So, it might be possible that power during rootfinding hits problematic edge or "invalid" cases.

@josef-pkt

josef-pkt commented Feb 8, 2023 •

Copy link
Copy Markdown
Member Author

after switching ftest_power_f2 to use scipy.special instead of boost

azure failed because it could fetch the source from github
I manually restarted the run https://dev.azure.com/statsmodels/statsmodels-testing/_build/results?buildId=4999&view=results
looks good so far, no failures yet

If this works, then I might also switch nct to avoid #8624
scipy/scipy#16591 switched nct to boost

@josef-pkt

Copy link
Copy Markdown
Member Author

all green (except the usual pre-testing) in restarted run.

I will amend latest commit and switch all cdf, sf for nct, nct to scipy.special

@josef-pkt

josef-pkt commented Feb 8, 2023 •

Copy link
Copy Markdown
Member Author

update
The following happened because ftest_anova_power still used boost.
I will amend the commit, but keep the following for the record, difference between scipy.special and boost

test failure after switching to scipy.special in FTestPower/ftest_power

(I did not switch ncf in oneway to scipy.special)
However, the test compares ftest_power with ftest_anova_power, both functions in `power
So the test compares now the boost with the scipy.special implementation of ncf for power computation (ncf.sf)

        alpha = 0.05
        pow_ols = smpwr.ftest_power(np.sqrt(es_ols), df_denom, df_num, alpha,
                                    ncc=1)
        pow_oneway = smpwr.ftest_anova_power(np.sqrt(es_oneway), nobs_t, alpha,
                                             k_groups=k, df=None)
>       assert_allclose(pow_ols, pow_oneway, rtol=1e-13)

statsmodels\stats\tests\test_oneway.py:492: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

args = (<function assert_allclose.<locals>.compare at 0x000001473DDA3640>, array(0.06544216), array(0.06544208))
kwds = {'equal_nan': True, 'err_msg': '', 'header': 'Not equal to tolerance rtol=1e-13, atol=0', 'verbose': True}

    @wraps(func)
    def inner(*args, **kwds):
        with self._recreate_cm():
>           return func(*args, **kwds)
E           AssertionError: 
E           Not equal to tolerance rtol=1e-13, atol=0
E           
E           Mismatched elements: 1 / 1 (100%)
E           Max absolute difference: 0.00000008
E           Max relative difference: 0.00000116
E            x: array(0.065442)
E            y: array(0.065442)

Note: ncf.sf is not used in oneway, only functions for equivalence tests use ncf in oneway
power computation for oneway anova only need the effect size computation from oneway module
I will switch to scipy.special in the next commit

@josef-pkt

Copy link
Copy Markdown
Member Author

CodeQL complains about a possibly uninitialized variable
false positive, but code could be "nicer"
Uses if elseif without an else, but we already raise if neither if nor elseif condition applies

otherwise green, merging

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.

BUG: FTestPower always Fails to converge on a solution, wrong names, unclear usage MAINT: RuntimeWarning: invalid value encountered in _nct_sf

1 participant