Skip to content

Commit

Permalink
docs(stats_test): better attribution of sources
Browse files Browse the repository at this point in the history
  • Loading branch information
mdahlin committed Jan 18, 2025
1 parent 21113fc commit 15ae850
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 18 deletions.
7 changes: 4 additions & 3 deletions src/stats_tests/chisquare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,13 @@ impl std::error::Error for ChiSquareTestError {}
///
/// # Remarks
///
/// Implementation based on the one-way chi-square test of [scipy](https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.chisquare.html#scipy.stats.chisquare).
/// and Pearson's chi-squared test [wikipedia] article.
///
/// `ddof` represents an adjustment that can be made to the degrees of freedom where the unadjusted
/// degrees of freedom is `f_obs.len() - 1`.
///
/// Implementation based on [wikipedia](https://en.wikipedia.org/wiki/Pearson%27s_chi-squared_test)
/// while aligning to [scipy's](https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.chisquare.html)
/// function header where possible. The scipy implementation was also used for testing and validation.
///
/// # Examples
///
/// ```
Expand Down
11 changes: 6 additions & 5 deletions src/stats_tests/f_oneway.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,21 @@ impl std::error::Error for FOneWayTestError {}
/// Takes in a set (outer vector) of samples (inner vector) and returns the F-statistic and p-value
///
/// # Remarks
/// Implementation based on [statsdirect](https://www.statsdirect.com/help/analysis_of_variance/one_way.htm)
/// and [scipy](https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.f_oneway.html#scipy.stats.f_oneway)
///
/// `samples` needs to be mutable in case needing to filter out NaNs for NaNPolicy::Emit
///
/// Implementation based on [statsdirect](https://www.statsdirect.com/help/analysis_of_variance/one_way.htm)
/// while aligning to [scipy's](https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.f_oneway.html#scipy.stats.f_oneway)
/// function header where possible. The scipy implementation was also used for testing and
/// validation. Includes the use of [McDonald et al. (1991)](doi.org/10.1007/BF01319403) for
/// testing and validation.
///
/// # Examples
///
/// ```
/// use statrs::stats_tests::f_oneway::f_oneway;
/// use statrs::stats_tests::NaNPolicy;
///
/// // based on wikipedia example
/// let a1 = Vec::from([6f64, 8f64, 4f64, 5f64, 3f64, 4f64]);
/// let a2 = Vec::from([8f64, 12f64, 9f64, 11f64, 6f64, 8f64]);
/// let a3 = Vec::from([13f64, 9f64, 11f64, 8f64, 7f64, 12f64]);
Expand Down Expand Up @@ -149,8 +152,6 @@ mod tests {

#[test]
fn test_scipy_example() {
// Test against the scipy example
// https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.f_oneway.html#scipy.stats.f_oneway
let tillamook = Vec::from([
0.0571, 0.0813, 0.0831, 0.0976, 0.0817, 0.0859, 0.0735, 0.0659, 0.0923, 0.0836,
]);
Expand Down
15 changes: 11 additions & 4 deletions src/stats_tests/mannwhitneyu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,10 +213,17 @@ fn calc_mwu_exact_pvalue(u: f64, n1: usize, n2: usize) -> f64 {
/// samples sizes (length of `x` + length of `y`) above 20 are approximated fairly well using the
/// asymptotic (normal) methods.
///
/// Implementation was largely based on the [scipy version](https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.mannwhitneyu.html#scipy.stats.mannwhitneyu).
/// There are a few deviations including, not supporting calculation of the value via permutation
/// tests, not supporting calculation of the exact p-value where input data includes ties, and not
/// supporting the NaN policy due to being generic on T which might not have NaN values.
///
/// Implementation based on [wikipedia](https://en.wikipedia.org/wiki/Mann–Whitney_U_test)
/// while aligning to [scipy's](https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.mannwhitneyu.html#scipy.stats.mannwhitneyu)
/// function header where possible. The scipy implementation was also used for testing and
/// validation. Includes the use of [Shier (2004)](https://www.statstutor.ac.uk/resources/uploaded/mannwhitney.pdf) for
/// testing and validation.
///
/// There are a few deviations from the scipy version including, not supporting calculation
/// of the value via permutation tests, not supporting calculation of the exact p-value
/// where input data includes ties, and not supporting the NaN policy due to being generic
/// on T which might not have NaN values.
///
/// # Examples
///
Expand Down
11 changes: 7 additions & 4 deletions src/stats_tests/skewtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,15 @@ fn calc_root_b1(data: &[f64]) -> f64 {
///
/// # Remarks
///
/// Implementation based on [scipy](https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.skewtest.html#scipy.stats.skewtest).
/// and [fintools.com](https://www.fintools.com/docs/normality_correlation.pdf) which both
/// reference D'Agostino, 1970 (but direct access to the paper has been challenging to find)
///
/// `a` needs to be mutable in case needing to filter out NaNs for NaNPolicy::Emit
///
/// Implementation based on [fintools.com](https://www.fintools.com/docs/normality_correlation.pdf)
/// which indirectly uses [D'Agostino, (1970)](https://doi.org/10.2307/2684359)
/// while aligning to [scipy's](https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.skewtest.html#scipy.stats.skewtest)
/// function header where possible. The scipy implementation was also used for testing and validation.
/// Includes the use of [Shapiro & Wilk (1965)](https://doi.org/10.2307/2333709) for
/// testing and validation.
///
/// # Examples
///
/// ```
Expand Down
6 changes: 4 additions & 2 deletions src/stats_tests/ttest_onesample.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,12 @@ impl std::error::Error for TTestOneSampleError {}
///
/// # Remarks
///
/// Implementation based on [scipy](https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.ttest_1samp.html).
///
/// `a` needs to be mutable in case needing to filter out NaNs for NaNPolicy::Emit
///
/// Implementation based on [jmp](https://www.jmp.com/en_us/statistics-knowledge-portal/t-test/one-sample-t-test.html)
/// while aligning to [scipy's](https://docs.scipy.org/doc/scipy-1.14.1/reference/generated/scipy.stats.ttest_1samp.html)
/// function header where possible.
///
/// # Examples
///
/// ```
Expand Down

0 comments on commit 15ae850

Please sign in to comment.