sstat 0.0.7 → 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/ext/sstat/lib/basic/basic.c +4 -0
- data/ext/sstat/lib/distribution.h +1 -1
- data/ext/sstat/lib/histogram/histogram_stat.h +51 -49
- data/ext/sstat/lib/histogram/histogram_test +0 -0
- data/ext/sstat/lib/histogram/histogram_test.c +36 -0
- data/ext/sstat/lib/histogram/histogram_type.h +17 -5
- data/ext/sstat/lib/histogram/log +0 -0
- data/ext/sstat/lib/histogram/test.sh +3 -0
- data/ext/sstat/lib/survival_kaplan_meier.h +3 -6
- data/ext/sstat/lib/test_kaplan_meier.c +9 -2
- data/ext/sstat/sstat.c +56 -0
- data/ext/sstat/sstat.h +16 -10
- data/ext/sstat/sstat.o +0 -0
- data/ext/sstat/sstat.so +0 -0
- data/lib/simple_statistics.rb +0 -5
- data/lib/sstat.so +0 -0
- metadata +7 -3
- data/lib/simple_statistics/version.rb +0 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 61b0c98e6a838de0c30171c7ba698dd7ccb446e4
|
|
4
|
+
data.tar.gz: c5ebfe534e122751870fc4fda46481ec8b11b6f0
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4841789d8a2b606259e4cb4c9283dcd44a119dd5bbd9b7f984d9d184a9b9699e7cac2af7aa71da866bcb15e1781792db67ffe1be468732e322c5b9860f86497c
|
|
7
|
+
data.tar.gz: fef20644b53955330ff25c23b3dc6e21939d02f28586b4f86407ae53116a4f288c0b6e262b3ee22592dcf410a75a171f342139897a09c0c0e73787826a26c262
|
|
@@ -3,71 +3,73 @@
|
|
|
3
3
|
#include "histogram_type.h"
|
|
4
4
|
|
|
5
5
|
/*
|
|
6
|
-
*
|
|
6
|
+
* Mean of a histogram
|
|
7
|
+
* Compute the bin-weighted arithmetic mean M of a histogram using the recurrence relation
|
|
8
|
+
* M(n) = M(n-1) + (x[n] - M(n-1)) (w(n)/(W(n-1) + w(n)))
|
|
9
|
+
* W(n) = W(n-1) + w(n)
|
|
7
10
|
*/
|
|
8
|
-
int histogram_mean(const histogram* h,
|
|
11
|
+
int histogram_mean(const struct histogram* h, double* hmean)
|
|
9
12
|
{
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
int i, n;
|
|
14
|
+
double xi, wi;
|
|
15
|
+
(*hmean) = 0;
|
|
16
|
+
double W = 0;
|
|
17
|
+
n = h->n;
|
|
15
18
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
xi = (h->range[i+1] + h->range[i]) / 2;
|
|
20
|
-
wi = h->bin[i];
|
|
21
|
-
if(wi > 0)
|
|
22
|
-
{
|
|
23
|
-
W += wi;
|
|
24
|
-
hmean += (hmean - xi) * wi / W;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
19
|
+
for(i = 0; i < n; i++)
|
|
20
|
+
{
|
|
21
|
+
//make sure size of h->range is n + 1
|
|
27
22
|
|
|
28
|
-
|
|
29
|
-
|
|
23
|
+
xi = (h->range[i+1] + h->range[i]) / 2;
|
|
24
|
+
wi = h->bin[i];
|
|
25
|
+
if(wi > 0)
|
|
26
|
+
{
|
|
27
|
+
W += wi;
|
|
28
|
+
(*hmean) += (xi - (*hmean)) * wi / W;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return 0;
|
|
30
33
|
}
|
|
31
34
|
|
|
32
|
-
int histogram_bin_sum(const histogram* h,
|
|
35
|
+
int histogram_bin_sum(const struct histogram* h, double* sum)
|
|
33
36
|
{
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
37
|
+
size_t i, n;
|
|
38
|
+
(*sum) = 0;
|
|
39
|
+
n = h->n;
|
|
40
|
+
for(i = 0; i < n; i++)
|
|
41
|
+
{
|
|
42
|
+
(*sum) += h->bin[i];
|
|
43
|
+
}
|
|
41
44
|
|
|
42
|
-
|
|
43
|
-
return 0;
|
|
45
|
+
return 0;
|
|
44
46
|
}
|
|
45
47
|
|
|
46
|
-
int histogram_median(const histogram* h,
|
|
48
|
+
int histogram_median(const struct histogram* h, double* hmedian)
|
|
47
49
|
{
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
50
|
+
size_t i, n;
|
|
51
|
+
double sum, sum_50;
|
|
52
|
+
int proc_flag = histogram_bin_sum(h, &sum);
|
|
51
53
|
|
|
52
|
-
|
|
54
|
+
n = h->n;
|
|
53
55
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
+
if(proc_flag != 0)
|
|
57
|
+
return -1;
|
|
56
58
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
59
|
+
sum_50 = sum / 2.0;
|
|
60
|
+
sum = 0;
|
|
61
|
+
for(i = 0; i < n; i++)
|
|
62
|
+
{
|
|
63
|
+
sum += h->bin[i];
|
|
62
64
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
65
|
+
if(sum >= sum_50)
|
|
66
|
+
{
|
|
67
|
+
(*hmedian) = (h->range[i] + h->range[i+1]) / 2;
|
|
68
|
+
break;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
69
71
|
|
|
70
|
-
|
|
72
|
+
return 0;
|
|
71
73
|
}
|
|
72
74
|
|
|
73
75
|
#endif
|
|
Binary file
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
#include <stdlib.h>
|
|
2
|
+
#include <stdio.h>
|
|
3
|
+
|
|
4
|
+
#include "histogram.h"
|
|
5
|
+
|
|
6
|
+
int main(int argc, char const *argv[])
|
|
7
|
+
{
|
|
8
|
+
int n = 5;
|
|
9
|
+
int i = 0;
|
|
10
|
+
double hmean = 0;
|
|
11
|
+
double hmedian = 0;
|
|
12
|
+
struct histogram* h = (struct histogram*)malloc( sizeof(struct histogram));
|
|
13
|
+
|
|
14
|
+
h->range = malloc(sizeof(double) * (n + 1));
|
|
15
|
+
h->bin = malloc(sizeof(double) * (n));
|
|
16
|
+
|
|
17
|
+
for(i = 0; i < (n+1); i++)
|
|
18
|
+
h->range[i] = i;
|
|
19
|
+
|
|
20
|
+
h->bin[0] = 2;
|
|
21
|
+
h->bin[1] = 3;
|
|
22
|
+
h->bin[2] = 5;
|
|
23
|
+
h->bin[3] = 2;
|
|
24
|
+
h->bin[4] = 1;
|
|
25
|
+
|
|
26
|
+
h->n = n;
|
|
27
|
+
/* Test histogram mean */
|
|
28
|
+
histogram_mean(h, &hmean);
|
|
29
|
+
printf("histogram mean %f \n", hmean);
|
|
30
|
+
|
|
31
|
+
histogram_median(h, &hmedian);
|
|
32
|
+
printf("histogram median %f \n", hmedian);
|
|
33
|
+
|
|
34
|
+
free_histogram(h);
|
|
35
|
+
return 0;
|
|
36
|
+
}
|
|
@@ -3,12 +3,24 @@
|
|
|
3
3
|
/*
|
|
4
4
|
* The contain of this file is modified based on GSL lib
|
|
5
5
|
* */
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
typedef struct {
|
|
6
|
+
struct histogram {
|
|
9
7
|
size_t n ;
|
|
10
|
-
double * range ;
|
|
8
|
+
double * range ; /* size of range should be size of bin + 1 */
|
|
11
9
|
double * bin ;
|
|
12
|
-
}
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
void free_histogram(struct histogram* h)
|
|
13
|
+
{
|
|
14
|
+
if(h)
|
|
15
|
+
{
|
|
16
|
+
if(h->range)
|
|
17
|
+
free(h->range);
|
|
18
|
+
|
|
19
|
+
if(h->bin)
|
|
20
|
+
free(h->bin);
|
|
21
|
+
|
|
22
|
+
free(h);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
13
25
|
|
|
14
26
|
#endif
|
|
File without changes
|
|
@@ -102,10 +102,9 @@ int censored_uncensred_each_time_range(double* time, int* censored, int size, s
|
|
|
102
102
|
else
|
|
103
103
|
uncensored_num_at++;
|
|
104
104
|
|
|
105
|
-
|
|
105
|
+
/* If the last sample is censored, follow block stores counting for last time unique uncensored period */
|
|
106
106
|
if (i == size - 1)
|
|
107
107
|
{
|
|
108
|
-
count_at++;
|
|
109
108
|
(*cens_ucens_number)->uncensored[count_at] = uncensored_num_at;
|
|
110
109
|
(*cens_ucens_number)->censored[count_at] = censored_num_at;
|
|
111
110
|
}
|
|
@@ -180,8 +179,6 @@ void calculate_kaplan_meier(int size, const struct CENS_UC_NUM* cens_ucens_numbe
|
|
|
180
179
|
*/
|
|
181
180
|
int kaplan_meier(double* time, int* censored, int size, curve* KM_curve)
|
|
182
181
|
{
|
|
183
|
-
|
|
184
|
-
int i, N;
|
|
185
182
|
struct CENS_UC_NUM* cens_ucens_number;
|
|
186
183
|
|
|
187
184
|
censored_uncensred_each_time_range(time, censored, size, &cens_ucens_number);
|
|
@@ -282,7 +279,7 @@ int kaplan_meier_3p_extrapolation(double* time, int* censored, int size, struct
|
|
|
282
279
|
{
|
|
283
280
|
int proc_state = 0;
|
|
284
281
|
struct CENS_UC_NUM* cens_ucens_number;
|
|
285
|
-
censored_uncensred_each_time_range(time, censored, size, &cens_ucens_number);
|
|
282
|
+
proc_state = censored_uncensred_each_time_range(time, censored, size, &cens_ucens_number);
|
|
286
283
|
struct point* KM = alloc_points(size);
|
|
287
284
|
|
|
288
285
|
/* If the length of the inital KM curve is less than or equal to 7, we will not apply extrapolation */
|
|
@@ -304,7 +301,7 @@ int kaplan_meier_3p_extrapolation(double* time, int* censored, int size, struct
|
|
|
304
301
|
|
|
305
302
|
free_CENS_UC_NUM(&cens_ucens_number);
|
|
306
303
|
|
|
307
|
-
return
|
|
304
|
+
return proc_state;
|
|
308
305
|
}
|
|
309
306
|
|
|
310
307
|
#endif
|
|
@@ -1,14 +1,21 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* This content of this file is used to generate binary to test kaplan meier
|
|
3
|
+
*/
|
|
1
4
|
#include "survival_kaplan_meier.h"
|
|
2
5
|
|
|
3
6
|
int main(int argc, char const *argv[])
|
|
4
7
|
{
|
|
5
8
|
struct curve KM_curve;
|
|
9
|
+
struct curve KM_curve_3p;
|
|
6
10
|
|
|
7
11
|
double _time[14] = {1.0, 2.1, 3.2, 4.5, 5.5, 6.2, 7.4, 8.5, 9.1, 10.4, 11.3, 12.5, 13.2, 14.7};
|
|
8
12
|
int _censored[14] = {1, 0 , 0, 0, 1, 1, 1, 0 , 1, 1,0,1,0,1};
|
|
9
|
-
|
|
10
|
-
|
|
13
|
+
kaplan_meier(_time, _censored, 14, &KM_curve);
|
|
14
|
+
|
|
11
15
|
free(KM_curve.point_array);
|
|
12
16
|
|
|
17
|
+
kaplan_meier_3p_extrapolation(_time, _censored, 14, &KM_curve_3p);
|
|
18
|
+
free(KM_curve_3p.point_array);
|
|
19
|
+
|
|
13
20
|
return 0;
|
|
14
21
|
}
|
data/ext/sstat/sstat.c
CHANGED
|
@@ -52,6 +52,62 @@ static VALUE rb_index_less_equal(VALUE self, VALUE array, VALUE target)
|
|
|
52
52
|
return INT2NUM(_index);
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
+
static VALUE rb_hist_mean(VALUE self, VALUE bin, VALUE range)
|
|
56
|
+
{
|
|
57
|
+
int bin_size = RARRAY_LEN(bin);
|
|
58
|
+
int range_size = RARRAY_LEN(range);
|
|
59
|
+
int i;
|
|
60
|
+
|
|
61
|
+
if ((range_size - bin_size) != 1)
|
|
62
|
+
rb_raise(rb_eTypeError, "Size of range should be 1 larger than size of bin.");
|
|
63
|
+
|
|
64
|
+
double hmean = 0;
|
|
65
|
+
struct histogram* h = (struct histogram*)malloc(sizeof(struct histogram));
|
|
66
|
+
h->n = bin_size;
|
|
67
|
+
h->range = malloc(sizeof(double) * ( h->n + 1));
|
|
68
|
+
h->bin = malloc(sizeof(double) * (h->n));
|
|
69
|
+
|
|
70
|
+
for (i = 0; i < bin_size; i++) {
|
|
71
|
+
h->bin[i] = NUM2DBL(rb_ary_entry(bin, i));
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
for (i = 0; i < range_size; i++) {
|
|
75
|
+
h->range[i] = NUM2DBL(rb_ary_entry(range, i));
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
histogram_mean(h, &hmean);
|
|
79
|
+
free_histogram(h);
|
|
80
|
+
return DBL2NUM(hmean);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
static VALUE rb_hist_median(VALUE self, VALUE bin, VALUE range)
|
|
84
|
+
{
|
|
85
|
+
int bin_size = RARRAY_LEN(bin);
|
|
86
|
+
int range_size = RARRAY_LEN(range);
|
|
87
|
+
int i;
|
|
88
|
+
|
|
89
|
+
if ((range_size - bin_size) != 1)
|
|
90
|
+
rb_raise(rb_eTypeError, "Size of range should be 1 larger than size of bin.");
|
|
91
|
+
|
|
92
|
+
double hmedian = 0;
|
|
93
|
+
struct histogram* h = (struct histogram*)malloc(sizeof(struct histogram));
|
|
94
|
+
h->n = bin_size;
|
|
95
|
+
h->range = malloc(sizeof(double) * ( h->n + 1));
|
|
96
|
+
h->bin = malloc(sizeof(double) * (h->n));
|
|
97
|
+
|
|
98
|
+
for (i = 0; i < bin_size; i++) {
|
|
99
|
+
h->bin[i] = NUM2DBL(rb_ary_entry(bin, i));
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
for (i = 0; i < range_size; i++) {
|
|
103
|
+
h->range[i] = NUM2DBL(rb_ary_entry(range, i));
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
histogram_median(h, &hmedian);
|
|
107
|
+
free_histogram(h);
|
|
108
|
+
return DBL2NUM(hmedian);
|
|
109
|
+
}
|
|
110
|
+
|
|
55
111
|
static VALUE rb_kaplan_meier(VALUE self, VALUE time, VALUE censored)
|
|
56
112
|
{
|
|
57
113
|
int size = RARRAY_LEN(time);
|
data/ext/sstat/sstat.h
CHANGED
|
@@ -22,18 +22,24 @@ static VALUE rb_kaplan_meier_3p_extraploation(VALUE self, VALUE time, VALUE cens
|
|
|
22
22
|
static VALUE rb_log_rank_test(VALUE self, VALUE time_1, VALUE censor_1,VALUE time_2, VALUE censor_2);
|
|
23
23
|
|
|
24
24
|
static VALUE rb_cdf_unormal_Q(VALUE self, VALUE x);
|
|
25
|
+
static VALUE rb_hist_mean(VALUE self, VALUE bin, VALUE range);
|
|
26
|
+
static VALUE rb_hist_median(VALUE self, VALUE bin, VALUE range);
|
|
25
27
|
|
|
26
28
|
void Init_sstat() {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
29
|
+
VALUE sstat_module = rb_define_module("SStat");
|
|
30
|
+
VALUE surv_class = rb_define_class_under(sstat_module, "Surv", rb_cObject);
|
|
31
|
+
VALUE dist_class = rb_define_class_under(sstat_module, "Dist", rb_cObject);
|
|
32
|
+
VALUE hist_class = rb_define_class_under(sstat_module, "Hist", rb_cObject);
|
|
33
|
+
rb_define_method(surv_class, "percentile_index", rb_percentile_index, 2);
|
|
34
|
+
rb_define_method(surv_class, "percentile", rb_percentile, 2);
|
|
35
|
+
rb_define_method(surv_class, "index_less_equal", rb_index_less_equal, 2);
|
|
36
|
+
rb_define_method(surv_class, "kaplan_meier", rb_kaplan_meier, 2);
|
|
37
|
+
rb_define_method(surv_class, "log_rank_test", rb_log_rank_test, 4);
|
|
38
|
+
rb_define_method(surv_class, "kaplan_meier_3p_extraploation", rb_kaplan_meier_3p_extraploation, 2);
|
|
39
|
+
rb_define_method(dist_class, "cdf_unormal_Q", rb_cdf_unormal_Q, 1);
|
|
40
|
+
rb_define_method(hist_class, "hist_mean", rb_hist_mean, 2);
|
|
41
|
+
rb_define_method(hist_class, "hist_median", rb_hist_median, 2);
|
|
42
|
+
|
|
37
43
|
}
|
|
38
44
|
|
|
39
45
|
#endif
|
data/ext/sstat/sstat.o
CHANGED
|
Binary file
|
data/ext/sstat/sstat.so
CHANGED
|
Binary file
|
data/lib/simple_statistics.rb
CHANGED
data/lib/sstat.so
CHANGED
|
Binary file
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: sstat
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.8
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Haipeng Li
|
|
@@ -10,7 +10,7 @@ authors:
|
|
|
10
10
|
autorequire:
|
|
11
11
|
bindir: bin
|
|
12
12
|
cert_chain: []
|
|
13
|
-
date: 2016-
|
|
13
|
+
date: 2016-08-17 00:00:00.000000000 Z
|
|
14
14
|
dependencies: []
|
|
15
15
|
description:
|
|
16
16
|
email: haipeng3@ualberta.ca
|
|
@@ -33,12 +33,17 @@ files:
|
|
|
33
33
|
- ext/lib/type_def.h
|
|
34
34
|
- ext/sstat/Makefile
|
|
35
35
|
- ext/sstat/extconf.rb
|
|
36
|
+
- ext/sstat/lib/basic/basic.c
|
|
36
37
|
- ext/sstat/lib/distribution.h
|
|
37
38
|
- ext/sstat/lib/global_utility.h
|
|
38
39
|
- ext/sstat/lib/histogram/histogram.h
|
|
39
40
|
- ext/sstat/lib/histogram/histogram_error.h
|
|
40
41
|
- ext/sstat/lib/histogram/histogram_stat.h
|
|
42
|
+
- ext/sstat/lib/histogram/histogram_test
|
|
43
|
+
- ext/sstat/lib/histogram/histogram_test.c
|
|
41
44
|
- ext/sstat/lib/histogram/histogram_type.h
|
|
45
|
+
- ext/sstat/lib/histogram/log
|
|
46
|
+
- ext/sstat/lib/histogram/test.sh
|
|
42
47
|
- ext/sstat/lib/km
|
|
43
48
|
- ext/sstat/lib/survival.h
|
|
44
49
|
- ext/sstat/lib/survival_def.h
|
|
@@ -52,7 +57,6 @@ files:
|
|
|
52
57
|
- ext/sstat/sstat.o
|
|
53
58
|
- ext/sstat/sstat.so
|
|
54
59
|
- lib/simple_statistics.rb
|
|
55
|
-
- lib/simple_statistics/version.rb
|
|
56
60
|
- lib/sstat.so
|
|
57
61
|
homepage:
|
|
58
62
|
licenses: []
|