sstat 0.0.5 → 0.0.6
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_def.h +2 -0
- data/ext/lib/survival_func.h +0 -1
- data/ext/sstat/Makefile +238 -0
- data/ext/sstat/lib/km +0 -0
- data/ext/sstat/lib/survival_def.h +14 -14
- data/ext/sstat/lib/survival_kaplan_meier.h +49 -50
- data/ext/sstat/lib/survival_utility.h +5 -2
- data/ext/sstat/lib/test_kaplan_meier.c +14 -0
- data/ext/sstat/lib/type_def.h +3 -1
- data/ext/sstat/sstat.c +1 -1
- data/ext/sstat/sstat.o +0 -0
- data/ext/sstat/sstat.so +0 -0
- data/lib/simple_statistics/version.rb +1 -1
- data/lib/sstat.so +0 -0
- metadata +7 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d61f133522ad431b5b1d5e1c46108b06cedde6c7
|
|
4
|
+
data.tar.gz: 7dce85fc0abf74bd51773990fdcd92237f5db144
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f8a8c976017428dc0d6b3f1c4022f2b0eccd6453764060db49e9d4ec846219e48dc29eb3c37a5970e9012d500eef986e91f4e9054daab9a7594f207faf07fa15
|
|
7
|
+
data.tar.gz: e05eebcaba60be2548a8af81e67c3892b34bd4138c6e6b86336ff41fa4a8d7159b5c742043bbdc5a895959b793089bce7fb644fe85a7c02e0d9e81d7f17f4d2c
|
data/ext/lib/survival_def.h
CHANGED
data/ext/lib/survival_func.h
CHANGED
data/ext/sstat/Makefile
ADDED
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
|
|
2
|
+
SHELL = /bin/sh
|
|
3
|
+
|
|
4
|
+
# V=0 quiet, V=1 verbose. other values don't work.
|
|
5
|
+
V = 0
|
|
6
|
+
Q1 = $(V:1=)
|
|
7
|
+
Q = $(Q1:0=@)
|
|
8
|
+
ECHO1 = $(V:1=@:)
|
|
9
|
+
ECHO = $(ECHO1:0=@echo)
|
|
10
|
+
|
|
11
|
+
#### Start of system configuration section. ####
|
|
12
|
+
|
|
13
|
+
srcdir = .
|
|
14
|
+
topdir = /home/chizhang/.rvm/rubies/ruby-2.1.1/include/ruby-2.1.0
|
|
15
|
+
hdrdir = $(topdir)
|
|
16
|
+
arch_hdrdir = /home/chizhang/.rvm/rubies/ruby-2.1.1/include/ruby-2.1.0/x86_64-linux
|
|
17
|
+
PATH_SEPARATOR = :
|
|
18
|
+
VPATH = $(srcdir):$(arch_hdrdir)/ruby:$(hdrdir)/ruby
|
|
19
|
+
prefix = $(DESTDIR)/home/chizhang/.rvm/rubies/ruby-2.1.1
|
|
20
|
+
rubysitearchprefix = $(rubylibprefix)/$(sitearch)
|
|
21
|
+
rubyarchprefix = $(rubylibprefix)/$(arch)
|
|
22
|
+
rubylibprefix = $(libdir)/$(RUBY_BASE_NAME)
|
|
23
|
+
exec_prefix = $(prefix)
|
|
24
|
+
vendorarchhdrdir = $(vendorhdrdir)/$(sitearch)
|
|
25
|
+
sitearchhdrdir = $(sitehdrdir)/$(sitearch)
|
|
26
|
+
rubyarchhdrdir = $(rubyhdrdir)/$(arch)
|
|
27
|
+
vendorhdrdir = $(rubyhdrdir)/vendor_ruby
|
|
28
|
+
sitehdrdir = $(rubyhdrdir)/site_ruby
|
|
29
|
+
rubyhdrdir = $(includedir)/$(RUBY_VERSION_NAME)
|
|
30
|
+
vendorarchdir = $(vendorlibdir)/$(sitearch)
|
|
31
|
+
vendorlibdir = $(vendordir)/$(ruby_version)
|
|
32
|
+
vendordir = $(rubylibprefix)/vendor_ruby
|
|
33
|
+
sitearchdir = $(sitelibdir)/$(sitearch)
|
|
34
|
+
sitelibdir = $(sitedir)/$(ruby_version)
|
|
35
|
+
sitedir = $(rubylibprefix)/site_ruby
|
|
36
|
+
rubyarchdir = $(rubylibdir)/$(arch)
|
|
37
|
+
rubylibdir = $(rubylibprefix)/$(ruby_version)
|
|
38
|
+
sitearchincludedir = $(includedir)/$(sitearch)
|
|
39
|
+
archincludedir = $(includedir)/$(arch)
|
|
40
|
+
sitearchlibdir = $(libdir)/$(sitearch)
|
|
41
|
+
archlibdir = $(libdir)/$(arch)
|
|
42
|
+
ridir = $(datarootdir)/$(RI_BASE_NAME)
|
|
43
|
+
mandir = $(datarootdir)/man
|
|
44
|
+
localedir = $(datarootdir)/locale
|
|
45
|
+
libdir = $(exec_prefix)/lib
|
|
46
|
+
psdir = $(docdir)
|
|
47
|
+
pdfdir = $(docdir)
|
|
48
|
+
dvidir = $(docdir)
|
|
49
|
+
htmldir = $(docdir)
|
|
50
|
+
infodir = $(datarootdir)/info
|
|
51
|
+
docdir = $(datarootdir)/doc/$(PACKAGE)
|
|
52
|
+
oldincludedir = $(DESTDIR)/usr/include
|
|
53
|
+
includedir = $(prefix)/include
|
|
54
|
+
localstatedir = $(prefix)/var
|
|
55
|
+
sharedstatedir = $(prefix)/com
|
|
56
|
+
sysconfdir = $(prefix)/etc
|
|
57
|
+
datadir = $(datarootdir)
|
|
58
|
+
datarootdir = $(prefix)/share
|
|
59
|
+
libexecdir = $(exec_prefix)/libexec
|
|
60
|
+
sbindir = $(exec_prefix)/sbin
|
|
61
|
+
bindir = $(exec_prefix)/bin
|
|
62
|
+
archdir = $(rubyarchdir)
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
CC = gcc
|
|
66
|
+
CXX = g++
|
|
67
|
+
LIBRUBY = $(LIBRUBY_SO)
|
|
68
|
+
LIBRUBY_A = lib$(RUBY_SO_NAME)-static.a
|
|
69
|
+
LIBRUBYARG_SHARED = -Wl,-R -Wl,$(libdir) -L$(libdir) -l$(RUBY_SO_NAME)
|
|
70
|
+
LIBRUBYARG_STATIC = -Wl,-R -Wl,$(libdir) -L$(libdir) -l$(RUBY_SO_NAME)-static
|
|
71
|
+
empty =
|
|
72
|
+
OUTFLAG = -o $(empty)
|
|
73
|
+
COUTFLAG = -o $(empty)
|
|
74
|
+
|
|
75
|
+
RUBY_EXTCONF_H =
|
|
76
|
+
cflags = $(optflags) $(debugflags) $(warnflags)
|
|
77
|
+
optflags = -O3 -fno-fast-math
|
|
78
|
+
debugflags = -ggdb3
|
|
79
|
+
warnflags = -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wunused-variable -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wimplicit-function-declaration
|
|
80
|
+
CCDLFLAGS = -fPIC
|
|
81
|
+
CFLAGS = $(CCDLFLAGS) $(cflags) -fPIC -std=gnu99 -Wno-declaration-after-statement $(ARCH_FLAG)
|
|
82
|
+
INCFLAGS = -I. -I$(arch_hdrdir) -I$(hdrdir)/ruby/backward -I$(hdrdir) -I$(srcdir)
|
|
83
|
+
DEFS =
|
|
84
|
+
CPPFLAGS = $(DEFS) $(cppflags)
|
|
85
|
+
CXXFLAGS = $(CCDLFLAGS) $(cxxflags) $(ARCH_FLAG)
|
|
86
|
+
ldflags = -L. -fstack-protector -rdynamic -Wl,-export-dynamic
|
|
87
|
+
dldflags =
|
|
88
|
+
ARCH_FLAG =
|
|
89
|
+
DLDFLAGS = $(ldflags) $(dldflags) $(ARCH_FLAG)
|
|
90
|
+
LDSHARED = $(CC) -shared
|
|
91
|
+
LDSHAREDXX = $(CXX) -shared
|
|
92
|
+
AR = ar
|
|
93
|
+
EXEEXT =
|
|
94
|
+
|
|
95
|
+
RUBY_INSTALL_NAME = ruby
|
|
96
|
+
RUBY_SO_NAME = ruby
|
|
97
|
+
RUBYW_INSTALL_NAME =
|
|
98
|
+
RUBY_VERSION_NAME = $(RUBY_BASE_NAME)-$(ruby_version)
|
|
99
|
+
RUBYW_BASE_NAME = rubyw
|
|
100
|
+
RUBY_BASE_NAME = ruby
|
|
101
|
+
|
|
102
|
+
arch = x86_64-linux
|
|
103
|
+
sitearch = $(arch)
|
|
104
|
+
ruby_version = 2.1.0
|
|
105
|
+
ruby = $(bindir)/ruby
|
|
106
|
+
RUBY = $(ruby)
|
|
107
|
+
ruby_headers = $(hdrdir)/ruby.h $(hdrdir)/ruby/ruby.h $(hdrdir)/ruby/defines.h $(hdrdir)/ruby/missing.h $(hdrdir)/ruby/intern.h $(hdrdir)/ruby/st.h $(hdrdir)/ruby/subst.h $(arch_hdrdir)/ruby/config.h
|
|
108
|
+
|
|
109
|
+
RM = rm -f
|
|
110
|
+
RM_RF = $(RUBY) -run -e rm -- -rf
|
|
111
|
+
RMDIRS = rmdir --ignore-fail-on-non-empty -p
|
|
112
|
+
MAKEDIRS = /bin/mkdir -p
|
|
113
|
+
INSTALL = /usr/bin/install -c
|
|
114
|
+
INSTALL_PROG = $(INSTALL) -m 0755
|
|
115
|
+
INSTALL_DATA = $(INSTALL) -m 644
|
|
116
|
+
COPY = cp
|
|
117
|
+
TOUCH = exit >
|
|
118
|
+
|
|
119
|
+
#### End of system configuration section. ####
|
|
120
|
+
|
|
121
|
+
preload =
|
|
122
|
+
|
|
123
|
+
libpath = . $(libdir)
|
|
124
|
+
LIBPATH = -L. -L$(libdir) -Wl,-R$(libdir)
|
|
125
|
+
DEFFILE =
|
|
126
|
+
|
|
127
|
+
CLEANFILES = mkmf.log
|
|
128
|
+
DISTCLEANFILES =
|
|
129
|
+
DISTCLEANDIRS =
|
|
130
|
+
|
|
131
|
+
extout =
|
|
132
|
+
extout_prefix =
|
|
133
|
+
target_prefix =
|
|
134
|
+
LOCAL_LIBS =
|
|
135
|
+
LIBS = $(LIBRUBYARG_SHARED) -lpthread -ldl -lcrypt -lm -lc
|
|
136
|
+
ORIG_SRCS = sstat.c
|
|
137
|
+
SRCS = $(ORIG_SRCS)
|
|
138
|
+
OBJS = sstat.o
|
|
139
|
+
HDRS = $(srcdir)/sstat.h
|
|
140
|
+
TARGET = sstat
|
|
141
|
+
TARGET_NAME = sstat
|
|
142
|
+
TARGET_ENTRY = Init_$(TARGET_NAME)
|
|
143
|
+
DLLIB = $(TARGET).so
|
|
144
|
+
EXTSTATIC =
|
|
145
|
+
STATIC_LIB =
|
|
146
|
+
|
|
147
|
+
TIMESTAMP_DIR = .
|
|
148
|
+
BINDIR = $(bindir)
|
|
149
|
+
RUBYCOMMONDIR = $(sitedir)$(target_prefix)
|
|
150
|
+
RUBYLIBDIR = $(sitelibdir)$(target_prefix)
|
|
151
|
+
RUBYARCHDIR = $(sitearchdir)$(target_prefix)
|
|
152
|
+
HDRDIR = $(rubyhdrdir)/ruby$(target_prefix)
|
|
153
|
+
ARCHHDRDIR = $(rubyhdrdir)/$(arch)/ruby$(target_prefix)
|
|
154
|
+
|
|
155
|
+
TARGET_SO = $(DLLIB)
|
|
156
|
+
CLEANLIBS = $(TARGET).so
|
|
157
|
+
CLEANOBJS = *.o *.bak
|
|
158
|
+
|
|
159
|
+
all: $(DLLIB)
|
|
160
|
+
static: $(STATIC_LIB)
|
|
161
|
+
.PHONY: all install static install-so install-rb
|
|
162
|
+
.PHONY: clean clean-so clean-static clean-rb
|
|
163
|
+
|
|
164
|
+
clean-static::
|
|
165
|
+
clean-rb-default::
|
|
166
|
+
clean-rb::
|
|
167
|
+
clean-so::
|
|
168
|
+
clean: clean-so clean-static clean-rb-default clean-rb
|
|
169
|
+
-$(Q)$(RM) $(CLEANLIBS) $(CLEANOBJS) $(CLEANFILES) .*.time
|
|
170
|
+
|
|
171
|
+
distclean-rb-default::
|
|
172
|
+
distclean-rb::
|
|
173
|
+
distclean-so::
|
|
174
|
+
distclean-static::
|
|
175
|
+
distclean: clean distclean-so distclean-static distclean-rb-default distclean-rb
|
|
176
|
+
-$(Q)$(RM) Makefile $(RUBY_EXTCONF_H) conftest.* mkmf.log
|
|
177
|
+
-$(Q)$(RM) core ruby$(EXEEXT) *~ $(DISTCLEANFILES)
|
|
178
|
+
-$(Q)$(RMDIRS) $(DISTCLEANDIRS) 2> /dev/null || true
|
|
179
|
+
|
|
180
|
+
realclean: distclean
|
|
181
|
+
install: install-so install-rb
|
|
182
|
+
|
|
183
|
+
install-so: $(DLLIB) $(TIMESTAMP_DIR)/.RUBYARCHDIR.time
|
|
184
|
+
$(INSTALL_PROG) $(DLLIB) $(RUBYARCHDIR)
|
|
185
|
+
clean-static::
|
|
186
|
+
-$(Q)$(RM) $(STATIC_LIB)
|
|
187
|
+
install-rb: pre-install-rb install-rb-default
|
|
188
|
+
install-rb-default: pre-install-rb-default
|
|
189
|
+
pre-install-rb: Makefile
|
|
190
|
+
pre-install-rb-default: Makefile
|
|
191
|
+
pre-install-rb-default:
|
|
192
|
+
$(ECHO) installing default sstat libraries
|
|
193
|
+
$(TIMESTAMP_DIR)/.RUBYARCHDIR.time:
|
|
194
|
+
$(Q) $(MAKEDIRS) $(@D) $(RUBYARCHDIR)
|
|
195
|
+
$(Q) $(TOUCH) $@
|
|
196
|
+
|
|
197
|
+
site-install: site-install-so site-install-rb
|
|
198
|
+
site-install-so: install-so
|
|
199
|
+
site-install-rb: install-rb
|
|
200
|
+
|
|
201
|
+
.SUFFIXES: .c .m .cc .mm .cxx .cpp .C .o
|
|
202
|
+
|
|
203
|
+
.cc.o:
|
|
204
|
+
$(ECHO) compiling $(<)
|
|
205
|
+
$(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $<
|
|
206
|
+
|
|
207
|
+
.mm.o:
|
|
208
|
+
$(ECHO) compiling $(<)
|
|
209
|
+
$(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $<
|
|
210
|
+
|
|
211
|
+
.cxx.o:
|
|
212
|
+
$(ECHO) compiling $(<)
|
|
213
|
+
$(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $<
|
|
214
|
+
|
|
215
|
+
.cpp.o:
|
|
216
|
+
$(ECHO) compiling $(<)
|
|
217
|
+
$(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $<
|
|
218
|
+
|
|
219
|
+
.C.o:
|
|
220
|
+
$(ECHO) compiling $(<)
|
|
221
|
+
$(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $<
|
|
222
|
+
|
|
223
|
+
.c.o:
|
|
224
|
+
$(ECHO) compiling $(<)
|
|
225
|
+
$(Q) $(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) $(COUTFLAG)$@ -c $<
|
|
226
|
+
|
|
227
|
+
.m.o:
|
|
228
|
+
$(ECHO) compiling $(<)
|
|
229
|
+
$(Q) $(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) $(COUTFLAG)$@ -c $<
|
|
230
|
+
|
|
231
|
+
$(DLLIB): $(OBJS) Makefile
|
|
232
|
+
$(ECHO) linking shared-object $(DLLIB)
|
|
233
|
+
-$(Q)$(RM) $(@)
|
|
234
|
+
$(Q) $(LDSHARED) -o $@ $(OBJS) $(LIBPATH) $(DLDFLAGS) $(LOCAL_LIBS) $(LIBS)
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
$(OBJS): $(HDRS) $(ruby_headers)
|
data/ext/sstat/lib/km
ADDED
|
Binary file
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
#ifndef _SURVIVAL_STAT_DEF_H_
|
|
2
2
|
#define _SURVIVAL_STAT_DEF_H_
|
|
3
|
-
|
|
3
|
+
#include <stdio.h>
|
|
4
|
+
#include <stdlib.h>
|
|
5
|
+
#include <stddef.h>
|
|
4
6
|
#include "type_def.h"
|
|
5
7
|
|
|
6
8
|
/* Debug macro from http://c.learncodethehardway.org/book/ex20.html */
|
|
@@ -35,7 +37,7 @@
|
|
|
35
37
|
|
|
36
38
|
enum ERRORS {
|
|
37
39
|
OUTOF_MEMORY_ERROR = 1,
|
|
38
|
-
NOT_EMPTY_ERROR = 2
|
|
40
|
+
NOT_EMPTY_ERROR = 2,
|
|
39
41
|
};
|
|
40
42
|
|
|
41
43
|
/**
|
|
@@ -49,28 +51,26 @@ typedef struct CENS_UC_NUM
|
|
|
49
51
|
int size;
|
|
50
52
|
} CENS_UC_NUM;
|
|
51
53
|
|
|
52
|
-
void free_CENS_UC_NUM(struct CENS_UC_NUM
|
|
54
|
+
void free_CENS_UC_NUM(struct CENS_UC_NUM** instance)
|
|
53
55
|
{
|
|
54
|
-
if (instance != NULL)
|
|
56
|
+
if ( (*instance) != NULL)
|
|
55
57
|
{
|
|
56
|
-
if(instance->uncensored != NULL)
|
|
57
|
-
free(instance->uncensored);
|
|
58
|
+
if((*instance)->uncensored != NULL)
|
|
59
|
+
free((*instance)->uncensored);
|
|
58
60
|
|
|
59
|
-
if(instance->censored != NULL)
|
|
60
|
-
free(instance->censored);
|
|
61
|
+
if((*instance)->censored != NULL)
|
|
62
|
+
free((*instance)->censored);
|
|
61
63
|
|
|
62
|
-
if(instance->time != NULL)
|
|
63
|
-
free(instance->time);
|
|
64
|
+
if((*instance)->time != NULL)
|
|
65
|
+
free((*instance)->time);
|
|
64
66
|
|
|
65
|
-
free(instance);
|
|
67
|
+
free((*instance));
|
|
66
68
|
}
|
|
67
69
|
}
|
|
68
70
|
|
|
69
|
-
|
|
70
71
|
void print_CENS_UC_NUM(struct CENS_UC_NUM *cens_uncens_instance)
|
|
71
72
|
{
|
|
72
73
|
int i;
|
|
73
|
-
puts("Start to print out Group N: ");
|
|
74
74
|
for( i = 0; i < cens_uncens_instance->size; i++ )
|
|
75
75
|
{
|
|
76
76
|
printf("Time : %f -- Uncensored : %i -- Censored : %i \n",
|
|
@@ -103,7 +103,7 @@ error_1:
|
|
|
103
103
|
if((*cens_uncens_instance) == NULL)
|
|
104
104
|
return OUTOF_MEMORY_ERROR;
|
|
105
105
|
else
|
|
106
|
-
free_CENS_UC_NUM(
|
|
106
|
+
free_CENS_UC_NUM(cens_uncens_instance);
|
|
107
107
|
free((*cens_uncens_instance));
|
|
108
108
|
}
|
|
109
109
|
|
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
#define _SURVIVAL_STAT_KAPLAN_MEIER_H_
|
|
3
3
|
|
|
4
4
|
#include "survival_def.h"
|
|
5
|
+
#include "global_utility.h"
|
|
5
6
|
#include <math.h>
|
|
6
|
-
|
|
7
|
+
#include <stdio.h>
|
|
7
8
|
/**
|
|
8
9
|
* @brief calculate the number of samples censored or uncenosored (die) at each time ragne
|
|
9
10
|
* @param time Event time array
|
|
@@ -15,6 +16,7 @@ int censored_uncensred_each_time_range(double* time, int* censored, int size, s
|
|
|
15
16
|
int i, count_at, uncensored_num_at, censored_num_at;
|
|
16
17
|
double tmp, time_at;
|
|
17
18
|
|
|
19
|
+
|
|
18
20
|
//sort time and censored based on time together, time can censored array
|
|
19
21
|
struct point* time_censored_array = alloc_points(size);
|
|
20
22
|
|
|
@@ -52,8 +54,10 @@ int censored_uncensred_each_time_range(double* time, int* censored, int size, s
|
|
|
52
54
|
}
|
|
53
55
|
}
|
|
54
56
|
}
|
|
55
|
-
|
|
57
|
+
/*
|
|
56
58
|
double* unique_uncensored_time = (double *) malloc(count * sizeof(double));
|
|
59
|
+
check_mem(unique_uncensored_time);*/
|
|
60
|
+
alloc_CENS_UC_NUM(cens_ucens_number, count);
|
|
57
61
|
|
|
58
62
|
count = 0;
|
|
59
63
|
|
|
@@ -63,7 +67,7 @@ int censored_uncensred_each_time_range(double* time, int* censored, int size, s
|
|
|
63
67
|
{
|
|
64
68
|
if (count == 0)
|
|
65
69
|
{
|
|
66
|
-
|
|
70
|
+
(*cens_ucens_number)->time[count] = time_censored_array[i].x;
|
|
67
71
|
tmp = time_censored_array[i].x;
|
|
68
72
|
count++;
|
|
69
73
|
}
|
|
@@ -72,7 +76,7 @@ int censored_uncensred_each_time_range(double* time, int* censored, int size, s
|
|
|
72
76
|
{
|
|
73
77
|
if (time_censored_array[i].x != tmp)
|
|
74
78
|
{
|
|
75
|
-
|
|
79
|
+
(*cens_ucens_number)->time[count] = time_censored_array[i].x;
|
|
76
80
|
tmp = time_censored_array[i].x;
|
|
77
81
|
count++;
|
|
78
82
|
}
|
|
@@ -80,11 +84,8 @@ int censored_uncensred_each_time_range(double* time, int* censored, int size, s
|
|
|
80
84
|
}
|
|
81
85
|
}
|
|
82
86
|
|
|
83
|
-
int* uncensored_num = (int *) malloc(count * sizeof(int));
|
|
84
|
-
int* censored_num = (int *) malloc(count * sizeof(int));
|
|
85
|
-
|
|
86
87
|
//record current time point
|
|
87
|
-
time_at =
|
|
88
|
+
time_at = (*cens_ucens_number)->time[0];
|
|
88
89
|
count_at = 0;
|
|
89
90
|
uncensored_num_at = 0;
|
|
90
91
|
censored_num_at = 0;
|
|
@@ -104,13 +105,18 @@ int censored_uncensred_each_time_range(double* time, int* censored, int size, s
|
|
|
104
105
|
if (i == size - 1)
|
|
105
106
|
{
|
|
106
107
|
count_at++;
|
|
107
|
-
|
|
108
|
-
|
|
108
|
+
(*cens_ucens_number)->uncensored[count_at] = uncensored_num_at;
|
|
109
|
+
(*cens_ucens_number)->censored[count_at] = censored_num_at;
|
|
109
110
|
}
|
|
110
111
|
|
|
111
112
|
} else {
|
|
112
|
-
|
|
113
|
-
|
|
113
|
+
|
|
114
|
+
if(count_at < (*cens_ucens_number)-> size)
|
|
115
|
+
{
|
|
116
|
+
(*cens_ucens_number)->uncensored[count_at] = uncensored_num_at;
|
|
117
|
+
(*cens_ucens_number)->censored[count_at] = censored_num_at;
|
|
118
|
+
}
|
|
119
|
+
|
|
114
120
|
count_at++;
|
|
115
121
|
|
|
116
122
|
//reset uncensored_num_at and censored_num_at
|
|
@@ -118,7 +124,8 @@ int censored_uncensred_each_time_range(double* time, int* censored, int size, s
|
|
|
118
124
|
censored_num_at = 0;
|
|
119
125
|
|
|
120
126
|
//go to next time range
|
|
121
|
-
|
|
127
|
+
if(count_at < (*cens_ucens_number)-> size)
|
|
128
|
+
time_at = (*cens_ucens_number)->time[count_at];
|
|
122
129
|
|
|
123
130
|
if (time_censored_array[i].y > 0)
|
|
124
131
|
censored_num_at++;
|
|
@@ -126,29 +133,20 @@ int censored_uncensred_each_time_range(double* time, int* censored, int size, s
|
|
|
126
133
|
uncensored_num_at++;
|
|
127
134
|
|
|
128
135
|
/* If the last sample is censored, follow block stores counting for last time unique uncensored period */
|
|
129
|
-
if (i == size - 1)
|
|
136
|
+
if ( (i == size - 1) && (count_at < (*cens_ucens_number)-> size))
|
|
130
137
|
{
|
|
131
|
-
|
|
132
|
-
|
|
138
|
+
(*cens_ucens_number)->uncensored[count_at] = uncensored_num_at;
|
|
139
|
+
(*cens_ucens_number)->censored[count_at] = censored_num_at;
|
|
133
140
|
}
|
|
134
141
|
}
|
|
135
142
|
}
|
|
136
143
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
for(i = 0; i < count; i++)
|
|
140
|
-
{
|
|
141
|
-
(*cens_ucens_number)->uncensored[i] = uncensored_num[i];
|
|
142
|
-
(*cens_ucens_number)->censored[i] = censored_num[i];
|
|
143
|
-
(*cens_ucens_number)->time[i] = unique_uncensored_time[i];
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
free(time_censored_array);
|
|
147
|
-
free(uncensored_num);
|
|
148
|
-
free(censored_num);
|
|
149
|
-
free(unique_uncensored_time);
|
|
144
|
+
if(time_censored_array != NULL)
|
|
145
|
+
free(time_censored_array);
|
|
150
146
|
|
|
151
147
|
return 0;
|
|
148
|
+
error:
|
|
149
|
+
return OUTOF_MEMORY_ERROR;
|
|
152
150
|
}
|
|
153
151
|
|
|
154
152
|
/**
|
|
@@ -194,7 +192,7 @@ int kaplan_meier(double* time, int* censored, int size, curve* KM_curve)
|
|
|
194
192
|
/**
|
|
195
193
|
* @brief extend the KM curve based on the last 3 points
|
|
196
194
|
*/
|
|
197
|
-
int KM_3p_extrapolation(struct CENS_UC_NUM
|
|
195
|
+
int KM_3p_extrapolation(struct CENS_UC_NUM** cens_uc_num, struct CENS_UC_NUM** updated_cens_uc_num, int sample_size)
|
|
198
196
|
{
|
|
199
197
|
double mean_last_uncensored = 0;
|
|
200
198
|
double mean_last_censored = 0;
|
|
@@ -204,12 +202,14 @@ int KM_3p_extrapolation(struct CENS_UC_NUM* cens_uc_num, struct CENS_UC_NUM** up
|
|
|
204
202
|
int extrapolation_size = 0;
|
|
205
203
|
int updated_cens_uc_num_size = 0;
|
|
206
204
|
int i;
|
|
205
|
+
int last_1_index = (*cens_uc_num)->size - 2;
|
|
206
|
+
int last_4_index = (*cens_uc_num)->size - 5;
|
|
207
207
|
|
|
208
208
|
/* calculate the total number (censored and uncensored) already used */
|
|
209
|
-
for(i = 0; i < cens_uc_num->size; i ++)
|
|
209
|
+
for(i = 0; i < (*cens_uc_num)->size; i ++)
|
|
210
210
|
{
|
|
211
|
-
used_sample_num += cens_uc_num->censored[i];
|
|
212
|
-
used_sample_num += cens_uc_num->uncensored[i];
|
|
211
|
+
used_sample_num += (*cens_uc_num)->censored[i];
|
|
212
|
+
used_sample_num += (*cens_uc_num)->uncensored[i];
|
|
213
213
|
}
|
|
214
214
|
|
|
215
215
|
/* TODO should error check here */
|
|
@@ -225,30 +225,29 @@ int KM_3p_extrapolation(struct CENS_UC_NUM* cens_uc_num, struct CENS_UC_NUM** up
|
|
|
225
225
|
* x_last y_last (not used)
|
|
226
226
|
* why? when we calculate the last 3 time intervals, we need 4 points
|
|
227
227
|
*/
|
|
228
|
-
mean_last_uncensored += cens_uc_num->uncensored[cens_uc_num->size - 2 - i];
|
|
229
|
-
mean_last_censored += cens_uc_num->censored[cens_uc_num->size - 2 - i];
|
|
228
|
+
mean_last_uncensored += (*cens_uc_num)->uncensored[(*cens_uc_num)->size - 2 - i];
|
|
229
|
+
mean_last_censored += (*cens_uc_num)->censored[(*cens_uc_num)->size - 2 - i];
|
|
230
230
|
}
|
|
231
231
|
|
|
232
|
-
time_interval_mean = cens_uc_num->time[
|
|
233
|
-
|
|
232
|
+
time_interval_mean = (*cens_uc_num)->time[last_1_index] - (*cens_uc_num)->time[last_4_index];
|
|
234
233
|
mean_last_uncensored = mean_last_uncensored / 3;
|
|
235
234
|
mean_last_censored = mean_last_censored / 3;
|
|
236
235
|
time_interval_mean = time_interval_mean / 3;
|
|
237
236
|
|
|
238
237
|
/* Calculate how many points we should extrapolate */
|
|
239
238
|
extrapolation_size = ceil((double)num_left / (mean_last_uncensored + mean_last_censored));
|
|
240
|
-
updated_cens_uc_num_size = cens_uc_num->size + extrapolation_size;
|
|
239
|
+
updated_cens_uc_num_size = (*cens_uc_num)->size + extrapolation_size;
|
|
241
240
|
|
|
242
241
|
check(alloc_CENS_UC_NUM(updated_cens_uc_num, updated_cens_uc_num_size) == 0, "Failed in allocating CENS_UC_NUM structure");
|
|
243
242
|
|
|
244
|
-
for(i = 0; i < cens_uc_num->size; i++)
|
|
243
|
+
for(i = 0; i < (*cens_uc_num)->size; i++)
|
|
245
244
|
{
|
|
246
|
-
(*updated_cens_uc_num)->censored[i] = cens_uc_num->censored[i];
|
|
247
|
-
(*updated_cens_uc_num)->uncensored[i] = cens_uc_num->uncensored[i];
|
|
248
|
-
(*updated_cens_uc_num)->time[i] = cens_uc_num->time[i];
|
|
245
|
+
(*updated_cens_uc_num)->censored[i] = (*cens_uc_num)->censored[i];
|
|
246
|
+
(*updated_cens_uc_num)->uncensored[i] = (*cens_uc_num)->uncensored[i];
|
|
247
|
+
(*updated_cens_uc_num)->time[i] = (*cens_uc_num)->time[i];
|
|
249
248
|
}
|
|
250
249
|
|
|
251
|
-
for(i = cens_uc_num->size; i < (cens_uc_num->size + extrapolation_size); i++)
|
|
250
|
+
for(i = (*cens_uc_num)->size; i < ((*cens_uc_num)->size + extrapolation_size); i++)
|
|
252
251
|
{
|
|
253
252
|
(*updated_cens_uc_num)->time[i] = (*updated_cens_uc_num)->time[i-1] + time_interval_mean;
|
|
254
253
|
|
|
@@ -271,7 +270,7 @@ int KM_3p_extrapolation(struct CENS_UC_NUM* cens_uc_num, struct CENS_UC_NUM** up
|
|
|
271
270
|
return 0;
|
|
272
271
|
|
|
273
272
|
error:
|
|
274
|
-
free_CENS_UC_NUM(
|
|
273
|
+
free_CENS_UC_NUM(updated_cens_uc_num);
|
|
275
274
|
return 1;
|
|
276
275
|
}
|
|
277
276
|
|
|
@@ -279,11 +278,11 @@ int kaplan_meier_3p_extrapolation(double* time, int* censored, int size, struct
|
|
|
279
278
|
{
|
|
280
279
|
int proc_state = 0;
|
|
281
280
|
int i;
|
|
282
|
-
struct CENS_UC_NUM* cens_ucens_number
|
|
281
|
+
struct CENS_UC_NUM* cens_ucens_number;
|
|
283
282
|
censored_uncensred_each_time_range(time, censored, size, &cens_ucens_number);
|
|
284
|
-
struct CENS_UC_NUM* updated_cens_ucens_number
|
|
283
|
+
struct CENS_UC_NUM* updated_cens_ucens_number;
|
|
285
284
|
|
|
286
|
-
proc_state = KM_3p_extrapolation(cens_ucens_number, &updated_cens_ucens_number, size);
|
|
285
|
+
proc_state = KM_3p_extrapolation(&cens_ucens_number, &updated_cens_ucens_number, size);
|
|
287
286
|
int N = size;
|
|
288
287
|
|
|
289
288
|
struct point* KM = alloc_points(size);
|
|
@@ -305,10 +304,10 @@ int kaplan_meier_3p_extrapolation(double* time, int* censored, int size, struct
|
|
|
305
304
|
|
|
306
305
|
KM_curve->point_array = KM;
|
|
307
306
|
KM_curve->size = updated_cens_ucens_number->size;
|
|
308
|
-
//print_curve(KM_curve);
|
|
309
307
|
|
|
310
|
-
free_CENS_UC_NUM(cens_ucens_number);
|
|
311
|
-
|
|
308
|
+
free_CENS_UC_NUM(&cens_ucens_number);
|
|
309
|
+
|
|
310
|
+
free_CENS_UC_NUM(&updated_cens_ucens_number);
|
|
312
311
|
return 0;
|
|
313
312
|
}
|
|
314
313
|
#endif
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
#ifndef _SURVIVAL_STAT_UTILITY_H_
|
|
2
2
|
#define _SURVIVAL_STAT_UTILITy_H_
|
|
3
3
|
|
|
4
|
-
#
|
|
5
|
-
#include <
|
|
4
|
+
#ifdef DEBUG
|
|
5
|
+
#include <stdio.h>
|
|
6
|
+
#include <stdlib.h>
|
|
7
|
+
#endif
|
|
8
|
+
|
|
6
9
|
#include "global_utility.h"
|
|
7
10
|
#include "survival_def.h"
|
|
8
11
|
#include "type_def.h"
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#include "survival_kaplan_meier.h"
|
|
2
|
+
|
|
3
|
+
int main(int argc, char const *argv[])
|
|
4
|
+
{
|
|
5
|
+
struct curve KM_curve;
|
|
6
|
+
|
|
7
|
+
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
|
+
int _censored[14] = {1, 0 , 0, 0, 1, 1, 1, 0 , 1, 1,0,1,0,1};
|
|
9
|
+
|
|
10
|
+
kaplan_meier_3p_extrapolation(_time, _censored, 14, &KM_curve);
|
|
11
|
+
free(KM_curve.point_array);
|
|
12
|
+
|
|
13
|
+
return 0;
|
|
14
|
+
}
|
data/ext/sstat/lib/type_def.h
CHANGED
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
#define GAUSS_XLOWER (-37)
|
|
17
17
|
#define GAUSS_SCALE (16.0)
|
|
18
18
|
#define GAUSS_EPSILON 1e-12
|
|
19
|
+
#include <stdio.h>
|
|
19
20
|
|
|
20
21
|
typedef struct point{
|
|
21
22
|
double x;
|
|
@@ -32,7 +33,8 @@ typedef struct array{
|
|
|
32
33
|
int size;
|
|
33
34
|
} array;
|
|
34
35
|
|
|
35
|
-
|
|
36
|
+
|
|
37
|
+
point* alloc_points(int size)
|
|
36
38
|
{
|
|
37
39
|
return (struct point*) malloc(size * sizeof(struct point));
|
|
38
40
|
}
|
data/ext/sstat/sstat.c
CHANGED
data/ext/sstat/sstat.o
ADDED
|
Binary file
|
data/ext/sstat/sstat.so
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.
|
|
4
|
+
version: 0.0.6
|
|
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-07-
|
|
13
|
+
date: 2016-07-13 00:00:00.000000000 Z
|
|
14
14
|
dependencies: []
|
|
15
15
|
description:
|
|
16
16
|
email: haipeng3@ualberta.ca
|
|
@@ -31,6 +31,7 @@ files:
|
|
|
31
31
|
- ext/lib/survival_func.h
|
|
32
32
|
- ext/lib/survival_utility.h
|
|
33
33
|
- ext/lib/type_def.h
|
|
34
|
+
- ext/sstat/Makefile
|
|
34
35
|
- ext/sstat/extconf.rb
|
|
35
36
|
- ext/sstat/lib/distribution.h
|
|
36
37
|
- ext/sstat/lib/global_utility.h
|
|
@@ -38,14 +39,18 @@ files:
|
|
|
38
39
|
- ext/sstat/lib/histogram/histogram_error.h
|
|
39
40
|
- ext/sstat/lib/histogram/histogram_stat.h
|
|
40
41
|
- ext/sstat/lib/histogram/histogram_type.h
|
|
42
|
+
- ext/sstat/lib/km
|
|
41
43
|
- ext/sstat/lib/survival.h
|
|
42
44
|
- ext/sstat/lib/survival_def.h
|
|
43
45
|
- ext/sstat/lib/survival_func.h
|
|
44
46
|
- ext/sstat/lib/survival_kaplan_meier.h
|
|
45
47
|
- ext/sstat/lib/survival_utility.h
|
|
48
|
+
- ext/sstat/lib/test_kaplan_meier.c
|
|
46
49
|
- ext/sstat/lib/type_def.h
|
|
47
50
|
- ext/sstat/sstat.c
|
|
48
51
|
- ext/sstat/sstat.h
|
|
52
|
+
- ext/sstat/sstat.o
|
|
53
|
+
- ext/sstat/sstat.so
|
|
49
54
|
- lib/simple_statistics.rb
|
|
50
55
|
- lib/simple_statistics/version.rb
|
|
51
56
|
- lib/sstat.so
|