File Coverage

blib/lib/Statistics/ANOVA/EffectSize.pm
Criterion Covered Total %
statement 50 55 90.9
branch 6 14 42.8
condition n/a
subroutine 22 24 91.6
pod 7 7 100.0
total 85 100 85.0


line stmt bran cond sub pod time code
1             package Statistics::ANOVA::EffectSize;
2            
3 5     5   137748 use 5.006;
  5         28  
4 5     5   21 use strict;
  5         8  
  5         99  
5 5     5   22 use warnings;
  5         6  
  5         128  
6 5     5   22 use base qw(Statistics::Data);
  5         8  
  5         1197  
7 5     5   47904 use Carp qw(croak);
  5         10  
  5         233  
8 5     5   26 use List::AllUtils qw(any);
  5         10  
  5         4573  
9             $Statistics::ANOVA::EffectSize::VERSION = '0.02';
10            
11             =head1 NAME
12            
13             Statistics::ANOVA::EffectSize - Calculate effect-sizes from ANOVAs incl. eta-squared and omega-squared
14            
15             =head1 VERSION
16            
17             This is documentation for B of Statistics::ANOVA::EffectSize.
18            
19             =head1 SYNOPSIS
20            
21             use Statistics::ANOVA::EffectSize;
22             my $es = Statistics::ANOVA::EffectSize->new();
23             $es->load(HOA); # a hash of arefs, or other, as in Statistics::Data
24             my $etasq = $es->eta_squared(independent => BOOL, partial => 1); # or give data => HOA here
25             my $omgsq = $es->omega_squared(independent => BOOL);
26             # or calculate not from loaded data but directly:
27            
28             =head2 DESCRIPTION
29            
30             Calculates effect-sizes from ANOVAs.
31            
32             For I-squared, 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.
33            
34             For I-squared, size is conventionally described as small where omega_sq = .01, medium if omega_sq = .059, and strong if omega_sq = .138 (Cohen, 1969).
35            
36             =head1 SUBROUTINES/METHODS
37            
38             Rather than working from raw data, these methods are given the statistics, like sums-of-squares, needed to calculate the effect-sizes.
39            
40             =head2 eta_sq_partial_by_ss, r_squared
41            
42             $es->eta_sq_partial_by_ss(ss_b => NUM, ss_w => NUM);
43            
44             Returns partial I-squared given between- and within-group sums-of-squares (I):
45            
46             =for html

  η2P = SSb / ( SSb + SSw )

47            
48             This is also what is commonly designated as I-squared (Maxwell & Delaney, 1990, Eq. 90).
49            
50             =cut
51            
52             sub eta_sq_partial_by_ss {
53 4     4 1 119 my ( $self, %args ) = @_;
54             croak
55             'Undefined values needed to calculate partial eta-squared by sums-of-squares'
56 4 50   8   22 if any { !defined $args{$_} } (qw/ss_b ss_w/);
  8         20  
57 4         24 return $args{'ss_b'} / ( $args{'ss_b'} + $args{'ss_w'} );
58             }
59             *r_squared = \&eta_sq_partial_by_ss;
60            
61             =head2 r_squared_adj
62            
63             $es->r_squared_adj(ss_b => NUM, ss_w => NUM, df_b => NUM, df_w => NUM);
64            
65             Returns adjusted I-squared.
66            
67             =cut
68            
69             sub r_squared_adj {
70 0     0 1 0 my ( $self, %args ) = @_;
71 0         0 my $r_squared = $self->r_squared(%args); # will check for ss_b and ss_w
72             croak 'Could not obtain values to calculate adjusted r-squared'
73 0 0   0   0 if any { !defined $args{$_} } (qw/df_b df_w/);
  0         0  
74             return 1 -
75 0         0 ( ( $args{'df_b'} + $args{'df_w'} ) / $args{'df_w'} ) *
76             ( 1 - $r_squared );
77             }
78            
79             =head2 eta_sq_partial_by_f
80            
81             $es->eta_sq_partial_by_f(f_value => NUM , df_b => NUM, df_w => NUM);
82            
83             Returns partial I-squared given I-value and its between- and within-groups degrees-of-freedom (I):
84            
85             =for html

  η2P = ( dfb . F ) / ( dfb . F + dfw )

