Project

sstat

0.0
No commit activity in last 3 years
No release in over 3 years
This gem includes native ruby statistics functions. For speed purpose, functions here are all created from C.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies
 Project Readme

SimpleStatistics

Simple Statistics aims to provide high performance survival statistic functions for Ruby. For better performance, all of the functions here are natively written by C, then wrapped into Ruby.

This gem is still under active development. If you have found any bugs or specifc requirements, please email haipeng3@ualberta.ca

Installment

In Gemfile, add following:

gem 'sstat'

Install simple statistics gem using:

gem install 

Requirements

ruby (> 2.1)

Testing

rake test

Usage

# Include simple statistics
require 'sstat'

Histogram

# Create statistics instance
sstat_hist = SStat::Hist.new
bin = [2, 3, 5, 2, 1]
range = [0, 1, 2, 3, 4, 5]

# Calculate the histogram mean
hist_mean = sstat_hist.hist_mean(bin, range)

# Calculate the histogram median
hist_median = sstat_hist.hist_median(bin, range)

Kaplan Meier Estimator

sstat_survival = SStat::Surv.new
# Event time for samples
time = [1, 2, 3, 4, 5, 6, 7]

# 1 -> censored. The event time is the patient's last visit time.
# 0 -> uncensored. The event time is the patient's actual dead time.
censored = [1, 1, 0, 0, 0, 1, 0]

# Calculate Kaplan-Meier without extraploation
sstat_survival.kaplan_meier(time, censored)

# Calculate Kaplan-Meier with extrapoloation based on last 3 points
sstat_instance.kaplan_meier_3p_extraploation(time, censored)

Log Rank Test

# time_test_1 -> Event time array for first test
# cens_test_1 -> Censored array for first test
# time_test_2 -> Event time array for second test
# cens_test_2 -> Censored array for second test
sstat_instance.log_rank_test(time_test_1, cens_test_1, time_test_2, cens_test_2)

License

The gem is available as open source under the terms of the MIT License.