Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Data quality

The question

Before you trust an analysis, you want to know whether the data behind it is sound: how much is missing, whether the gaps fall evenly or pile up in one group, whether any rows are implausible or far out of line with the rest, and whether some respondents answered carelessly.

It sounds like:

  • “How much is missing?”
  • “Is the missing data concentrated in one channel or group?”
  • “Are there customers whose figures look implausible?”
  • “Who answered carelessly?”

Count what is missing per field (a null count beside a count of present values), then group the same counts by a field that could explain the gaps, such as the channel a form arrived through. Keep or drop the null rows with a null filter once you know who they are. For rows out of line on several fields at once, score each row’s distance from the cohort’s centre (Mahalanobis distance) or its leverage in a model (how strongly that one row pulls the fitted line towards itself). For a rating battery, flag rows that give the same answer to every item (straight-lining) or answer too few items to score.

Pick your analysis

This question fits data shaped like:

  • fields: 1 or more numeric, categorical, date, bool or set fields

The operators that answer it, by kind; each name links to its catalog entry. Basic ones need the least setup; the worked example below uses AGG_COUNT, AGG_NULL_COUNT and GROUP_CATEGORY.

Aggregators

UseIn plain wordsLevel
AGG_DISTINCT_COUNTNumber of different values a field takes, over all rows or per group.basic
AGG_MAXLargest value of a numeric or date field, over all rows or per group.basic
AGG_MINSmallest value of a numeric or date field, over all rows or per group.basic
AGG_NULL_COUNTNumber of rows where a field has no value, over all rows or per group.basic

Attributes

UseIn plain wordsLevel
ATTR_MAHALANOBISAdds to every row how unusual its mix of several numeric fields is, allowing for how those fields usually vary together.advanced
ATTR_REG_INFLUENCEAdds to every row how much it moves a straight-line fit: how far the fitted values would shift if that one row were left out.advanced
ATTR_REG_LEVERAGEAdds to every row its leverage: how unusual its predictor values are, and so how hard it can pull a straight-line fit.advanced
ATTR_REG_RESIDUALAdds to every row its residual: the actual target value minus the value a straight-line model predicts for it.advanced

Filterers

UseIn plain wordsLevel
FILTER_EXCLUDEDrops the rows whose field holds one of the listed values and keeps the rest, such as removing test accounts.basic
FILTER_NULLKeeps either the rows where a field is missing or the rows where it is present, to find gaps or set them aside.basic
FILTER_RANGEKeeps only the rows whose number lies between a low and a high limit, both limits included.basic
FILTER_EXPRESSIONKeeps the rows for which a written yes-or-no condition is true, for rules the other filters cannot state, such as two fields together.intermediate

Statistical tests

UseIn plain wordsLevel
TEST_BOX_MChecks whether several groups share one spread pattern across a set of numeric fields, the assumption behind comparing average profiles.advanced
TEST_MARDIAChecks whether a set of numeric fields looks jointly normal, through their combined skew and tail weight.advanced

Matrix operators

UseIn plain wordsLevel
MAT_COLLINEARITYWhether candidate predictors overlap so much that a regression on them would give unstable coefficients, and which ones are tangled.intermediate

A worked example

To run the example below yourself, write the example cohorts once and work from their directory, since command-line cohort paths resolve against the working directory (Get the data). Start in a scratch directory outside your PULSE_DATA_DIR, so pulse-data does not nest inside the directory pulse mcp serves:

pulse examples data --out pulse-data
cd pulse-data
pulse examples show agg_missing_by_channel > req.json
pulse api process --request req.json --json

How much income is missing, and is it missing evenly across intake channels?

The request (example agg_missing_by_channel; pulse examples show agg_missing_by_channel prints it):

{
  "aggregations": [
    {
      "type": "AGG_COUNT",
      "field": "income",
      "label": "income_present"
    },
    {
      "type": "AGG_NULL_COUNT",
      "field": "income",
      "label": "income_null"
    },
    {
      "type": "AGG_NULL_COUNT",
      "field": "age",
      "label": "age_null"
    }
  ],
  "cohort": {
    "filename": "intake.pulse"
  },
  "groups": [
    {
      "type": "GROUP_CATEGORY",
      "field": "channel"
    }
  ],
  "return": {
    "preset": "standard",
    "precision": 4
  }
}

The result:

{
  "data": [
    {
      "age_null": 5,
      "channel": "paper",
      "income_null": 42,
      "income_present": 58
    },
    {
      "age_null": 5,
      "channel": "phone",
      "income_null": 13,
      "income_present": 87
    },
    {
      "age_null": 5,
      "channel": "web",
      "income_null": 4,
      "income_present": 96
    }
  ],
  "metadata": {
    "total_rows": 300,
    "filtered_rows": 300,
    "cohort_file": "intake.pulse"
  },
  "returned": {
    "preset": "standard",
    "digest": "rp1:3740c6cf7d1b2603620bc368cb97f40488ddae2bc40c4df12447e16826612255",
    "precision": 4
  }
}

Not evenly. Every channel has some blank incomes, but about two in five paper forms leave income blank, far more than the web forms, with phone in between, while age is blank on only a handful of forms in every channel. Whether income is blank therefore depends on how the form arrived, so an average income over the present rows leans towards web applicants; compare the channels, or weight them back, before you report one figure for everyone. A null here is a blank answer, not a zero income: the counts of present values leave the blanks out instead of treating them as nothing earned.

How to read the result

The figures these operators return read as their names say; for the ones that need more, see Reading your results.

Pitfalls

  • Missing is not zero. Aggregates leave null rows out and report how many they skipped (n_null); a filter or formula that turns a null into zero changes every figure after it.
  • Check what the missing rows have in common. If the blanks come mostly from one group, a figure over the present rows leans towards the groups that answered; compare the groups’ missing rates before you drop or ignore the blanks.
  • Dropping null rows is a choice, not a cleanup. A null filter shrinks every group by a different amount when the gaps are uneven; say how many rows each group lost.
  • A small, even gap is usually harmless. A field blank on a few rows in every group rarely moves a comparison; an uneven gap on the field you are reporting does.
  • An unusual row is a lead, not an error. A customer far from the centre may be a typo or a genuine high earner; check it before you delete or cap it.
  • Fix the data, then rerun. A quality check is worth doing before the analysis it protects; rerun the analysis after you exclude or correct rows and say what changed.

Next steps

Related questions:

Skills: intents, aggregation-design, attribute-composition, statistical-testing, test-variant-options, op-agg-count, op-agg-null-count, op-group-category

From the command line:

  • pulse recommend --intent data_quality --cohort PATH drafts requests for this question bound to your cohort’s fields.
  • pulse api predict checks a request against your cohort without running it.
  • pulse api process runs it.
  • pulse explain --response FILE --request REQ reads a result back in plain words: save the pulse api process --json output as FILE, and pass the request that produced it as REQ so the findings name its fields.