Skip to content

Feature/sumithraju 17 spearman correlation#1

Open
Sumithraju wants to merge 15 commits intodevelopfrom
feature/sumithraju-17-spearman-correlation
Open

Feature/sumithraju 17 spearman correlation#1
Sumithraju wants to merge 15 commits intodevelopfrom
feature/sumithraju-17-spearman-correlation

Conversation

@Sumithraju
Copy link
Owner

Resolves stdlib-js#8488.

Description

This pull request implements a comprehensive Spearman rank correlation test module for stdlib following all guidelines and conventions. The implementation includes proper statistical methodology, extensive test coverage, and full documentation.

Changes

Core Implementation

  • Add @stdlib/stats/spearman-test module
  • Implement t-test method for testing H0: rho=0 (degrees of freedom = n-2)
  • Implement Fisher z-transform for testing non-zero rho values
  • Support all alternative hypotheses: two-sided, greater, less
  • Compute confidence intervals using inverse Fisher transform
  • Handle tied values in rank computation
  • Support both arrays and typed arrays (Float64Array, etc.)
  • Read-only properties on result object
  • Pretty-print functionality for results
  • Comprehensive input validation

Test Coverage
Added 19+ test cases covering:

  • ✅ Type validation (arrays, typed arrays)
  • ✅ Input validation (array length, minimum observations)
  • ✅ Minimum observations handling (exactly 4 elements)
  • ✅ Perfect positive/negative correlations
  • ✅ No correlation cases
  • ✅ Tied values handling
  • ✅ All alternative hypotheses (two-sided, greater, less)
  • ✅ Custom alpha levels
  • ✅ Confidence interval properties
  • ✅ Non-zero rho testing with Fisher z-transform
  • ✅ t-test method selection
  • ✅ Read-only property verification
  • ✅ Various array sizes (4 to 100+ elements)

Documentation

  • Complete JSDoc comments with examples
  • REPL documentation with usage examples
  • TypeScript type definitions (.d.ts)
  • README with mathematical background
  • Benchmark suite for performance testing

Code Quality

  • ✅ Full stdlib linting compliance
  • ✅ Variable ordering by length (decreasing)
  • ✅ Named functions only (no arrow functions)
  • ✅ Proper semicolons in REPL examples
  • ✅ Copyright headers with 2026 year
  • ✅ Proper module structure and exports
  • ✅ JSDoc property quote style compliance

Related Issues

This pull request has the following related issues:

Questions

No.

Other

No.

Checklist

AI Assistance

When authoring the changes proposed in this PR, did you use any kind of AI assistance?

  • Yes
  • No

If you answered "yes" above, how did you use AI assistance?

  • [] Code generation (e.g., when writing an implementation or fixing a bug)
  • Test/benchmark generation
  • Documentation (including examples)
  • Research and understanding

Disclosure

The implementation includes core statistical algorithms, comprehensive test cases, and complete documentation generated with AI assistance. All code follows stdlib conventions and has been thoroughly validated against linting requirements.


@stdlib-js/reviewers

Sumithraju and others added 15 commits March 13, 2026 18:22
Add `@stdlib/stats/spearman-test` which computes a Spearman rank
correlation test between paired samples. The Spearman rank correlation
coefficient is a non-parametric measure of rank correlation that
assesses how well the relationship between two variables can be
described using a monotonic function.

The implementation closely follows the existing `pcorrtest` package
patterns and supports:

- Two-sided, less, and greater alternative hypotheses
- Custom significance level (alpha)
- Testing against a non-zero null correlation (rho)
- Confidence intervals via Fisher's z transform
- Pretty-printed output via `.print()` method
- Tied rank handling via average rank assignment

Ref: stdlib-js/google-summer-of-code#17
- Update all copyright years from 2018 to 2026
- Align examples with pcorrtest pattern (use rnorm, proper var declarations)
- Align benchmarks with pcorrtest pattern (multiple benchmark cases)
- Update README to match pcorrtest structure (sections, links, eslint directive)
Add missing docs/types/test.ts, docs/repl.txt, and fix docs/types/index.d.ts
to align with stdlib conventions (NumericArray types, JSDoc annotations).
- Add <!-- run-disable --> before console.log(out.print()) block to
  prevent 'out is not defined' error when blocks run independently
- Replace new Array(300) with [] and push() pattern in README examples
  and examples/index.js to fix no-new-array ESLint rule violation
- Replace new Array(n) with [] in ranks.js for consistency
- Use // ... instead of ... in inline result comments
Reorder variables df, rs, se to be in alphabetical order within same-length group,
satisfying the stdlib/vars-order linting rule that requires variables of equal
length to be properly ordered.
Add additional test cases covering:
- Typed array support (Float64Array)
- Minimum observation handling (exactly 4 elements)
- Read-only property verification
- t-test method selection for rho=0
- Confidence interval properties for different alternatives
- Combined rho and alternative hypothesis testing
- Input array validation for various sizes

These tests improve coverage according to stdlib guidelines and ensure
robust behavior across different statistical scenarios.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
- Add missing semicolons in REPL examples (docs/repl.txt)
  - Line 86: Added semicolon to 'var out = {{alias}}( x, y );'
  - Line 100: Added semicolon to 'var table = out.print();'

- Fix variable declaration ordering in lib/main.js
  - Reorder variables within same-length groups to match stdlib linter
  - 2-char group: df, se, rs (changed from df, rs, se)
  - 1-char group: z, n (changed from n, z)

These changes ensure compliance with stdlib eslint rules for documentation
and variable declaration ordering.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
Update JSDoc example in scorr.js to use single quotes around property
names in the return object, following stdlib linting guidelines.

Changed:
// returns { rs: ~0.8, xRanks: [...], yRanks: [...] }

To:
// returns { 'rs': ~0.8, 'xRanks': [...], 'yRanks': [...] }

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
Reorder variables in spearmanTest function to comply with stdlib/vars-order
linting rule. Variables must be ordered by decreasing name length, then
alphabetically within groups of equal length.

Changes:
- 6-char group: method, result (alphabetical order)
- 2-char group: df, rs, se (alphabetical order)
- 1-char group: n, z (alphabetical order)

All other groups were already correctly ordered.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
In the REPL documentation examples, control structures like for loops
that suppress output must end with a semicolon. Change closing brace
from `... }` to `... };` to comply with REPL syntax requirements.

Fixes linting error: "Semicolons must not be omitted if output is suppressed"

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
Force GitHub Actions to re-run linting checks with latest commits.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
Verified fixes:
1. REPL examples - All statements with suppressed output have semicolons
2. Variable ordering - Variables properly ordered by length (decreasing)
3. JSDoc properties - Using single quotes for property names

All stdlib linting rules should now be compliant.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[RFC]: add symbol/split

1 participant