bio-statsample-timeseries 0.1.1
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/.document +5 -0
- data/.travis.yml +13 -0
- data/Gemfile +21 -0
- data/LICENSE.txt +20 -0
- data/README.md +47 -0
- data/README.rdoc +48 -0
- data/Rakefile +48 -0
- data/VERSION +1 -0
- data/bin/bio-statsample-timeseries +74 -0
- data/features/acf.feature +31 -0
- data/features/pacf.feature +42 -0
- data/features/step_definitions/bio-statsample-timeseries_steps.rb +0 -0
- data/features/step_definitions/step_definitions.rb +37 -0
- data/features/step_definitions/step_definitions_acf.rb +8 -0
- data/features/support/env.rb +15 -0
- data/lib/bio-statsample-timeseries.rb +16 -0
- data/lib/bio-statsample-timeseries/arima.rb +124 -0
- data/lib/bio-statsample-timeseries/statsample-timeseries.rb +2 -0
- data/lib/bio-statsample-timeseries/timeseries.rb +181 -0
- data/lib/bio-statsample-timeseries/timeseries/pacf.rb +100 -0
- data/test/fixtures/stock_data.csv +500 -0
- data/test/helper.rb +81 -0
- data/test/test_arima_simulators.rb +176 -0
- data/test/test_pacf.rb +52 -0
- data/test/test_tseries.rb +103 -0
- data/test/test_wald.rb +71 -0
- metadata +256 -0
data/.document
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
language: ruby
|
2
|
+
rvm:
|
3
|
+
- 1.9.2
|
4
|
+
- 1.9.3
|
5
|
+
- 2.0.0
|
6
|
+
- jruby-19mode # JRuby in 1.9 mode
|
7
|
+
- rbx-19mode
|
8
|
+
# - 1.8.7
|
9
|
+
# - jruby-18mode # JRuby in 1.8 mode
|
10
|
+
# - rbx-18mode
|
11
|
+
|
12
|
+
# uncomment this line if your project needs to run something other than `rake`:
|
13
|
+
# script: bundle exec rspec spec
|
data/Gemfile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
|
3
|
+
gem 'statsample', '=1.2.0'
|
4
|
+
|
5
|
+
# Add dependencies required to use your gem here.
|
6
|
+
# Example:
|
7
|
+
gem "activesupport", "= 3.2.10"
|
8
|
+
|
9
|
+
# Add dependencies to develop your gem here.
|
10
|
+
# Include everything needed to run rake, tests, features, etc.
|
11
|
+
group :development do
|
12
|
+
gem "shoulda", ">= 0"
|
13
|
+
gem "rdoc", "~> 3.12"
|
14
|
+
gem "minitest", "~> 4.7.5"
|
15
|
+
gem "cucumber", ">= 0"
|
16
|
+
gem "bundler", "~> 1.3.5"
|
17
|
+
gem "jeweler", "~> 1.8.4"
|
18
|
+
gem "bio", ">= 1.4.2"
|
19
|
+
gem "rdoc", "~> 3.12"
|
20
|
+
gem 'mocha', '~> 0.14.0'
|
21
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2013 Ankur Goel
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
# bio-statsample-timeseries
|
2
|
+
|
3
|
+
[](http://travis-ci.org/ankurgel/bioruby-statsample-timeseries)
|
4
|
+
|
5
|
+
Full description goes here
|
6
|
+
|
7
|
+
Note: this software is under active development!
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
```sh
|
12
|
+
gem install bio-statsample-timeseries
|
13
|
+
```
|
14
|
+
|
15
|
+
## Usage
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
require 'bio-statsample-timeseries'
|
19
|
+
```
|
20
|
+
|
21
|
+
The API doc is online. For more code examples see the test files in
|
22
|
+
the source tree.
|
23
|
+
|
24
|
+
## Project home page
|
25
|
+
|
26
|
+
Information on the source tree, documentation, examples, issues and
|
27
|
+
how to contribute, see
|
28
|
+
|
29
|
+
http://github.com/ankurgel/bioruby-statsample-timeseries
|
30
|
+
|
31
|
+
The BioRuby community is on IRC server: irc.freenode.org, channel: #bioruby.
|
32
|
+
|
33
|
+
## Cite
|
34
|
+
|
35
|
+
If you use this software, please cite one of
|
36
|
+
|
37
|
+
* [BioRuby: bioinformatics software for the Ruby programming language](http://dx.doi.org/10.1093/bioinformatics/btq475)
|
38
|
+
* [Biogem: an effective tool-based approach for scaling up open source software development in bioinformatics](http://dx.doi.org/10.1093/bioinformatics/bts080)
|
39
|
+
|
40
|
+
## Biogems.info
|
41
|
+
|
42
|
+
This Biogem is published at [#bio-statsample-timeseries](http://biogems.info/index.html)
|
43
|
+
|
44
|
+
## Copyright
|
45
|
+
|
46
|
+
Copyright (c) 2013 Ankur Goel. See LICENSE.txt for further details.
|
47
|
+
|
data/README.rdoc
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
= bio-statsample-timeseries
|
2
|
+
|
3
|
+
{<img
|
4
|
+
src="https://secure.travis-ci.org/ankurgel/bioruby-statsample-timeseries.png"
|
5
|
+
/>}[http://travis-ci.org/#!/ankurgel/bioruby-statsample-timeseries]
|
6
|
+
|
7
|
+
Full description goes here
|
8
|
+
|
9
|
+
Note: this software is under active development!
|
10
|
+
|
11
|
+
== Installation
|
12
|
+
|
13
|
+
gem install bio-statsample-timeseries
|
14
|
+
|
15
|
+
== Usage
|
16
|
+
|
17
|
+
== Developers
|
18
|
+
|
19
|
+
To use the library
|
20
|
+
|
21
|
+
require 'bio-statsample-timeseries'
|
22
|
+
|
23
|
+
The API doc is online. For more code examples see also the test files in
|
24
|
+
the source tree.
|
25
|
+
|
26
|
+
== Project home page
|
27
|
+
|
28
|
+
Information on the source tree, documentation, issues and how to contribute, see
|
29
|
+
|
30
|
+
http://github.com/ankurgel/bioruby-statsample-timeseries
|
31
|
+
|
32
|
+
The BioRuby community is on IRC server: irc.freenode.org, channel: #bioruby.
|
33
|
+
|
34
|
+
== Cite
|
35
|
+
|
36
|
+
If you use this software, please cite one of
|
37
|
+
|
38
|
+
* [BioRuby: bioinformatics software for the Ruby programming language](http://dx.doi.org/10.1093/bioinformatics/btq475)
|
39
|
+
* [Biogem: an effective tool-based approach for scaling up open source software development in bioinformatics](http://dx.doi.org/10.1093/bioinformatics/bts080)
|
40
|
+
|
41
|
+
== Biogems.info
|
42
|
+
|
43
|
+
This Biogem is published at http://biogems.info/index.html#bio-statsample-timeseries
|
44
|
+
|
45
|
+
== Copyright
|
46
|
+
|
47
|
+
Copyright (c) 2013 Ankur Goel. See LICENSE.txt for further details.
|
48
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
+
gem.name = "bio-statsample-timeseries"
|
18
|
+
gem.homepage = "http://github.com/ankurgel/bioruby-statsample-timeseries"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = %Q{TimeSeries modules for Statsample}
|
21
|
+
gem.description = %Q{Statsample-timeseries is an extension to Statsample. It incorporates helpful timeseries functions and modules like ARMA, ARIMA, acf, pacf, lags etc.}
|
22
|
+
gem.email = "ankurgel@gmail.com"
|
23
|
+
gem.authors = ["Ankur Goel", "Claudio Bustos"]
|
24
|
+
# dependencies defined in Gemfile
|
25
|
+
end
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
27
|
+
|
28
|
+
require 'rake/testtask'
|
29
|
+
Rake::TestTask.new(:test) do |test|
|
30
|
+
test.libs << 'lib' << 'test'
|
31
|
+
test.pattern = 'test/**/test_*.rb'
|
32
|
+
test.verbose = true
|
33
|
+
end
|
34
|
+
|
35
|
+
require 'cucumber/rake/task'
|
36
|
+
Cucumber::Rake::Task.new(:features)
|
37
|
+
|
38
|
+
task :default => :test
|
39
|
+
|
40
|
+
require 'rdoc/task'
|
41
|
+
Rake::RDocTask.new do |rdoc|
|
42
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
43
|
+
|
44
|
+
rdoc.rdoc_dir = 'rdoc'
|
45
|
+
rdoc.title = "bio-statsample-timeseries #{version}"
|
46
|
+
rdoc.rdoc_files.include('README*')
|
47
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
48
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.1
|
@@ -0,0 +1,74 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# BioRuby bio-statsample-timeseries Plugin BioStatsampleTimeseries
|
4
|
+
# Author:: Ankur Goel
|
5
|
+
# Copyright:: 2013
|
6
|
+
|
7
|
+
USAGE = "Describe bio-statsample-timeseries"
|
8
|
+
|
9
|
+
if ARGV.size == 0
|
10
|
+
print USAGE
|
11
|
+
end
|
12
|
+
|
13
|
+
require 'bio-statsample-timeseries'
|
14
|
+
require 'optparse'
|
15
|
+
|
16
|
+
# Uncomment when using the bio-logger
|
17
|
+
# require 'bio-logger'
|
18
|
+
# Bio::Log::CLI.logger('stderr')
|
19
|
+
# Bio::Log::CLI.trace('info')
|
20
|
+
|
21
|
+
options = {:example_switch=>false,:show_help=>false}
|
22
|
+
opts = OptionParser.new do |o|
|
23
|
+
o.banner = "Usage: #{File.basename($0)} [options] reponame\ne.g. #{File.basename($0)} the-perfect-gem"
|
24
|
+
|
25
|
+
o.on('--example_parameter [EXAMPLE_PARAMETER]', 'TODO: put a description for the PARAMETER') do |example_parameter|
|
26
|
+
# TODO: your logic here, below an example
|
27
|
+
options[:example_parameter] = 'this is a parameter'
|
28
|
+
end
|
29
|
+
|
30
|
+
o.separator ""
|
31
|
+
o.on("--switch-example", 'TODO: put a description for the SWITCH') do
|
32
|
+
# TODO: your logic here, below an example
|
33
|
+
self[:example_switch] = true
|
34
|
+
end
|
35
|
+
|
36
|
+
# Uncomment the following when using the bio-logger
|
37
|
+
# o.separator ""
|
38
|
+
# o.on("--logger filename",String,"Log to file (default stderr)") do | name |
|
39
|
+
# Bio::Log::CLI.logger(name)
|
40
|
+
# end
|
41
|
+
#
|
42
|
+
# o.on("--trace options",String,"Set log level (default INFO, see bio-logger)") do | s |
|
43
|
+
# Bio::Log::CLI.trace(s)
|
44
|
+
# end
|
45
|
+
#
|
46
|
+
# o.on("-q", "--quiet", "Run quietly") do |q|
|
47
|
+
# Bio::Log::CLI.trace('error')
|
48
|
+
# end
|
49
|
+
#
|
50
|
+
# o.on("-v", "--verbose", "Run verbosely") do |v|
|
51
|
+
# Bio::Log::CLI.trace('info')
|
52
|
+
# end
|
53
|
+
#
|
54
|
+
# o.on("--debug", "Show debug messages") do |v|
|
55
|
+
# Bio::Log::CLI.trace('debug')
|
56
|
+
# end
|
57
|
+
|
58
|
+
o.separator ""
|
59
|
+
o.on_tail('-h', '--help', 'display this help and exit') do
|
60
|
+
options[:show_help] = true
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
begin
|
65
|
+
opts.parse!(ARGV)
|
66
|
+
|
67
|
+
# Uncomment the following when using the bio-logger
|
68
|
+
# Bio::Log::CLI.configure('bio-statsample-timeseries')
|
69
|
+
|
70
|
+
# TODO: your code here
|
71
|
+
# use options for your logic
|
72
|
+
rescue OptionParser::InvalidOption => e
|
73
|
+
options[:invalid_argument] = e.message
|
74
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
Feature: ACF
|
2
|
+
|
3
|
+
As a statistician
|
4
|
+
So that I can evaluate autocorrelation of a series
|
5
|
+
I want to evaluate acf
|
6
|
+
|
7
|
+
Background: a timeseries
|
8
|
+
|
9
|
+
Given the following values in a timeseries:
|
10
|
+
| timeseries |
|
11
|
+
| 10 20 30 40 50 60 70 80 90 100 |
|
12
|
+
| 110 120 130 140 150 160 170 180 190 200 |
|
13
|
+
|
14
|
+
Scenario: cross-check acf for 10 lags
|
15
|
+
When I provide 10 lags for acf
|
16
|
+
And I calculate acf
|
17
|
+
Then I should get 11 values in resultant acf
|
18
|
+
And I should see "1.0, 0.85, 0.7015037593984963, 0.556015037593985, 0.4150375939849624, 0.2800751879699248, 0.15263157894736842, 0.034210526315789476, -0.07368421052631578, -0.16954887218045114, -0.2518796992481203" as complete series
|
19
|
+
|
20
|
+
Scenario: cross-check acf for 5 lags
|
21
|
+
When I provide 5 lags for acf
|
22
|
+
And I calculate acf
|
23
|
+
Then I should get 6 values in resultant acf
|
24
|
+
And I should see "1.0, 0.85, 0.7015037593984963, 0.556015037593985, 0.4150375939849624, 0.2800751879699248" as complete series
|
25
|
+
|
26
|
+
Scenario: first value should be 1.0
|
27
|
+
When I provide 2 lags for acf
|
28
|
+
And I calculate acf
|
29
|
+
Then I should get 3 values in resultant acf
|
30
|
+
And I should see 1.0 as first value
|
31
|
+
|
@@ -0,0 +1,42 @@
|
|
1
|
+
Feature: PACF
|
2
|
+
|
3
|
+
As a statistician
|
4
|
+
So that I can quickly evaluate partial autocorrelation of a series
|
5
|
+
I want to evaluate pacf
|
6
|
+
|
7
|
+
Background: a timeseries
|
8
|
+
|
9
|
+
Given the following values in a timeseries:
|
10
|
+
| timeseries |
|
11
|
+
| 10 20 30 40 50 60 70 80 90 100 |
|
12
|
+
| 110 120 130 140 150 160 170 180 190 200 |
|
13
|
+
|
14
|
+
Scenario: check pacf for 10 lags with unbiased
|
15
|
+
When I provide 10 lags for pacf
|
16
|
+
When I provide yw yule walker as method
|
17
|
+
Then I should get Array as resultant output
|
18
|
+
Then I should get 11 values in resultant pacf
|
19
|
+
|
20
|
+
Scenario: check pacf for 5 lags with mle
|
21
|
+
When I provide 5 lags for pacf
|
22
|
+
When I provide mle yule walker as method
|
23
|
+
Then I should get Array as resultant output
|
24
|
+
Then I should get 6 values in resultant pacf
|
25
|
+
|
26
|
+
Scenario: check first value of pacf
|
27
|
+
When I provide 5 lags for pacf
|
28
|
+
When I provide yw yule walker as method
|
29
|
+
Then I should get Array as resultant output
|
30
|
+
And I should see 1.0 as first value
|
31
|
+
|
32
|
+
Scenario: check all values in pacf for 5 lags with mle
|
33
|
+
When I provide 5 lags for pacf
|
34
|
+
When I provide mle yule walker as method
|
35
|
+
Then I should get Array as resultant output
|
36
|
+
And I should see "1.0, 0.85, -0.07566212829370711, -0.07635069706072706, -0.07698628638512295, -0.07747034005560738" as complete series
|
37
|
+
|
38
|
+
Scenario: check all values in pacf for 5 lags with unbiased
|
39
|
+
When I provide 5 lags for pacf
|
40
|
+
When I provide yw yule walker as method
|
41
|
+
Then I should get Array as resultant output
|
42
|
+
And I should see "1.0, 0.8947368421052632, -0.10582010582010604, -0.11350188273265083, -0.12357534824820737, -0.13686534216335522" as complete series
|
File without changes
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'statsample'
|
2
|
+
include Statsample::TimeSeries
|
3
|
+
|
4
|
+
Given /^the following values in a timeseries:$/ do |series|
|
5
|
+
arr = []
|
6
|
+
series.hashes.each do |sequence|
|
7
|
+
arr += sequence['timeseries'].split(' ').map(&:to_i).to_ts
|
8
|
+
end
|
9
|
+
@timeseries = arr.to_ts
|
10
|
+
end
|
11
|
+
|
12
|
+
When /^I provide (\d+) lags for p?acf$/ do |lags|
|
13
|
+
@lags = lags.to_i
|
14
|
+
end
|
15
|
+
|
16
|
+
When /^I provide (\w+) yule walker as method$/ do |method|
|
17
|
+
@method = method
|
18
|
+
end
|
19
|
+
|
20
|
+
Then /^I should get (\w+) as resultant output$/ do |klass|
|
21
|
+
@result = @timeseries.pacf(@lags, @method)
|
22
|
+
assert_equal @result.class.to_s, klass
|
23
|
+
end
|
24
|
+
|
25
|
+
Then /^I should get (\w+) values in resultant p?acf$/ do |values_count|
|
26
|
+
assert_equal @result.size, values_count.to_i
|
27
|
+
end
|
28
|
+
|
29
|
+
And /^I should see (\d+\.\d) as first value$/ do |first_value|
|
30
|
+
assert_equal @result.first, first_value.to_f
|
31
|
+
end
|
32
|
+
|
33
|
+
And /^I should see \"(.+)\" as complete series$/ do |series|
|
34
|
+
series = series.split(',').map(&:to_f)
|
35
|
+
assert_equal @result, series
|
36
|
+
end
|
37
|
+
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'bundler'
|
2
|
+
begin
|
3
|
+
Bundler.setup(:default, :development)
|
4
|
+
rescue Bundler::BundlerError => e
|
5
|
+
$stderr.puts e.message
|
6
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
7
|
+
exit e.status_code
|
8
|
+
end
|
9
|
+
|
10
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__) + '/../../lib')
|
11
|
+
require 'bio-statsample-timeseries'
|
12
|
+
|
13
|
+
require 'test/unit/assertions'
|
14
|
+
|
15
|
+
World(Test::Unit::Assertions)
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# Please require your code below, respecting the naming conventions in the
|
2
|
+
# bioruby directory tree.
|
3
|
+
#
|
4
|
+
# For example, say you have a plugin named bio-plugin, the only uncommented
|
5
|
+
# line in this file would be
|
6
|
+
#
|
7
|
+
# require 'bio/bio-plugin/plugin'
|
8
|
+
#
|
9
|
+
# In this file only require other files. Avoid other source code.
|
10
|
+
|
11
|
+
require 'bio-statsample-timeseries/statsample-timeseries.rb'
|
12
|
+
require 'statsample'
|
13
|
+
require_relative 'bio-statsample-timeseries/timeseries.rb'
|
14
|
+
require_relative 'bio-statsample-timeseries/arima.rb'
|
15
|
+
|
16
|
+
|