Skip to content

Commit c6b2432

Browse files
committed
Merge pull request #11 from onli/chisquare_example
Add an example for chi-square homogeneity test
2 parents a277b3d + ca4d57d commit c6b2432

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

examples/chisquare_test.rb

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/usr/bin/ruby
2+
$:.unshift(File.dirname(__FILE__)+'/../lib')
3+
require 'statsample'
4+
5+
Statsample::Analysis.store(Statsample::Test::ChiSquare) do
6+
# Collect the two vectors with the categorical data (raw number of occurences) into one matrix. Here
7+
#--------------------------------------------
8+
#| category | observation 1 | observation 2 |
9+
#|------------------------------------------|
10+
#| A | 100 | 20 |
11+
#| B | 50 | 70 |
12+
#| C | 30 | 100 |
13+
#|------------------------------------------|
14+
#
15+
m=Matrix[[100, 50, 30],[20, 70, 100]]
16+
x_2=Statsample::Test.chi_square(m)
17+
# after the test is done, look at the p-value.
18+
puts x_2.probability
19+
end
20+
21+
if __FILE__==$0
22+
Statsample::Analysis.run_batch
23+
end

0 commit comments

Comments
 (0)