# = statsample.rb - # Statsample - Statistic package for Ruby # Copyright (C) 2008-2009 Claudio Bustos # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # $:.unshift(File.dirname(__FILE__)) $:.unshift(File.expand_path(File.dirname(__FILE__)+"/../ext")) require 'delegate' require 'matrix' class Numeric def square ; self * self ; end end def create_test(*args,&proc) description=args.shift fields=args [description, fields, Proc.new] end begin require 'rbgsl' HAS_GSL=true rescue LoadError HAS_GSL=false end begin require 'alglib' HAS_ALGIB=true rescue LoadError HAS_ALGIB=false end begin require 'statsample/optimization' rescue LoadError module Statsample OPTIMIZED=false end end # # Modules for statistical analysis # See first: # * Converter : several modules to import and export data # * Vector: The base class of all analysis # * Dataset: An union of vectors. # module Statsample VERSION = '0.3.2' SPLIT_TOKEN = "," autoload(:Database, 'statsample/converters') autoload(:Anova, 'statsample/anova') autoload(:CSV, 'statsample/converters') autoload(:Excel, 'statsample/converters') autoload(:GGobi, 'statsample/converters') autoload(:DominanceAnalysis, 'statsample/dominanceanalysis') autoload(:HtmlReport, 'statsample/htmlreport') autoload(:Mx, 'statsample/converters') autoload(:Resample, 'statsample/resample') autoload(:SRS, 'statsample/srs') autoload(:Codification, 'statsample/codification') autoload(:Reliability, 'statsample/reliability') autoload(:Bivariate, 'statsample/bivariate') autoload(:Multivariate, 'statsample/multivariate') autoload(:Regression, 'statsample/regression') autoload(:Test, 'statsample/test') def self.load(filename) fp=File.open(filename,"r") o=Marshal.load(fp) fp.close o end module Util # Reference: http://www.itl.nist.gov/div898/handbook/eda/section3/normprpl.htm def normal_order_statistic_medians(i,n) if i==1 u= 1.0 - normal_order_statistic_medians(n,n) elsif i==n u=0.5**(1 / n.to_f) else u= (i - 0.3175) / (n + 0.365) end u end end module Writable def save(filename) fp=File.open(filename,"w") Marshal.dump(self,fp) fp.close end end module HtmlSummary def add_line(n=nil) self << "
"+text.gsub("\n","
")+"
"+header.join(" | ")+" | " end out << "\n" row_with_line=false @rows.each{|row| if row==:hr row_with_line=true else out << "
---|---|
" out << row.join(" | ") +" | " out << "