Numeric, Categorical, Ordinal, and Binary Variables
Install and import#
npm install fintech-algorithmsimport { numericCategoricalOrdinalAndBinaryVariables } from "fintech-algorithms/foundations/data-variables-samples-and-measurement/numeric-categorical-ordinal-and-binary-variables";Signature#
numericCategoricalOrdinalAndBinaryVariables(input)Classifies every column of a table as binary, numeric, ordinal or categorical by inspecting the values actually present in it.
Parameters#
| Name | Type | Notes |
|---|---|---|
input | D00Input | A plain object. Every F03 topic first reads rows, which must be a non-empty array of row objects, and derives the sorted union of every key seen across them before any per-topic branch runs. This topic then reads ordinalColumns, an optional array of column names that should be treated as ordered rather than merely categorical; it defaults to empty. |
Returns#
{ types: Record<string, string> }
types maps each column name to one of binary, numeric, ordinal or categorical. Null and undefined entries are ignored when judging a column. A column whose remaining values are all booleans is binary; all numbers with two or fewer distinct values is also binary, otherwise numeric; anything else is ordinal when the column is listed in ordinalColumns and categorical when it is not.
Errors#
- When input is not a plain object — throws TypeError
- When rows is missing, empty, or not an array — throws RangeError
Complexity: time O(r * c),
space O(r * c).
Worked example#
verified This is the worked example published in the article, replayed by the test suite on every run. The output cannot drift.
Input#
{
"rows": [
{
"entity": "A",
"timestamp": "2025-01-01T00:00:00Z",
"value": 10,
"rating": "low"
},
{
"entity": "A",
"timestamp": "2025-01-02T00:00:00Z",
"value": null,
"rating": "medium",
"censored": true
},
{
"entity": "B",
"timestamp": "2025-01-01T00:00:00Z",
"value": 12,
"rating": "high"
}
],
"ordinalColumns": ["rating"],
"populationSize": 100,
"frameSize": 80,
"keyColumns": ["entity", "timestamp"],
"truncationRule": "values below 5 excluded",
"measurements": [9.9, 10, 10.1, 10],
"referenceValue": 10,
"vintages": [
{
"availableAt": "2025-02-01T00:00:00Z",
"value": 100
},
{
"availableAt": "2025-03-01T00:00:00Z",
"value": 102
},
{
"availableAt": "2025-04-01T00:00:00Z",
"value": 101
}
],
"asOf": "2025-03-15T00:00:00Z",
"provenance": {
"source": "teaching.csv",
"owner": "Fintech Builder",
"license": "CC-BY-4.0",
"retrievedAt": "2026-08-10",
"transformations": ["parse", "validate"]
}
}Call#
numericCategoricalOrdinalAndBinaryVariables(input)Returns#
object with 1 field: types
{
"types": {
"censored": "binary",
"entity": "categorical",
"rating": "ordinal",
"timestamp": "categorical",
"value": "numeric"
}
}Diagrams#
How it works#
This page states the contract — how to call it correctly. The article explains the concept: why it works, and where it breaks.
References#
- Categorical Data
- 2. W3C Data on the Web Best Practices
- Evidence boundary