Skip to content

ENH: Add CDF and SF of the Wilcoxon distribution#124

Open
fbourgey wants to merge 3 commits intoscipy:mainfrom
fbourgey:wilcoxon
Open

ENH: Add CDF and SF of the Wilcoxon distribution#124
fbourgey wants to merge 3 commits intoscipy:mainfrom
fbourgey:wilcoxon

Conversation

@fbourgey
Copy link
Copy Markdown
Member

Reference issue

Toward #98

What does this implement/fix?

  • Implement the CDF and SF of the Wilcoxon signed-rank distribution.
  • Port the exact distribution logic from scipy.stats._wilcoxon.py
  • Precompute a CDF table from the PMF so repeated CDF/SF queries for a given n are efficient.

Comment thread include/xsf/stats.h
Comment on lines +303 to +319
inline std::vector<double> wilcoxon_pmf(int n) {
// PMF of the Wilcoxon signed-rank statistic.
// The returned vector has length n*(n+1)/2 + 1, and the k-th element contains
// the probability of observing a test statistic equal to k for n pairs of
// observations.
std::vector<double> pmf = {1.0};
for (int k = 1; k < n + 1; k++) {
std::vector<double> tmp(k * (k + 1) / 2 + 1, 0.0);
int m = static_cast<int>(pmf.size());
for (int i = 0; i < m; i++) {
tmp[i] += 0.5 * pmf[i];
tmp[i + k] += 0.5 * pmf[i];
}
pmf = std::move(tmp);
}
return pmf;
}
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant