Skip to content

Commit 80b9bfd

Browse files
committed
feat: Add S_n and S_n0 statistics
Closes #6
1 parent ef7ffaf commit 80b9bfd

6 files changed

Lines changed: 120 additions & 16 deletions

File tree

doc/source/gsl-ffi-statistics.rst

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,3 +507,25 @@ Robust Scale Estimates
507507
:parameter work: An instance of `<c-double*>`.
508508
:value mad: An instance of `<c-double>`.
509509

510+
:math:`S_n` Statistic
511+
=====================
512+
513+
.. function:: gsl-stats-sn0-from-sorted-data
514+
515+
:signature: gsl-stats-sn0-from-sorted-data (sorted-data stride n work) => (sn0)
516+
517+
:parameter sorted-data: An instance of `<c-double*>`.
518+
:parameter stride: An instance of `<c-size-t>`.
519+
:parameter n: An instance of `<c-size-t>`.
520+
:parameter work: An instance of `<c-double*>`.
521+
:value sn0: An instance of `<c-double>`.
522+
523+
.. function:: gsl-stats-sn-from-sorted-data
524+
525+
:signature: gsl-stats-sn-from-sorted-data (sorted-data stride n work) => (sn)
526+
527+
:parameter sorted-data: An instance of `<c-double*>`.
528+
:parameter stride: An instance of `<c-size-t>`.
529+
:parameter n: An instance of `<c-size-t>`.
530+
:parameter work: An instance of `<c-double*>`.
531+
:value sn: An instance of `<c-double>`.

doc/source/gsl-statistics.rst

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,4 +300,21 @@ Robust Scale Estimates
300300

301301
:parameter data: An instance of :class:`<gsl-vector>`.
302302
:parameter #key stride: An instance of :drm:`<integer>`.
303-
:value mad0: An instance of :drm:`<double-float>`.
303+
:value mad0: An instance of :drm:`<double-float>`.
304+
305+
:math:`S_n` Statistic
306+
=====================
307+
308+
.. function:: sn0
309+
310+
:signature: sn0 (sorted-data) => (sn0)
311+
312+
:parameter data: An instance of :class:`<gsl-vector>`.
313+
:value sn0: An instance of :drm:`<double-float>`.
314+
315+
.. function:: sn
316+
317+
:signature: sn (sorted-data) => (sn)
318+
319+
:parameter data: An instance of :class:`<gsl-vector>`.
320+
:value sn: An instance of :drm:`<double-float>`.

src/lib/ffi/module-statistics.dylan

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Reference: https://www.gnu.org/software/gsl/doc/html/statistics.html
77

88
define module gsl-ffi-statistics
99

10-
// Mean, Standard Deviation and Variance (file:./mean-std-variance.dylan)
10+
// Mean, Standard Deviation and Variance
1111

1212
create
1313
gsl-stats-mean,
@@ -20,46 +20,46 @@ define module gsl-ffi-statistics
2020
gsl-stats-variance-with-fixed-mean,
2121
gsl-stats-sd-with-fixed-mean;
2222

23-
// Absolute deviation (file:./absolute-deviation.dylan)
23+
// Absolute deviation
2424

2525
create
2626
gsl-stats-absdev,
2727
gsl-stats-absdev-m;
2828

29-
// Higher moments (file:./higher-moments.dylan)
29+
// Higher moments
3030

3131
create
3232
gsl-stats-skew,
3333
gsl-stats-skew-m-sd,
3434
gsl-stats-kurtosis,
3535
gsl-stats-kurtosis-m-sd;
3636

37-
// Autocorrelation (file:./autocorrelation.dylan)
37+
// Autocorrelation
3838

3939
create
4040
gsl-stats-lag1-autocorrelation,
4141
gsl-stats-lag1-autocorrelation-m;
4242

43-
// Covariance (file:./covariance.dylan)
43+
// Covariance
4444

4545
create
4646
gsl-stats-covariance,
4747
gsl-stats-covariance-m;
4848

49-
// Maximum and Minimum (file:./maximum-minimum.dylan)
49+
// Maximum and Minimum
5050

5151
create
5252
gsl-stats-max,
5353
gsl-stats-min,
5454
gsl-stats-minmax;
5555

56-
// Correlation (file:./correlation.dylan)
56+
// Correlation
5757

5858
create
5959
gsl-stats-correlation,
6060
gsl-stats-spearman;
6161

62-
// Weighted samples (file:./weighted-samples.dylan)
62+
// Weighted samples
6363

6464
create
6565
gsl-stats-wmean,
@@ -77,29 +77,35 @@ define module gsl-ffi-statistics
7777
gsl-stats-wkurtosis,
7878
gsl-stats-wkurtosis-m-sd;
7979

