Robust handling of root-finding errors in fitpt.m0: skip genes with uniroot failures and return NA instead of stopping analysis - #35
Open
Ye1203 wants to merge 8 commits into
Open
Conversation
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
When using fitpt.m0, some genes may cause an error in the uniroot call:
Error in uniroot(function(eta)): f() values at end points not of opposite sign,
because the interval endpoints have the same sign
(i.e., both digamma(1e-10 * meanN) - log(1e-10) + meanA and digamma(1e+10 * meanN) - log(1e+10) + meanA are positive or both negative).
In the original code, such errors would stop the entire lamian_test workflow, resulting in no output even for unaffected (normal) genes, and sometimes secondary errors like $ operator is invalid for atomic vectors.
In this patch, I modify fitpt.m0 to skip those problematic genes by returning NA when root-finding fails, and propagate this behavior so that corresponding entries are NA in the output from lamian_test. This ensures that analyses continue even if some genes cannot be fit, and all valid results for normal genes are still returned.
This change increases the robustness and fault-tolerance of the package, ensuring stable analysis even with problematic or edge-case data.