NAME
Statistics::ANOVA - Perform oneway analyses of variance
SYNOPSIS
use Statistics::ANOVA;
my $varo = Statistics::ANOVA->new();
# Some data:
my @gp1 = (qw/8 7 11 14 9/);
my @gp2 = (qw/11 9 8 11 13/);
my @gp3 = (qw/7 13 12 8 10/);
# Load the data, names can be arbitrary
$varo->load_data({gp1 => \@gp1, gp2 => \@gp2, gp3 => \@gp3});
# If they are independent groups data, test equality of variances, difference between them, and means:
$varo->obrien_test()->dump(title => 'O\'Brien\'s test of equality of variances');
$varo->levene_test()->dump(title => 'Levene\'s test of equality of variances');
$varo->anova_indep()->dump(eta_squared => 1, omega_squared => 1, title => 'Independent groups ANOVA');
$varo->comparisons_indep();
# or if they are repeated measures data:
$varo->anova_dep()->dump(title => 'Dependent groups ANOVA');
$varo->comparisons_dep();
# or:
$varo->anova_friedman()->dump(title => 'Friedman test');
DESCRIPTION
Performs oneway between groups and repeated measures ANOVAs, with estimates of proportion of variance acounted for (eta-squared) and effect-size (omega-squared), plus pairwise comparisons by the relevant t-tests. Also performs equality of variances tests (O'Brien's, Levene's).
METHODS
Probabilities for all F-tests are computed using the fdtrc
function in the Math::Cephes module, rather than the Statistics::Distributions module, as the former appears to be more accurate for indicating higher-level significances than the latter.
new
Create a new Statistics::ANOVA object
load
$varo->load('data1', @data1)
$varo->load('data1', \@data1)
$varo->load({'data1' => \@data1, 'data2' => \@data2})
Alias: load_data
Provided for comparability with other Perl Statistics modules - but you can just send the data you want to test with the call to anova_indep
or anova_dep
if you like.
Accepts a single name value => pair
of a sample name, and a list (referenced or not) of data; or a hash reference of named array references of data. The data are loaded into the class object by name, within a hash called data
, as Statistics::Descriptive::Full objects. So you could get at the data again, for instance, by going $varo->{'data'}->{'data1'}->get_data(). You can keep updating the data this way, without unloading earlier loads.
Returns the Statistics::ANOVA object.
unload
$varo->unload();
Empties all cached data and calculations upon them, ensuring these will not be used for testing. This will not be automatically called with each new load or test. So it should be used whenever switching from one dataset to another. Alternatively, if you send a hash of data directly to anova_indep
or anova_dep
, that's what will be tested; i.e., you don't have to specifically load and unload the data.
anova_indep
$varo->anova_indep()
An implementation of a one-way between-groups analysis of variance. Feeds the class object $varo
as follows:
$varo->{'f_value'}
$varo->{'df_t'} : the treatment or numerator or between-groups degree(s) of freedom
$varo->{'df_e'} : the error or denominator or within-groups degree(s) of freedom
$varo->{'p_value'} : associated with the F-value with the above dfs
$varo->{'ss_t'} : treatment sums of squares
$varo->{'ss_e'} : error sums of squares
$varo->{'ms_t'} : treatment mean squares
$varo->{'ms_e'} : error mean squares
anova_dep
$varo->anova_dep()
Alias: anova_rm
Performs a one-way repeated measures analysis of variance (sphericity assumed). See anova_indep
for fed values.
anova_friedman
$varo->anova_friedman()
Alias: friedman_test
Performs Friedman's nonparametric analysis of variance - for two or more dependent (matched, related) groups. The statistical attributes now within the class object (see anova_indep
) pertain to this test, e.g., $varo->{'chi_value'} gives the chi-square statistic from the Friedman test; and $varo->{'p_value'} gives the associated p-value (area under the right-side, upper tail). There is now no defined 'f_value'. See some other module for performing nonparametric pairwise comparisons.
obrien_test
Performs O'Brien's Test for equality of variances. The statistical attributes now within the class object (see anova_indep
) pertain to this test, e.g., $varo->{'f_value'} gives the F-statistic for Obrien's Test; and $varo->{'p_value'} gives the p-value associated with the F-statistic for Obrien's Test.
levene_test
Performs Levene's (1960) Test for equality of variances. The statistical attributes now within the class object (see anova_indep
) pertain to this test, e.g., $varo->{'f_value'} gives the F-statistic for Levene's Test; and $varo->{'p_value'} gives the p-value associated with the F-statistic for Levene's Test.
comparisons_indep
$varo->comparisons_indep(tails => 1|2, flag => 1|0 )
Performs independent samples t-tests for each pair of the loaded data, using Statistics::TTest. Simply prints the results to STDOUT. The p_value is 2-tailed, by default, unless otherwise specified, as above. The output strings are appended with an asterisk if the logical value of the optional attribute flag
equals 1 and the p_value
is less than the Bonferroni-adjusted alpha level. This alpha level, relative to alpha = .05, for the number of paired comparisons, is printed at the end of the list.
comparisons_dep
$varo->comparisons_dep(tails => 1|2, flag => 1|0 )
Performs dependent samples t-tests for each pair of the loaded data, using Statistics::DependantTTest. The number of observations must be equal for each of the data-sets tested. Simply prints the results to STDOUT. The p_value is 2-tailed, by default, unless otherwise specified, as above. The output strings are appended with an asterisk if the logical value of the optional attribute flag
equals 1 and the p_value
is less than the Bonferroni-adjusted alpha level. This alpha level, relative to alpha = .05, for the number of paired comparisons, is printed at the end of the list.
eta_squared
Returns eta-squared if an ANOVA has been performed; otherwise croak
s. Also feeds $varo with the value, named 'eta_sq'. Values range from 0 to 1, 0 indicating no effect, 1 indicating difference between at least two DV means. Generally indicates the proportion of variance in the DV related to an effect.
omega_squared
Returns the effect size statistic omega-squared if an ANOVA has been performed; otherwise croak
s. Also feeds $varo with the value, named 'omega_sq'. Generally, size is small where omega_sq = .01, medium if omega_sq = .059, and strong if omega_sq = .138.
string
$str = $varo->string(mse => 1, eta_squared => 1, omega_squared => 1)
Returns a statement of result, in the form of F(df_t, df_e) = f_value, p = p_value
; or, for Friedman test chi^2(df_t) = chi_value, p = p_value
. Optionally also get MSe, eta_squared and omega_squared values appended to the string, where relevant.
dump
$varo->dump(mse => 1, eta_squared => 1, omega_squared => 1, title => 'ANOVA test')
Prints the string returned by string
. Optionally also get MSe, eta_squared and omega_squared values appended to the string. A newline - "\n" - is appended at the end of the print
. Above this string, a title can also be printed, by giving a value to the optional title
attribute.
EXPORT
None by default.
REFERENCES
None yet.
SEE ALSO
BUGS/LIMITATIONS
No computational bugs as yet identfied. Hopefully this will change, given usage over time. Optimisation of code welcomed.
No adjustment for violations of sphericity in repeated measures ANOVA.
Print only of t-test results.
REVISION HISTORY
AUTHOR/LICENSE
- Copyright (c) 2008 Roderick Garton
-
rgarton@utas_DOT_edu_DOT_au
This program is free software. It may may be modified, used, copied, and redistributed at your own risk, and under the terms of the Perl Artistic License (see http://www.perl.com/perl/misc/Artistic.html). Publicly redistributed modified versions must use a different name.
- Disclaimer
-
To the maximum extent permitted by applicable law, the author of this module disclaims all warranties, either express or implied, including but not limited to implied warranties of merchantability and fitness for a particular purpose, with regard to the software and the accompanying documentation.