Skip to content

Commit 0bc36d0

Browse files
committed
Use #average in correlations
1 parent 064ed60 commit 0bc36d0

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

src/DataFrame-Math/DataPearsonCorrelationMethod.class.st

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ DataPearsonCorrelationMethod class >> between: x and: y [
1111
| xDeviation yDeviation |
1212
x size = y size ifFalse: [ SizeMismatch signal: 'Correlation can not be calculated for two series of different size' ].
1313

14-
xDeviation := (x values replaceAll: nil with: 0) - (x sum / x size).
15-
yDeviation := (y values replaceAll: nil with: 0) - (y sum / y size).
14+
xDeviation := (x values replaceAll: nil with: 0) - x average.
15+
yDeviation := (y values replaceAll: nil with: 0) - y average.
1616

1717
^ (xDeviation * yDeviation) sum / ((xDeviation ** 2) sum * (yDeviation ** 2) sum) sqrt
1818
]

src/DataFrame-Tests/DataFrameStatsTest.class.st

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ DataFrameStatsTest >> testCorrelationMatrixWithNils [
7373
df := DataFrame withRows: #( #( 1 1 ) #( 2 nil ) #( nil 3 ) #( 4 4 ) ).
7474
df columnNames: #( dogs cats ).
7575

76-
expectedCorrelationMatrix := DataFrame withRows: #( #( 1 0.3207134902949093 ) #( 0.3207134902949093 1 ) ).
76+
expectedCorrelationMatrix := DataFrame withRows: #( #( 1 0.4174555390689118 ) #( 0.4174555390689118 1 ) ).
7777
expectedCorrelationMatrix columnNames: #( dogs cats ).
7878
expectedCorrelationMatrix rowNames: #( dogs cats ).
7979

0 commit comments

Comments
 (0)