Skip to content

One way ANOVA and F Test

Esteban Zapata Rojas edited this page Oct 19, 2017 · 1 revision

One way ANOVA

This is a basic One way ANOVA implementation.

Class methods

ANOVA F Score

This method calculates the one-way ANOVA F-test statistic. We assume that all specified arguments are arrays. It returns an array with three elements: [F-statistic or F-score, degrees of freedom numerator, degrees of freedom denominator].

Formulas extracted from: https://courses.lumenlearning.com/boundless-statistics/chapter/one-way-anova/ http://sphweb.bumc.bu.edu/otlt/MPH-Modules/BS/BS704_HypothesisTesting-ANOVA/BS704_HypothesisTesting-Anova_print.html

[131] pry(main)> StatisticalTest::FTest.anova_f_score([1, 2, 3], [4, 5, 6])
=> [1.0, 1, 4] # [F-Statistic, DF numerator, DF denominator]

[132] pry(main)> StatisticalTest::FTest.anova_f_score([1, 2, 3], [4, 5, 6], [7, 8, 9])
=> [27.0, 2, 6]

One way ANOVA

This method expects the alpha value and the groups to calculate the one-way ANOVA test. It returns a hash with multiple information and the test result (if reject the null hypotesis or not). Keep in mind that the values for the alternative key (true/false) does not imply that the alternative hypothesis is TRUE or FALSE. It's a minor notation advantage to decide if reject the null hypothesis or not.

In the following example, the test suggest to reject the null hypothesis and consider the alternative one.

[135] pry(main)> StatisticalTest::FTest.one_way_anova(alpha = 0.05, [1, 2, 3], [4, 5, 6], [7, 8, 9])
=> {:probability=>0.999, :p_value=>0.0010000000000000009, :alpha=>0.05, :null=>false, :alternative=>true, :confidence_level=>0.95}

To perform an F-Test, specify only two arrays of observations. In the following example, the test suggest to accept the null hypothesis and reject the alternative one.

[136] pry(main)> StatisticalTest::FTest.one_way_anova(alpha = 0.05, [1, 2, 3], [4, 5, 6])
=> {:probability=>0.6260990336999411, :p_value=>0.37390096630005887, :alpha=>0.05, :null=>true, :alternative=>false, :confidence_level=>0.95}