-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
feat: add stats/incr/nanmcovariance
#6865
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
base: develop
Are you sure you want to change the base?
feat: add stats/incr/nanmcovariance
#6865
Conversation
…/* namespace This commit adds the `nanmcovariance` module to the `stats/incr/*` namespace, providing a way to compute a moving unbiased sample covariance incrementally, while handling NaN values. This commit was made to address Issue stdlib-js#5567 and as suggested in the issue, it is based on a thin wrapper around wmean, similar to the relationship between nansum and sum, mainting API consistency and design. This commit includes appropriate documentation and tests for the new purpose of the package, styles of which are consistent to the stats/incr/* namespace. Fixes: stdlib-js#5567 [RFC] Private-ref: stdlib-js#5567 Authored-by: Don Chacko <[email protected]>
Coverage Report
The above coverage report was generated for the changes in this PR. |
…cases This commit fixes a coverage issue with the previous commit where the NaN branch of the main.js file of the nanmcovariance package, is not adequetly tested. It now ensures that the branch for known and unknown means are tested and benchmarked, for full coverage. Authored by: Don Chacko <[email protected]>
Planeshifter
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the delay of getting to this PR; left some initial comments.
| * @private | ||
| * @param {number} [x] - input value | ||
| * @param {number} [y] - input value | ||
| * @returns {(number)} unbiased sample covariance |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The return type should include null since mcovariance() returns null when no data has been provided yet. See the reference in @stdlib/stats/incr/mcovariance which uses @returns {(number|null)}.
| * @returns {(number)} unbiased sample covariance | |
| * @returns {(number|null)} unbiased sample covariance or null |
| * @returns {(number)} unbiased sample covariance | ||
| */ | ||
| function accumulator( x, y ) { | ||
| if ( arguments.length === 0 || isnan( x ) || isnan( y )) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing space before the closing parenthesis. Per stdlib style conventions (see @stdlib/stats/incr/mcovariance for reference), it should be isnan( y ) ) with a space before the final ).
| if ( arguments.length === 0 || isnan( x ) || isnan( y )) { | |
| if ( arguments.length === 0 || isnan( x ) || isnan( y ) ) { |
| type accumulator = ( x?: number, y?: number ) => number | null; | ||
|
|
||
| /** | ||
| * Returns an accumulator function which incrementally computes a moving unbiased sample covariance. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This overload's description doesn't mention NaN handling, but the second overload at line 52 does. Since NaN handling is the key differentiator of this package, both overloads should mention it for consistency. Consider updating to:
"Returns an accumulator function which incrementally computes a moving unbiased sample covariance, while handling NaN values."
| * * * | ||
|
|
||
| ## See Also | ||
|
|
||
| - <span class="package-name">[`@stdlib/stats/incr/covariance`][@stdlib/stats/incr/covariance]</span><span class="delimiter">: </span><span class="description">compute an unbiased sample covariance incrementally.</span> | ||
| - <span class="package-name">[`@stdlib/stats/incr/mpcorr`][@stdlib/stats/incr/mpcorr]</span><span class="delimiter">: </span><span class="description">compute a moving sample Pearson product-moment correlation coefficient incrementally.</span> | ||
| - <span class="package-name">[`@stdlib/stats/incr/mcovariance`][@stdlib/stats/incr/mcovariance]</span><span class="delimiter">: </span><span class="description">compute a moving unbiased sample variance incrementally.</span> | ||
|
|
||
| </section> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The "related" section is auto-populated.
| * * * | |
| ## See Also | |
| - <span class="package-name">[`@stdlib/stats/incr/covariance`][@stdlib/stats/incr/covariance]</span><span class="delimiter">: </span><span class="description">compute an unbiased sample covariance incrementally.</span> | |
| - <span class="package-name">[`@stdlib/stats/incr/mpcorr`][@stdlib/stats/incr/mpcorr]</span><span class="delimiter">: </span><span class="description">compute a moving sample Pearson product-moment correlation coefficient incrementally.</span> | |
| - <span class="package-name">[`@stdlib/stats/incr/mcovariance`][@stdlib/stats/incr/mcovariance]</span><span class="delimiter">: </span><span class="description">compute a moving unbiased sample variance incrementally.</span> | |
| </section> |
| [@stdlib/stats/incr/covariance]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/incr/covariance | ||
|
|
||
| [@stdlib/stats/incr/mpcorr]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/incr/mpcorr | ||
|
|
||
| [@stdlib/stats/incr/mcovariance]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/incr/mcovariance |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is also auto-populated:
| [@stdlib/stats/incr/covariance]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/incr/covariance | |
| [@stdlib/stats/incr/mpcorr]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/incr/mpcorr | |
| [@stdlib/stats/incr/mcovariance]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/incr/mcovariance |
Resolves #5567.
Description
This pull request:
nanmcovariancemodule to thestats/incr/*namespace, providing a way to compute a moving unbiased sample covariance incrementally, while handling NaN values. This commit was made to address Issue [RFC]: addstats/incr/nanmcovariance#5567 and as suggested in the issue, it is based on a thin wrapper aroundmcovariance, similar to the relationship betweennansumandsum, maintaining API consistency and design. This commit includes appropriate documentation and tests for the new purpose of the package, styles of which are consistent to the stats/incr/* namespace.Related Issues
This pull request:
stats/incr/nanmcovariance#5567Questions
No.
Other
No.
Checklist
@stdlib-js/reviewers