Skip to content

Commit

Permalink
Rename variables
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed Dec 19, 2021
1 parent b91a518 commit bc7b87c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
12 changes: 6 additions & 6 deletions src/stats/critical_values/chi_squared.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,25 @@ import { getCriticalValue, getCriticalValuesMap } from './map.js'

/* eslint-disable max-lines */
// Return number to multiply variance with in order to get its confidence
// interval for a given significance rate and size.
// interval for a given significance level and size.
// Uses the chi-squared distribution's critical value.
export const getChiSquaredValue = function (size, significanceRate) {
export const getChiSquaredValue = function (size, significanceLevel) {
const degreesOfFreedom = size - 1
const criticalValue = getCriticalValue(
CHI_SQUARED_MAP,
degreesOfFreedom,
significanceRate,
significanceLevel,
)
return degreesOfFreedom / criticalValue
}

// Chi-squared critical values, with specific significance rate, single-sided
// Chi-squared critical values, with specific significance level, single-sided
// TODO: more digits of precision
// TODO: more values
/* eslint-disable unicorn/numeric-separators-style */
const CHI_SQUARED_RAW = [
{
significanceRate: 0.025,
significanceLevel: 0.025,
getMaxValue(degreesOfFreedom) {
return degreesOfFreedom + 1
},
Expand Down Expand Up @@ -296,7 +296,7 @@ const CHI_SQUARED_RAW = [
},
},
{
significanceRate: 0.975,
significanceLevel: 0.975,
getMaxValue(degreesOfFreedom) {
return degreesOfFreedom - 1
},
Expand Down
12 changes: 6 additions & 6 deletions src/stats/critical_values/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// computing the real value with their underlying function. This is much faster
// but less precise.
// The pre-computed table is an array of objects with properties:
// - `significanceRate` {float}: from 0 to 1
// - `significanceLevel` {float}: from 0 to 1
// - `values` {object}:
// - keys are the degrees of freedom
// - values are the critical values
Expand All @@ -17,7 +17,7 @@ export const getCriticalValuesMap = function (criticalValuesRaw) {
}

const getCriticalValueEntry = function ({
significanceRate,
significanceLevel,
getMaxValue,
criticalValues,
}) {
Expand All @@ -29,7 +29,7 @@ const getCriticalValueEntry = function ({
const [impreciseEntriesMaxIndex] =
impreciseEntries[impreciseEntries.length - 1]
return [
roundDecimals(significanceRate),
roundDecimals(significanceLevel),
{ preciseMap, impreciseEntries, impreciseEntriesMaxIndex, getMaxValue },
]
}
Expand All @@ -45,7 +45,7 @@ const isLastPreciseKey = function ([key], index, entries) {
}

// Retrieve a critical value given a specific degrees of freedom and
// significance rate.
// significance level.
// There are three levels of precision depending on how high the numbers of
// degrees of freedom are, since the pre-computed table cannot hard code all
// possible values:
Expand All @@ -55,14 +55,14 @@ const isLastPreciseKey = function ([key], index, entries) {
export const getCriticalValue = function (
criticalValuesMap,
degreesOfFreedom,
significanceRate,
significanceLevel,
) {
const {
preciseMap,
impreciseEntries,
impreciseEntriesMaxIndex,
getMaxValue,
} = criticalValuesMap.get(roundDecimals(significanceRate))
} = criticalValuesMap.get(roundDecimals(significanceLevel))

if (degreesOfFreedom > impreciseEntriesMaxIndex) {
return getMaxValue(degreesOfFreedom)
Expand Down
8 changes: 4 additions & 4 deletions src/stats/critical_values/student_t.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ import { getCriticalValue, getCriticalValuesMap } from './map.js'
// Retrieve critical value of the Student's t distribution, two-tailed, for a
// given degrees of freedom
export const getStudentTValue = function (degreesOfFreedom) {
const singleSignificanteRate = (1 - SIGNIFICANCE_RATE) / 2
const singleSignificanteLevel = (1 - SIGNIFICANCE_LEVEL) / 2
return getCriticalValue(
STUDENT_T_MAP,
degreesOfFreedom,
singleSignificanteRate,
singleSignificanteLevel,
)
}

const SIGNIFICANCE_RATE = 0.95
const SIGNIFICANCE_LEVEL = 0.95

const STUDENT_T_RAW = [
{
significanceRate: 0.025,
significanceLevel: 0.025,
getMaxValue() {
return MAX_T_VALUE
},
Expand Down

0 comments on commit bc7b87c

Please sign in to comment.