forked from clbustos/statsample
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from onli/chisquare_example
Add an example for chi-square homogeneity test
- Loading branch information
Showing
1 changed file
with
23 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#!/usr/bin/ruby | ||
$:.unshift(File.dirname(__FILE__)+'/../lib') | ||
require 'statsample' | ||
|
||
Statsample::Analysis.store(Statsample::Test::ChiSquare) do | ||
# Collect the two vectors with the categorical data (raw number of occurences) into one matrix. Here | ||
#-------------------------------------------- | ||
#| category | observation 1 | observation 2 | | ||
#|------------------------------------------| | ||
#| A | 100 | 20 | | ||
#| B | 50 | 70 | | ||
#| C | 30 | 100 | | ||
#|------------------------------------------| | ||
# | ||
m=Matrix[[100, 50, 30],[20, 70, 100]] | ||
x_2=Statsample::Test.chi_square(m) | ||
# after the test is done, look at the p-value. | ||
puts x_2.probability | ||
end | ||
|
||
if __FILE__==$0 | ||
Statsample::Analysis.run_batch | ||
end |