86            
87             =cut
88            
89             sub eta_sq_partial_by_f {
90 2     2 1 660 my ( $self, %args ) = @_;
91             croak 'Could not obtain values to calculate partial eta-squared by F-value'
92 2 50   6   11 if any { !defined $args{$_} } (qw/df_b df_w f_value/);
  6         12  
93             return ( $args{'df_b'} * $args{'f_value'} ) /
94 2         15 ( $args{'df_b'} * $args{'f_value'} + $args{'df_w'} );
95             }
96            
97             =head2 omega_sq_partial_by_ss
98            
99             $es->omega_sq_partial_by_ss(df_b => NUM, df_w => NUM, ss_b => NUM, ss_w => NUM, count => NUM);
100            
101             Returns partial I-squared given the between- and within-groups sums-of-squares and degrees-of-freedom.
102            
103             =for html

  ω2P = ( ssb — (dfb . SSw / dfw) ) / ( SSb + (Ndfb ) SSw / dfw )

104            
105             (as in, e.g., Olejnik & Algina, 2003, p. 435).
106            
107             =cut
108            
109             sub omega_sq_partial_by_ss {
110 2     2 1 304 my ( $self, %args ) = @_;
111             croak
112             'Undefined values for calculating partial omega-squared by sums-of-squares'
113 2 50   10   11 if any { !defined $args{$_} } (qw/ss_b ss_w df_b df_w count/);
  10         17  
114 2         7 return _omega_numerator_ss( \%args ) / _omega_denominator_ss( \%args );
115             }
116            
117             =head2 omega_sq_partial_by_ms
118            
119             $es->omega_sq_partial_by_ms(df_b => NUM, ms_b => NUM, ms_w => NUM, count => NUM);
120            
121             Returns partial I-squared given between- and within-group mean sums-of-squares (I). Also needs between-groups degrees-of-freedom and sample-size (here labelled "count") I:
122            
123             =for html

  ω2P = dfb ( MSbMSw ) / ( dfb . MSb + ( Ndfb ) MSw )

124            
125             (as in, e.g., Lakens, 2013, Eq. 15).
126            
127             =cut
128            
129             sub omega_sq_partial_by_ms {
130 1     1 1 228 my ( $self, %args ) = @_;
131             croak
132             'Could not obtain values to calculate partial omega-squared by mean sums-of-squares'
133 1 50   4   6 if any { !defined $_ } values %args;
  4         7  
134 1         3 return _omega_numerator_ms( \%args ) / _omega_denominator_ms( \%args );
135             }
136            
137             =head2 omega_sq_partial_by_f
138            
139             $es->omega_sq_partial_by_ms(f_value => NUM, df_b => NUM, df_w => NUM);
140            
141             Returns partial I-squared given I-value and its between- and within-group degrees-of-freedom (I):
142            
143             =for html

  ω2P(est.) = ( F - 1 ) / ( F + ( dfw + 1 ) / dfb )

144            
145             This is an estimate provided by L.
146            
147             =cut
148            
149             sub omega_sq_partial_by_f {
150 2     2 1 257 my ( $self, %args ) = @_;
151             croak
152             'Could not obtain values to calculate partial omega-squared by mean sums-of-squares'
153 2 50   6   12 if any { !defined $_ } values %args;
  6         11  
154             return ( $args{'f_value'} - 1 ) /
155 2         13 ( $args{'f_value'} + ( $args{'df_w'} + 1 ) / $args{'df_b'} );
156             }
157            
158             =head2 eta_to_omega
159            
160             $es->eta_to_omega(df_b => NUM, df_w => NUM, eta_sq => NUM);
161            
162             Returns I-squared based on I-squared and the between- and within-groups degrees-of-freedom.
163            
164             =for html

  ω2P = ( η2P(dfb + dfw) – dfb ) / ( η2P(dfb + dfw) – dfb ) + ( (dfw + 1)(1 – η2P) ) )

