sstat 0.0.8 → 0.0.9
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/lib/survival_func.h +1 -0
- data/ext/lib/survival_utility.h +1 -0
- data/ext/sstat/lib/basic/log +4 -0
- data/ext/sstat/lib/basic/median.h +47 -0
- data/ext/sstat/lib/basic/median_test +0 -0
- data/ext/sstat/lib/basic/median_test.c +11 -0
- data/ext/sstat/lib/basic/utility.h +42 -0
- data/ext/sstat/lib/histogram/histogram_test.c +1 -0
- data/ext/sstat/lib/{distribution.h → survival/distribution.h} +1 -1
- data/ext/sstat/lib/survival/global_utility.h +21 -0
- data/ext/sstat/lib/{survival.h → survival/survival.h} +0 -0
- data/ext/sstat/lib/{survival_def.h → survival/survival_def.h} +0 -0
- data/ext/sstat/lib/{survival_func.h → survival/survival_func.h} +11 -4
- data/ext/sstat/lib/{survival_kaplan_meier.h → survival/survival_kaplan_meier.h} +1 -1
- data/ext/sstat/lib/{survival_utility.h → survival/survival_utility.h} +0 -0
- data/ext/sstat/lib/{test_kaplan_meier.c → survival/test_kaplan_meier.c} +0 -0
- data/ext/sstat/lib/{type_def.h → survival/type_def.h} +0 -0
- data/ext/sstat/sstat.c +1 -1
- data/ext/sstat/sstat.h +2 -3
- data/ext/sstat/sstat.o +0 -0
- data/ext/sstat/sstat.so +0 -0
- data/lib/sstat.so +0 -0
- metadata +16 -12
- data/ext/sstat/lib/basic/basic.c +0 -4
- data/ext/sstat/lib/km +0 -0
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 843d3d96c90916264fd977b3adc810b232350c98
|
|
4
|
+
data.tar.gz: 8c585198944119c3981eb3c76fed0db7f6f2f35f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d444d31fb1ec4432aaf324ea902710e8d61a32a6109cfbeea5ee80032cdafe9ff41e0afa531ce3a08d87d47928fc8c664dd0dfdf7aadad977f0d9116beffe562
|
|
7
|
+
data.tar.gz: 107902e5f175e919ea220fa3b222e16a468dfaa95c29afc942dbee89f7aee29e79ca43c5a3c15d24c1e0b74872e1ef506ff68271cb3a9fa22655363cea54fe65
|
data/ext/lib/survival_func.h
CHANGED
data/ext/lib/survival_utility.h
CHANGED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
#ifndef _BASIC_MEDIAN_H_
|
|
2
|
+
#define _BASIC_MEDIAN_H_
|
|
3
|
+
|
|
4
|
+
#include "utility.h"
|
|
5
|
+
#include <stdio.h>
|
|
6
|
+
#include <stdlib.h>
|
|
7
|
+
|
|
8
|
+
int median_for_sorted_data(const double* sorted_data, int n, double* median)
|
|
9
|
+
{
|
|
10
|
+
const int lhs = (n - 1) / 2 ;
|
|
11
|
+
const int rhs = n / 2 ;
|
|
12
|
+
|
|
13
|
+
if(n == 0)
|
|
14
|
+
{
|
|
15
|
+
(*median) = 0;
|
|
16
|
+
return 0;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
if (lhs == rhs)
|
|
20
|
+
{
|
|
21
|
+
(*median) = sorted_data[lhs] ;
|
|
22
|
+
}
|
|
23
|
+
else
|
|
24
|
+
{
|
|
25
|
+
(*median) = (sorted_data[lhs] + sorted_data[rhs])/2.0 ;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return 0;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
int median(const double* data, int n, double* median)
|
|
32
|
+
{
|
|
33
|
+
int i;
|
|
34
|
+
double* data_cpy = (double *) malloc(sizeof(double) * n);
|
|
35
|
+
for(i = 0; i < n; i++)
|
|
36
|
+
{
|
|
37
|
+
data_cpy[i] = data[i];
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
qsort(data_cpy, n, sizeof(double), &compare_double);
|
|
41
|
+
|
|
42
|
+
median_for_sorted_data(data_cpy, n, median);
|
|
43
|
+
free(data_cpy);
|
|
44
|
+
return 0;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
#endif
|
|
Binary file
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
#include "median.h"
|
|
2
|
+
|
|
3
|
+
int main(int argc, char const *argv[])
|
|
4
|
+
{
|
|
5
|
+
double data[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 };
|
|
6
|
+
double m;
|
|
7
|
+
int proc = median(data, 14, &m);
|
|
8
|
+
printf("Median %f \n", m);
|
|
9
|
+
|
|
10
|
+
return 0;
|
|
11
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
#ifndef _BASIC_MEDIAN_H_
|
|
2
|
+
#define _BASIC_MEDIAN_H_
|
|
3
|
+
|
|
4
|
+
/* error macro */
|
|
5
|
+
#include <stdlib>
|
|
6
|
+
#include <stdio.h>
|
|
7
|
+
#include <errno.h>
|
|
8
|
+
#include <string.h>
|
|
9
|
+
|
|
10
|
+
#ifdef NDEBUG
|
|
11
|
+
#define debug(M, ...)
|
|
12
|
+
#else
|
|
13
|
+
#define debug(M, ...) fprintf(stderr, "DEBUG %s:%d: " M "\n", __FILE__, __LINE__, ##__VA_ARGS__)
|
|
14
|
+
#endif
|
|
15
|
+
|
|
16
|
+
#define clean_errno() (errno == 0 ? "None" : strerror(errno))
|
|
17
|
+
|
|
18
|
+
#define log_err(M, ...) fprintf(stderr, "[ERROR] (%s:%d: errno: %s) " M "\n", __FILE__, __LINE__, clean_errno(), ##__VA_ARGS__)
|
|
19
|
+
|
|
20
|
+
#define log_warn(M, ...) fprintf(stderr, "[WARN] (%s:%d: errno: %s) " M "\n", __FILE__, __LINE__, clean_errno(), ##__VA_ARGS__)
|
|
21
|
+
|
|
22
|
+
#define log_info(M, ...) fprintf(stderr, "[INFO] (%s:%d) " M "\n", __FILE__, __LINE__, ##__VA_ARGS__)
|
|
23
|
+
|
|
24
|
+
#define check(A, M, ...) if(!(A)) { log_err(M, ##__VA_ARGS__); errno=0; goto error; }
|
|
25
|
+
|
|
26
|
+
#define sentinel(M, ...) { log_err(M, ##__VA_ARGS__); errno=0; goto error; }
|
|
27
|
+
|
|
28
|
+
#define check_mem(A) check((A), "Out of memory.")
|
|
29
|
+
|
|
30
|
+
#define check_debug(A, M, ...) if(!(A)) { debug(M, ##__VA_ARGS__); errno=0; goto error; }
|
|
31
|
+
|
|
32
|
+
#endif
|
|
33
|
+
|
|
34
|
+
int compare_double (const void * a, const void * b)
|
|
35
|
+
{
|
|
36
|
+
return *((double*)a) > *((double*)b)? 1 : 0;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
enum ERRORS {
|
|
40
|
+
OUTOF_MEMORY_ERROR = 1,
|
|
41
|
+
NOT_EMPTY_ERROR = 2,
|
|
42
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
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
|
+
double diff = (double)(((struct point*)a)->x) - (double)(((struct point*)b)->x);
|
|
15
|
+
if(diff > 0)
|
|
16
|
+
return 1;
|
|
17
|
+
else
|
|
18
|
+
return 0;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
#endif
|
|
File without changes
|
|
File without changes
|
|
@@ -51,7 +51,7 @@ double log_rank_test(double* time_1, int* censored_1, double* time_2, int* censo
|
|
|
51
51
|
{
|
|
52
52
|
int i, time_pnt_size;
|
|
53
53
|
int index;
|
|
54
|
-
|
|
54
|
+
|
|
55
55
|
array merged_time_pnts = merge_two_array(time_1, size_1, time_2, size_2);
|
|
56
56
|
array merged_uniq_time_pnts = create_sorted_unique_array(merged_time_pnts.D_ptr, merged_time_pnts.size);
|
|
57
57
|
|
|
@@ -126,9 +126,14 @@ double log_rank_test(double* time_1, int* censored_1, double* time_2, int* censo
|
|
|
126
126
|
|
|
127
127
|
for (i = 0; i < time_pnt_size; ++i)
|
|
128
128
|
{
|
|
129
|
-
|
|
129
|
+
|
|
130
|
+
N_i[i] = (N1_at_risk[i] + N2_at_risk[i]);
|
|
131
|
+
|
|
130
132
|
O_i[i] = (combined_Group_N_1.uncensored[i] + combined_Group_N_2.uncensored[i]);
|
|
131
|
-
|
|
133
|
+
|
|
134
|
+
if(N_i[i] != 0)
|
|
135
|
+
{
|
|
136
|
+
E_i[i] = 1.0 * N1_at_risk[i] * O_i[i] / N_i[i];
|
|
132
137
|
|
|
133
138
|
if (N_i[i] > 1)
|
|
134
139
|
{
|
|
@@ -140,10 +145,12 @@ double log_rank_test(double* time_1, int* censored_1, double* time_2, int* censo
|
|
|
140
145
|
V_i_sum += V_i[i];
|
|
141
146
|
}
|
|
142
147
|
|
|
143
|
-
|
|
148
|
+
Z += (combined_Group_N_1.uncensored[i] - E_i[i]);
|
|
149
|
+
}
|
|
144
150
|
}
|
|
145
151
|
|
|
146
152
|
Z = Z / sqrt(V_i_sum);
|
|
153
|
+
|
|
147
154
|
free(Group_N_1.uncensored);
|
|
148
155
|
free(Group_N_1.censored);
|
|
149
156
|
free(Group_N_2.uncensored);
|
|
@@ -234,7 +234,7 @@ int KM_3p_extrapolation(struct CENS_UC_NUM** cens_uc_num, struct CENS_UC_NUM** u
|
|
|
234
234
|
mean_last_uncensored = mean_last_uncensored / 3;
|
|
235
235
|
mean_last_censored = mean_last_censored / 3;
|
|
236
236
|
time_interval_mean = time_interval_mean / 3;
|
|
237
|
-
|
|
237
|
+
|
|
238
238
|
/* Calculate how many points we should extrapolate */
|
|
239
239
|
extrapolation_size = ceil((double)num_left / (mean_last_uncensored + mean_last_censored));
|
|
240
240
|
updated_cens_uc_num_size = (*cens_uc_num)->size + extrapolation_size;
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
data/ext/sstat/sstat.c
CHANGED
|
@@ -202,7 +202,6 @@ static VALUE rb_log_rank_test(VALUE self, VALUE _time_1, VALUE _cens_1, VALUE _t
|
|
|
202
202
|
double* time_2 = (double *)malloc(sizeof(double) * size_2);
|
|
203
203
|
int* cens_1 = (int *)malloc(sizeof(int) * size_1);
|
|
204
204
|
int* cens_2 = (int *)malloc(sizeof(int) * size_2);
|
|
205
|
-
|
|
206
205
|
for (i = 0; i < size_1; i++) {
|
|
207
206
|
time_1[i] = NUM2DBL(rb_ary_entry(_time_1, i));
|
|
208
207
|
cens_1[i] = NUM2INT(rb_ary_entry(_cens_1, i));
|
|
@@ -212,6 +211,7 @@ static VALUE rb_log_rank_test(VALUE self, VALUE _time_1, VALUE _cens_1, VALUE _t
|
|
|
212
211
|
time_2[i] = NUM2DBL(rb_ary_entry(_time_2, i));
|
|
213
212
|
cens_2[i] = NUM2INT(rb_ary_entry(_cens_2, i));
|
|
214
213
|
}
|
|
214
|
+
|
|
215
215
|
_Z = log_rank_test(time_1, cens_1, time_2, cens_2, size_1, size_2);
|
|
216
216
|
|
|
217
217
|
free(time_1);
|
data/ext/sstat/sstat.h
CHANGED
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
#include <ruby.h>
|
|
4
4
|
#include <stdio.h>
|
|
5
5
|
#include <stdlib.h>
|
|
6
|
-
#include "lib/survival.h"
|
|
6
|
+
#include "lib/survival/survival.h"
|
|
7
|
+
#include "lib/survival/distribution.h"
|
|
7
8
|
#include "lib/global_utility.h"
|
|
8
|
-
#include "lib/distribution.h"
|
|
9
9
|
#include "lib/histogram/histogram.h"
|
|
10
10
|
|
|
11
11
|
static VALUE rb_percentile(VALUE self, VALUE arg, VALUE target);
|
|
@@ -39,7 +39,6 @@ void Init_sstat() {
|
|
|
39
39
|
rb_define_method(dist_class, "cdf_unormal_Q", rb_cdf_unormal_Q, 1);
|
|
40
40
|
rb_define_method(hist_class, "hist_mean", rb_hist_mean, 2);
|
|
41
41
|
rb_define_method(hist_class, "hist_median", rb_hist_median, 2);
|
|
42
|
-
|
|
43
42
|
}
|
|
44
43
|
|
|
45
44
|
#endif
|
data/ext/sstat/sstat.o
CHANGED
|
Binary file
|
data/ext/sstat/sstat.so
CHANGED
|
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.
|
|
4
|
+
version: 0.0.9
|
|
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-09-06 00:00:00.000000000 Z
|
|
14
14
|
dependencies: []
|
|
15
15
|
description:
|
|
16
16
|
email: haipeng3@ualberta.ca
|
|
@@ -33,8 +33,11 @@ files:
|
|
|
33
33
|
- ext/lib/type_def.h
|
|
34
34
|
- ext/sstat/Makefile
|
|
35
35
|
- ext/sstat/extconf.rb
|
|
36
|
-
- ext/sstat/lib/basic/
|
|
37
|
-
- ext/sstat/lib/
|
|
36
|
+
- ext/sstat/lib/basic/log
|
|
37
|
+
- ext/sstat/lib/basic/median.h
|
|
38
|
+
- ext/sstat/lib/basic/median_test
|
|
39
|
+
- ext/sstat/lib/basic/median_test.c
|
|
40
|
+
- ext/sstat/lib/basic/utility.h
|
|
38
41
|
- ext/sstat/lib/global_utility.h
|
|
39
42
|
- ext/sstat/lib/histogram/histogram.h
|
|
40
43
|
- ext/sstat/lib/histogram/histogram_error.h
|
|
@@ -44,14 +47,15 @@ files:
|
|
|
44
47
|
- ext/sstat/lib/histogram/histogram_type.h
|
|
45
48
|
- ext/sstat/lib/histogram/log
|
|
46
49
|
- ext/sstat/lib/histogram/test.sh
|
|
47
|
-
- ext/sstat/lib/
|
|
48
|
-
- ext/sstat/lib/survival.h
|
|
49
|
-
- ext/sstat/lib/
|
|
50
|
-
- ext/sstat/lib/
|
|
51
|
-
- ext/sstat/lib/
|
|
52
|
-
- ext/sstat/lib/
|
|
53
|
-
- ext/sstat/lib/
|
|
54
|
-
- ext/sstat/lib/
|
|
50
|
+
- ext/sstat/lib/survival/distribution.h
|
|
51
|
+
- ext/sstat/lib/survival/global_utility.h
|
|
52
|
+
- ext/sstat/lib/survival/survival.h
|
|
53
|
+
- ext/sstat/lib/survival/survival_def.h
|
|
54
|
+
- ext/sstat/lib/survival/survival_func.h
|
|
55
|
+
- ext/sstat/lib/survival/survival_kaplan_meier.h
|
|
56
|
+
- ext/sstat/lib/survival/survival_utility.h
|
|
57
|
+
- ext/sstat/lib/survival/test_kaplan_meier.c
|
|
58
|
+
- ext/sstat/lib/survival/type_def.h
|
|
55
59
|
- ext/sstat/sstat.c
|
|
56
60
|
- ext/sstat/sstat.h
|
|
57
61
|
- ext/sstat/sstat.o
|
data/ext/sstat/lib/basic/basic.c
DELETED
data/ext/sstat/lib/km
DELETED
|
Binary file
|