80-
// Median and percentiles (file:./median-percentiles.dylan)
80+
// Median and percentiles
8181

8282
create
8383
gsl-stats-median-from-sorted-data,
8484
gsl-stats-median;
8585

86-
// Order statistics (file:./order-statistic.dylan)
86+
// Order statistics
8787

8888
create
8989
gsl-stats-select;
9090

91-
// Robust location estimates (file:./robust-location-estimates.dylan)
91+
// Robust location estimates
9292

9393
create
9494
gsl-stats-trmean-from-sorted-data,
9595
gsl-stats-gastwirth-from-sorted-data;
9696

97-
// Robust scale estimates (file:./robust-scale-estimates.dylan)
97+
// Robust scale estimates
9898

9999
create
100100
gsl-stats-mad,
101101
gsl-stats-mad0;
102102

103+
// S_n statistic
104+
105+
create
106+
gsl-stats-sn0-from-sorted-data,
107+
gsl-stats-sn-from-sorted-data;
108+
103109
end module;
104110

105111
define module gsl-ffi-statistics-impl

src/lib/ffi/statistics.dylan

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -624,5 +624,33 @@ define c-function gsl-stats-mad
624624
c-name: "gsl_stats_mad";
625625
end;
626626

627-
// TODO: S_n Statistics
627+
//////////////////////////////////////////////////////////////////////////////
628+
//
629+
// S_n Statistic
630+
//
631+
// https://www.gnu.org/software/gsl/doc/html/statistics.html#s-n-statistic
632+
//
633+
// https://www.gnu.org/software/gsl/doc/html/statistics.html#c.gsl_stats_Sn0_from_sorted_data
634+
// https://www.gnu.org/software/gsl/doc/html/statistics.html#c.gsl_stats_Sn_from_sorted_data
635+
//
636+
//////////////////////////////////////////////////////////////////////////////
637+
638+
define c-function gsl-stats-sn0-from-sorted-data
639+
parameter sorted-data :: <c-double*>;
640+
parameter stride :: <c-size-t>;
641+
parameter n :: <c-size-t>;
642+
parameter work :: <c-double*>;
643+
result sn0 :: <c-double>;
644+
c-name: "gsl_stats_Sn0_from_sorted_data";
645+
end;
646+
647+
define c-function gsl-stats-sn-from-sorted-data
648+
parameter sorted-data :: <c-double*>;
649+
parameter stride :: <c-size-t>;
650+
parameter n :: <c-size-t>;
651+
parameter work :: <c-double*>;
652+
result sn :: <c-double>;
653+
c-name: "gsl_stats_Sn_from_sorted_data";
654+
end;
655+
628656
// TODO: Q_n Statistics

src/lib/gsl/module-statistics.dylan

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ define module gsl-statistics
3434
trimmed-mean,
3535
gastwirth-estimator,
3636
mad,
37-
mad0;
37+
mad0,
38+
sn0;
3839

3940
end module;
4041

src/lib/gsl/statistics.dylan

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -550,5 +550,35 @@ define function mad
550550
end
551551
end;
552552

553-
// TODO: S_n Statistics
553+
//////////////////////////////////////////////////////////////////////////////
554+
//
555+
// S_n Statistic
556+
//
557+
// https://www.gnu.org/software/gsl/doc/html/statistics.html#s-n-statistic
558+
//
559+
// https://www.gnu.org/software/gsl/doc/html/statistics.html#c.gsl_stats_Sn0_from_sorted_data
560+
// https://www.gnu.org/software/gsl/doc/html/statistics.html#c.gsl_stats_Sn_from_sorted_data
561+
//
562+
//////////////////////////////////////////////////////////////////////////////
563+
564+
define function sn0
565+
(sorted-data :: <gsl-vector>)
566+
=> (sn0 :: <double-float>)
567+
let n = sorted-data.size;
568+
with-stack-structure (work :: <c-double*>, element-count: n)
569+
gsl-stats-sn0-from-sorted-data
570+
(sorted-data.%gsl-vector-data, sorted-data.gsl-vector-stride, n, work)
571+
end
572+
end;
573+
574+
define function sn
575+
(sorted-data :: <gsl-vector>)
576+
=> (sn :: <double-float>)
577+
let n = sorted-data.size;
578+
with-stack-structure (work :: <c-double*>, element-count: n)
579+
gsl-stats-sn-from-sorted-data
580+
(sorted-data.%gsl-vector-data, sorted-data.gsl-vector-stride, n, work)
581+
end
582+
end;
583+
554584
// TODO: Q_n Statistics

0 commit comments

Comments
 (0)