165            
166             =cut
167            
168             sub eta_to_omega {
169 2     2 1 490 my ( $self, %args ) = @_;
170             croak
171             'Could not obtain values to calculate partial omega-squared by mean sums-of-squares'
172 2 50   6   13 if any { !defined $_ } values %args;
  6         11  
173             my $num =
174 2         11 $args{'eta_sq'} * ( $args{'df_b'} + $args{'df_w'} ) - $args{'df_b'};
175             return $num /
176 2         11 ( $num + ( ( $args{'df_w'} + 1 ) * ( 1 - $args{'eta_sq'} ) ) );
177             }
178            
179             sub _omega_numerator_ss {
180 3     3   263 my $args = shift;
181             return $args->{'ss_b'} -
182 3         11 $args->{'df_b'} * $args->{'ss_w'} / $args->{'df_w'};
183             }
184            
185             sub _omega_numerator_ms {
186 2     2   10 my $args = shift;
187 2         6 return $args->{'df_b'} * ( $args->{'ms_b'} - $args->{'ms_w'} );
188             }
189            
190             sub _omega_denominator_ss {
191 3     3   237 my $args = shift;
192            
193             #return ( $args->{'ss_b'} + $args->{'ss_w'} ) + $args->{'ss_w'} / $args->{'df_w'};
194             return $args->{'ss_b'} +
195             ( $args->{'count'} - $args->{'df_b'} ) *
196             $args->{'ss_w'} /
197 3         12 $args->{'df_w'};
198             }
199            
200             sub _omega_denominator_ms {
201 2     2   8 my $args = shift;
202             return $args->{'df_b'} * $args->{'ms_b'} +
203 2         7 ( $args->{'count'} - $args->{'df_b'} ) * $args->{'ms_w'};
204             }
205            
206             =head1 DEPENDENCIES
207            
208             L : C method
209            
210             L : used as base.
211            
212             =head1 DIAGNOSTICS
213            
214             =over 4
215            
216             =item Could not obtain values to calculate ...
217            
218             Ced if the sufficient statistics have not been provided.
219            
220             =back
221            
222             =head1 REFERENCES
223            
224             Cohen, J. (1969). I. New York, US: Academic.
225            
226             Lakens, D. (2013). Calculating and reporting effect sizes to facilitate cumulative science: A practical primer for t-tests and ANOVAs. Frontiers in Psychology, 4, 863. doi:L<10.3389/fpsyg.2013.00863|http://dx.doi.org/10.3389/fpsyg.2013.00863>
227            
228             Lakens, D. (2015). Why you should use omega-squared instead of eta-squared, I [L].
229            
230             Maxwell, S. E., & Delaney, H. D. (1990). I. Belmont, CA, US: Wadsworth.
231            
232             Olejnik, S., & Algina, J. (2003). Generalized eta and omega squared statistics: Measures of effect size for some common research designs. I, I<8>, 434-447. doi: L<10.1037/1082-989X.8.4.434|http://dx.doi.org/10.1037/1082-989X.8.4.434>.
233            
234             =head1 AUTHOR
235            
236             Roderick Garton, C<< >>
237            
238             =head1 BUGS
239            
240             Please report any bugs or feature requests to C, or through the web interface at L. I will be notified, and then you'll
241             automatically be notified of progress on your bug as I make changes.
242            
243             =head1 SUPPORT
244            
245             You can find documentation for this module with the perldoc command.
246            
247             perldoc Statistics::ANOVA::EffectSize
248            
249            
250             You can also look for information at:
251            
252             =over 4
253            
254             =item * RT: CPAN's request tracker (report bugs here)
255            
256             L
257            
258             =item * AnnoCPAN: Annotated CPAN documentation
259            
260             L
261            
262             =item * CPAN Ratings
263            
264             L
265            
266             =item * Search CPAN
267            
268             L
269            
270             =back
271            
272             =head1 LICENSE AND COPYRIGHT
273            
274             Copyright 2015-2018 Roderick Garton.
275            
276             This program is free software; you can redistribute it and/or modify it
277             under the terms of either: the GNU General Public License as published
278             by the Free Software Foundation; or the Artistic License.
279            
280             See L for more information.
281            
282             =cut
283            
284             1; # End of Statistics::ANOVA::EffectSize