-
Notifications
You must be signed in to change notification settings - Fork 0
Amend README example, fix some typos in arguments and docstrings, and add equivalent checks from R package #35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
c249668
Delete unnecessary import in example
remlapmot 495457b
Bump version
remlapmot e91209f
Amend bootstrap_method to bootstrap_CI_method
remlapmot 0e9e107
Amend self.hazard to self.hazard_estimate
remlapmot c40f067
Amend f"{v}_bas" to f"{v}{self.indicator_baseline}"
remlapmot fe12074
Typo fix arugment to argument
remlapmot 6f48741
Typo fix preform to perform
remlapmot 36b0fd0
Amend indicator_baseline to indicator_squared
remlapmot b5ace46
Add a check for pefect separation
remlapmot 1855bc2
Add tests for the check of perfect separation
remlapmot 7278c4c
Handle no-variation weight models
remlapmot e8ef1fb
Add tests for no variation models
remlapmot e1ecb0d
Format with black
remlapmot d751848
Format with isort
remlapmot 507faac
Bump actions/upload-artifact to v7
remlapmot 2ea27ab
Bump actions/download-artifact to v8
remlapmot bc48442
hopefully resolved needing to update version twice
ryan-odea File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,9 @@ | ||
| from ._check_separation import _check_separation | ||
| from ._data_checker import _data_checker | ||
| from ._param_checker import _param_checker | ||
|
|
||
| __all__ = [ | ||
| "_check_separation", | ||
| "_data_checker", | ||
| "_param_checker", | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| import warnings | ||
|
|
||
| import numpy as np | ||
|
|
||
|
|
||
| def _check_separation(model_fit, label="model"): | ||
| """ | ||
| Check for perfect or quasi-complete separation in a fitted logistic regression model. | ||
| Issues a warning if large (|coef| > 25) or non-finite coefficients are detected, | ||
| as these are reliable indicators of separation in logistic regression. | ||
| """ | ||
| params = np.array(model_fit.params).flatten() | ||
|
|
||
| has_large = np.any(np.abs(params) > 25) | ||
| has_nonfinite = np.any(~np.isfinite(params)) | ||
|
|
||
| if has_large or has_nonfinite: | ||
| warnings.warn( | ||
| f"Possible perfect or quasi-complete separation detected in {label}. " | ||
| "The resulting weights may be unreliable.", | ||
| UserWarning, | ||
| stacklevel=2, | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| import warnings | ||
| from types import SimpleNamespace | ||
|
|
||
| import numpy as np | ||
| import pytest | ||
|
|
||
| from pySEQTarget.error._check_separation import _check_separation | ||
|
|
||
|
|
||
| def _mock_model(params): | ||
| """Create a minimal mock model with a .params attribute.""" | ||
| return SimpleNamespace(params=np.array(params)) | ||
|
|
||
|
|
||
| def test_no_warning_for_normal_coefficients(): | ||
| model = _mock_model([0.5, -1.2, 3.0, -0.01]) | ||
| with warnings.catch_warnings(): | ||
| warnings.simplefilter("error") | ||
| _check_separation(model) # should not raise | ||
|
|
||
|
|
||
| def test_warns_for_large_positive_coefficient(): | ||
| model = _mock_model([0.5, 26.0]) | ||
| with pytest.warns(UserWarning, match="separation"): | ||
| _check_separation(model) | ||
|
|
||
|
|
||
| def test_warns_for_large_negative_coefficient(): | ||
| model = _mock_model([0.5, -30.0]) | ||
| with pytest.warns(UserWarning, match="separation"): | ||
| _check_separation(model) | ||
|
|
||
|
|
||
| def test_warns_for_inf_coefficient(): | ||
| model = _mock_model([1.0, np.inf]) | ||
| with pytest.warns(UserWarning, match="separation"): | ||
| _check_separation(model) | ||
|
|
||
|
|
||
| def test_warns_for_neg_inf_coefficient(): | ||
| model = _mock_model([1.0, -np.inf]) | ||
| with pytest.warns(UserWarning, match="separation"): | ||
| _check_separation(model) | ||
|
|
||
|
|
||
| def test_warns_for_nan_coefficient(): | ||
| model = _mock_model([1.0, np.nan]) | ||
| with pytest.warns(UserWarning, match="separation"): | ||
| _check_separation(model) | ||
|
|
||
|
|
||
| def test_boundary_coefficient_does_not_warn(): | ||
| # Exactly 25 should not trigger (threshold is strictly > 25) | ||
| model = _mock_model([25.0, -25.0]) | ||
| with warnings.catch_warnings(): | ||
| warnings.simplefilter("error") | ||
| _check_separation(model) | ||
|
|
||
|
|
||
| def test_label_appears_in_warning(): | ||
| model = _mock_model([100.0]) | ||
| with pytest.warns(UserWarning, match="censoring numerator"): | ||
| _check_separation(model, label="censoring numerator") | ||
|
|
||
|
|
||
| def test_default_label_appears_in_warning(): | ||
| model = _mock_model([np.inf]) | ||
| with pytest.warns(UserWarning, match="model"): | ||
| _check_separation(model) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.