Skip to content

Commit

Permalink
use stats package
Browse files Browse the repository at this point in the history
  • Loading branch information
mjhuff committed Nov 25, 2024
1 parent 84ca777 commit 8945788
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 23 deletions.
23 changes: 2 additions & 21 deletions .github/actions/odd-resource-analysis/action/lib/analysis.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Analysis is based on one-tailed, Pearson's correlation coefficient.

const { sampleCorrelation } = require('simple-statistics')
const { MINIMUM_VALID_SAMPLE_SIZE } = require('./constants')

/**
Expand All @@ -9,27 +10,7 @@ const { MINIMUM_VALID_SAMPLE_SIZE } = require('./constants')
* @return {number} The Pearson Correlation.
*/
function calculatePearsonCorrelation(x, y) {
const n = x.length
let sum_x = 0
let sum_y = 0
let sum_xy = 0
let sum_x2 = 0
let sum_y2 = 0

for (let i = 0; i < n; i++) {
sum_x += x[i]
sum_y += y[i]
sum_xy += x[i] * y[i]
sum_x2 += x[i] * x[i]
sum_y2 += y[i] * y[i]
}

const numerator = n * sum_xy - sum_x * sum_y
const denominator = Math.sqrt(
(n * sum_x2 - sum_x * sum_x) * (n * sum_y2 - sum_y * sum_y)
)

return denominator === 0 ? 0 : numerator / denominator
return sampleCorrelation(x, y)
}

/**
Expand Down
11 changes: 10 additions & 1 deletion .github/actions/odd-resource-analysis/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion .github/actions/odd-resource-analysis/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"dependencies": {
"@actions/core": "1.11.1",
"@actions/github": "6.0.0",
"node-fetch": "2.6.9"
"node-fetch": "2.6.9",
"simple-statistics": "7.8.7"
},
"devDependencies": {
"@vercel/ncc": "0.38.3"
Expand Down

0 comments on commit 8945788

Please sign in to comment.