sstat 0.0.10 → 0.0.11

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.
data/ext/sstat/sstat.h CHANGED
@@ -3,6 +3,7 @@
3
3
  #include <ruby.h>
4
4
  #include <stdio.h>
5
5
  #include <stdlib.h>
6
+
6
7
  #include "lib/survival/survival.h"
7
8
  #include "lib/survival/distribution.h"
8
9
  #include "lib/global_utility.h"
@@ -22,21 +23,33 @@ static VALUE rb_kaplan_meier_3p_extraploation(VALUE self, VALUE time, VALUE cens
22
23
  static VALUE rb_log_rank_test(VALUE self, VALUE time_1, VALUE censor_1,VALUE time_2, VALUE censor_2);
23
24
 
24
25
  static VALUE rb_cdf_unormal_Q(VALUE self, VALUE x);
26
+
27
+ static VALUE rb_dist_chi_square_Q(VALUE self, VALUE index, VALUE degree);
28
+ static VALUE rb_dist_chi_square_P(VALUE self, VALUE index, VALUE degree);
29
+
25
30
  static VALUE rb_hist_mean(VALUE self, VALUE bin, VALUE range);
26
31
  static VALUE rb_hist_median(VALUE self, VALUE bin, VALUE range);
27
32
 
33
+ static VALUE rb_basic_(VALUE self, VALUE bin, VALUE range);
34
+
28
35
  void Init_sstat() {
29
36
  VALUE sstat_module = rb_define_module("SStat");
30
37
  VALUE surv_class = rb_define_class_under(sstat_module, "Surv", rb_cObject);
31
38
  VALUE dist_class = rb_define_class_under(sstat_module, "Dist", rb_cObject);
32
39
  VALUE hist_class = rb_define_class_under(sstat_module, "Hist", rb_cObject);
40
+
41
+ /* Functions for basic */
33
42
  rb_define_method(surv_class, "percentile_index", rb_percentile_index, 2);
34
43
  rb_define_method(surv_class, "percentile", rb_percentile, 2);
35
44
  rb_define_method(surv_class, "index_less_equal", rb_index_less_equal, 2);
36
45
  rb_define_method(surv_class, "kaplan_meier", rb_kaplan_meier, 2);
37
46
  rb_define_method(surv_class, "log_rank_test", rb_log_rank_test, 4);
38
47
  rb_define_method(surv_class, "kaplan_meier_3p_extraploation", rb_kaplan_meier_3p_extraploation, 2);
48
+
49
+ /* Functions for distribution */
39
50
  rb_define_method(dist_class, "cdf_unormal_Q", rb_cdf_unormal_Q, 1);
51
+
52
+ /* Functions for histogram */
40
53
  rb_define_method(hist_class, "hist_mean", rb_hist_mean, 2);
41
54
  rb_define_method(hist_class, "hist_median", rb_hist_median, 2);
42
55
  }
data/ext/sstat/sstat.o CHANGED
Binary file
data/ext/sstat/sstat.so CHANGED
Binary file
data/lib/sstat.o ADDED
Binary file
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.10
4
+ version: 0.0.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Haipeng Li
@@ -10,30 +10,20 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2016-09-06 00:00:00.000000000 Z
13
+ date: 2016-11-17 00:00:00.000000000 Z
14
14
  dependencies: []
15
15
  description:
16
16
  email: haipeng3@ualberta.ca
17
17
  executables: []
18
18
  extensions:
19
- - ext/extconf.rb
20
19
  - ext/sstat/extconf.rb
21
20
  extra_rdoc_files: []
22
21
  files:
23
22
  - bin/#console#
24
23
  - bin/console
25
24
  - bin/setup
26
- - ext/extconf.rb
27
- - ext/lib/distribution.h
28
- - ext/lib/global_utility.h
29
- - ext/lib/survival.h
30
- - ext/lib/survival_def.h
31
- - ext/lib/survival_func.h
32
- - ext/lib/survival_utility.h
33
- - ext/lib/type_def.h
34
25
  - ext/sstat/Makefile
35
26
  - ext/sstat/extconf.rb
36
- - ext/sstat/lib/basic/log
37
27
  - ext/sstat/lib/basic/median.h
38
28
  - ext/sstat/lib/basic/median_test
39
29
  - ext/sstat/lib/basic/median_test.c
@@ -47,6 +37,7 @@ files:
47
37
  - ext/sstat/lib/histogram/histogram_type.h
48
38
  - ext/sstat/lib/histogram/log
49
39
  - ext/sstat/lib/histogram/test.sh
40
+ - ext/sstat/lib/survival.tar.gz
50
41
  - ext/sstat/lib/survival/distribution.h
51
42
  - ext/sstat/lib/survival/global_utility.h
52
43
  - ext/sstat/lib/survival/survival.h
@@ -61,6 +52,7 @@ files:
61
52
  - ext/sstat/sstat.o
62
53
  - ext/sstat/sstat.so
63
54
  - lib/simple_statistics.rb
55
+ - lib/sstat.o
64
56
  - lib/sstat.so
65
57
  homepage:
66
58
  licenses:
data/ext/extconf.rb DELETED
@@ -1,4 +0,0 @@
1
- require 'mkmf'
2
- $CFLAGS << ' -std=gnu99 -Wno-declaration-after-statement'
3
-
4
- create_makefile('sstat')
@@ -1,274 +0,0 @@
1
- #ifndef _SSTAT_DISTRIBUTION_UTILITY_H_
2
- #define _SSTAT_DISTRIBUTION_UTILITY_H_
3
- #include "type_def.h"
4
- static double
5
- get_del (double x, double rational)
6
- {
7
- double xsq = 0.0;
8
- double del = 0.0;
9
- double result = 0.0;
10
-
11
- xsq = floor (x * GAUSS_SCALE) / GAUSS_SCALE;
12
- del = (x - xsq) * (x + xsq);
13
- del *= 0.5;
14
-
15
- result = exp (-0.5 * xsq * xsq) * exp (-1.0 * del) * rational;
16
-
17
- return result;
18
- }
19
-
20
- /*
21
- * Normal cdf for fabs(x) < 0.66291
22
- */
23
- static double
24
- gauss_small (const double x)
25
- {
26
- unsigned int i;
27
- double result = 0.0;
28
- double xsq;
29
- double xnum;
30
- double xden;
31
-
32
- const double a[5] = {
33
- 2.2352520354606839287,
34
- 161.02823106855587881,
35
- 1067.6894854603709582,
36
- 18154.981253343561249,
37
- 0.065682337918207449113
38
- };
39
- const double b[4] = {
40
- 47.20258190468824187,
41
- 976.09855173777669322,
42
- 10260.932208618978205,
43
- 45507.789335026729956
44
- };
45
-
46
- xsq = x * x;
47
- xnum = a[4] * xsq;
48
- xden = xsq;
49
-
50
- for (i = 0; i < 3; i++)
51
- {
52
- xnum = (xnum + a[i]) * xsq;
53
- xden = (xden + b[i]) * xsq;
54
- }
55
-
56
- result = x * (xnum + a[3]) / (xden + b[3]);
57
-
58
- return result;
59
- }
60
-
61
- /*
62
- * Normal cdf for 0.66291 < fabs(x) < sqrt(32).
63
- */
64
- static double
65
- gauss_medium (const double x)
66
- {
67
- unsigned int i;
68
- double temp = 0.0;
69
- double result = 0.0;
70
- double xnum;
71
- double xden;
72
- double absx;
73
-
74
- const double c[9] = {
75
- 0.39894151208813466764,
76
- 8.8831497943883759412,
77
- 93.506656132177855979,
78
- 597.27027639480026226,
79
- 2494.5375852903726711,
80
- 6848.1904505362823326,
81
- 11602.651437647350124,
82
- 9842.7148383839780218,
83
- 1.0765576773720192317e-8
84
- };
85
- const double d[8] = {
86
- 22.266688044328115691,
87
- 235.38790178262499861,
88
- 1519.377599407554805,
89
- 6485.558298266760755,
90
- 18615.571640885098091,
91
- 34900.952721145977266,
92
- 38912.003286093271411,
93
- 19685.429676859990727
94
- };
95
-
96
- absx = fabs (x);
97
-
98
- xnum = c[8] * absx;
99
- xden = absx;
100
-
101
- for (i = 0; i < 7; i++)
102
- {
103
- xnum = (xnum + c[i]) * absx;
104
- xden = (xden + d[i]) * absx;
105
- }
106
-
107
- temp = (xnum + c[7]) / (xden + d[7]);
108
-
109
- result = get_del (x, temp);
110
-
111
- return result;
112
- }
113
-
114
- /*
115
- * Normal cdf for
116
- * {sqrt(32) < x < GAUSS_XUPPER} union { GAUSS_XLOWER < x < -sqrt(32) }.
117
- */
118
- static double
119
- gauss_large (const double x)
120
- {
121
- int i;
122
- double result;
123
- double xsq;
124
- double temp;
125
- double xnum;
126
- double xden;
127
- double absx;
128
-
129
- const double p[6] = {
130
- 0.21589853405795699,
131
- 0.1274011611602473639,
132
- 0.022235277870649807,
133
- 0.001421619193227893466,
134
- 2.9112874951168792e-5,
135
- 0.02307344176494017303
136
- };
137
- const double q[5] = {
138
- 1.28426009614491121,
139
- 0.468238212480865118,
140
- 0.0659881378689285515,
141
- 0.00378239633202758244,
142
- 7.29751555083966205e-5
143
- };
144
-
145
- absx = fabs (x);
146
- xsq = 1.0 / (x * x);
147
- xnum = p[5] * xsq;
148
- xden = xsq;
149
-
150
- for (i = 0; i < 4; i++)
151
- {
152
- xnum = (xnum + p[i]) * xsq;
153
- xden = (xden + q[i]) * xsq;
154
- }
155
-
156
- temp = xsq * (xnum + p[4]) / (xden + q[4]);
157
- temp = (M_1_SQRT2PI - temp) / absx;
158
-
159
- result = get_del (x, temp);
160
-
161
- return result;
162
- }
163
-
164
- double
165
- gsl_cdf_ugaussian_P (const double x)
166
- {
167
- double result;
168
- double absx = fabs (x);
169
-
170
- if (absx < GAUSS_EPSILON)
171
- {
172
- result = 0.5;
173
- return result;
174
- }
175
- else if (absx < 0.66291)
176
- {
177
- result = 0.5 + gauss_small (x);
178
- return result;
179
- }
180
- else if (absx < SQRT32)
181
- {
182
- result = gauss_medium (x);
183
-
184
- if (x > 0.0)
185
- {
186
- result = 1.0 - result;
187
- }
188
-
189
- return result;
190
- }
191
- else if (x > GAUSS_XUPPER)
192
- {
193
- result = 1.0;
194
- return result;
195
- }
196
- else if (x < GAUSS_XLOWER)
197
- {
198
- result = 0.0;
199
- return result;
200
- }
201
- else
202
- {
203
- result = gauss_large (x);
204
-
205
- if (x > 0.0)
206
- {
207
- result = 1.0 - result;
208
- }
209
- }
210
-
211
- return result;
212
- }
213
-
214
- double
215
- cdf_ugaussian_Q (const double x)
216
- {
217
- double result;
218
- double absx = fabs (x);
219
-
220
- if (absx < GAUSS_EPSILON)
221
- {
222
- result = 0.5;
223
- return result;
224
- }
225
- else if (absx < 0.66291)
226
- {
227
- result = gauss_small (x);
228
-
229
- if (x < 0.0)
230
- {
231
- result = fabs (result) + 0.5;
232
- }
233
- else
234
- {
235
- result = 0.5 - result;
236
- }
237
-
238
- return result;
239
- }
240
- else if (absx < SQRT32)
241
- {
242
- result = gauss_medium (x);
243
-
244
- if (x < 0.0)
245
- {
246
- result = 1.0 - result;
247
- }
248
-
249
- return result;
250
- }
251
- else if (x > -(GAUSS_XLOWER))
252
- {
253
- result = 0.0;
254
- return result;
255
- }
256
- else if (x < -(GAUSS_XUPPER))
257
- {
258
- result = 1.0;
259
- return result;
260
- }
261
- else
262
- {
263
- result = gauss_large (x);
264
-
265
- if (x < 0.0)
266
- {
267
- result = 1.0 - result;
268
- }
269
-
270
- }
271
-
272
- return result;
273
- }
274
- #endif
@@ -1,17 +0,0 @@
1
- #ifndef _SSTAT_GLOBAL_UTILITY_H_
2
- #define _SSTAT_GLOBAL_UTILITY_H_
3
- #include <stdio.h>
4
- #include <stdlib.h>
5
- #include "type_def.h"
6
-
7
- int compare_double (const void * a, const void * b)
8
- {
9
- return *((double*)a) > *((double*)b)? 1 : 0;
10
- }
11
-
12
- int point_compare_x (const void * a, const void * b)
13
- {
14
- return ((struct point*)a)->x - ((struct point*)b)->x;
15
- }
16
-
17
- #endif
data/ext/lib/survival.h DELETED
@@ -1,6 +0,0 @@
1
- #ifndef _SURVIVAL_STAT_H_
2
- #define _SURVIVAL_STAT_H_
3
-
4
- #include "survival_func.h"
5
-
6
- #endif
@@ -1,49 +0,0 @@
1
- #ifndef _SURVIVAL_STAT_DEF_H_
2
- #define _SURVIVAL_STAT_DEF_H_
3
-
4
- #include "type_def.h"
5
- #include <stdio>
6
- #include <stdlib>
7
-
8
- /* Define survival stat data structure */
9
- typedef struct Group_N
10
- {
11
- /* Time stands for the event time */
12
- double* time;
13
-
14
- /* How many people died at different event times */
15
- int * uncensored;
16
-
17
- /* How many people censored at different event times */
18
- int * censored;
19
-
20
- int size;
21
-
22
- } Group_N;
23
-
24
- void free_Group_N(struct Group_N* grp_n)
25
- {
26
- if(grp_n->time != NULL)
27
- free(grp_n->time);
28
-
29
- if(grp_n->uncensored != NULL )
30
- free(grp_n->uncensored);
31
-
32
- if(grp_n->censored != NULL )
33
- free(grp_n->censored);
34
- }
35
-
36
- void put_Group_N(struct Group_N * grp_n)
37
- {
38
- int i;
39
- puts("Start to print out Group N");
40
- for( i = 0; i < grp_n->size; i++ )
41
- {
42
- printf("Time : %f -- Uncensored : %f -- Censored : %f \n",
43
- grp_n-> time[i],
44
- grp_n-> uncensored[i],
45
- grp_n-> censored[i]);
46
- }
47
- }
48
-
49
- #endif