Tutorials › Introduction to Statistics › Quality Checks Before Analyzing Data

Ethics, Data Quality and Reproducible Work · Tutorial 97 of 996

Quality Checks Before Analyzing Data

Use a structured set of checks to spot data problems before analysis, and distinguish a warning that needs investigation from a confirmed error.

Beginner 9 min read

What You'll Learn

  • Compare imported row counts and identifiers with the records the data are expected to contain.
  • Check that each variable’s recorded values match its defined type and meaning.
  • Count missing cells by variable and describe how they affect completeness.
  • Use identifiers and record comparisons to flag possible duplicates.
  • Compare observed values with documented valid ranges and permitted categories.
  • Recognize why a failed check calls for investigation, not automatic deletion or correction.

Why Check Data Before Analyzing It?

A calculation can be performed correctly and still answer the wrong question if the data contain an unnoticed problem. A missing record can change who is represented; a value recorded in the wrong units can distort a summary; and a category spelled two ways can be treated as two groups. Quality checks help identify these risks before analysis begins.

A check is not a guarantee that every value is correct. It compares the data with what is expected: the study plan, data dictionary, source records, or another reliable reference. A value outside an expected range is a reason to investigate, not proof that the value is wrong. Likewise, a value that passes a check may still have been recorded incorrectly.

Definition: A pre-analysis quality check is a systematic comparison of a data set with its documented structure and expected content, made before statistical analysis. Checks commonly cover row counts, variable types, missing values, duplicate records, ranges, and category labels. A flag is an observation that needs review; it is not, by itself, a decision to change or remove data.

A Practical Checklist

Start with expectations that can be stated before inspecting the results: what one row represents, which variables should be present, how many records are expected, and which values are permitted. The data dictionary and study documentation provide useful references. Then check the imported data in a consistent order.

1
Check the structure and row count.
Confirm that the expected variables are present and that each row represents the intended observational unit. Compare the number of rows and, when available, record identifiers with a roster or expected count.
2
Check variable types and meanings.
Confirm that each column contains the kind of information its definition describes. Look for numbers stored as text, category codes treated as measurements, or dates interpreted in an unexpected format.
3
Check missing values.
Count missing cells overall and by variable. Confirm that missingness is represented as intended and is not hidden in a special code or text entry.
4
Check for duplicate records.
Look for repeated identifiers or repeated records. Decide what counts as a duplicate using the study’s definition; identical values do not always mean the same person or event has been recorded twice.
5
Check ranges and category labels.
Compare quantitative values with documented limits and categorical values with the permitted labels. Review unusual values and inconsistent spellings before deciding whether they reflect errors or meaningful distinctions.

The order is useful because some checks depend on others. For example, a category column cannot be reviewed sensibly until its intended meaning is understood. A count of rows also needs context: it can be compared with an expected number only if that expectation is known. These checks do not require a statistical model; they require clear definitions and reliable reference information.

Worked Example: Row Counts, Missing Values, and a Possible Duplicate

Worked Example: Row Counts, Missing Values, and a Possible Duplicate

Suppose a hypothetical class project expects one record for each of eight participants, with identifiers 101 through 108. Its imported table contains these rows:

IDAge (years)Usual transport
10120Bus
10219walk
103MissingMissing
10420Car
10522Missing
10619Bus
10619Bus
10720Missing

Row count and identifiers. The table has 8 rows, which matches the expected number of records. However, its identifiers are not the expected set 101 through 108: ID 106 appears twice and ID 108 is absent. The row count alone would not reveal this discrepancy. Matching identifiers to the expected list suggests that one row may be duplicated and that a record may be missing.

Missing values. There are three missing entries in usual transport: IDs 103, 105, and 107. Age has one missing entry, for ID 103. Thus the two measured variables have \(8 \times 2 = 16\) cells in total, of which 4 are missing. The missing-cell proportion is

$$ \frac{4}{16}=0.25=25\%. $$

This describes missing cells in the imported table, not missing participants in the intended group. Because ID 103 lacks both values, the four missing cells occur in three rows. The repeated ID 106 also means that the table’s eight rows do not represent eight distinct identifiers.

Duplicate flag. The two rows for ID 106 agree on every displayed value, so they are a strong candidate for a repeated record. The data source or study records should be checked before removing one. A repeated identifier could instead reflect a legitimate repeated measurement if the row definition allowed multiple records per participant, but this project expects one row per participant.

Worked Example: Checking Types and Ranges

Worked Example: Checking Types and Ranges

In a hypothetical survey of adults aged 18 through 25, a data dictionary defines age as a whole number of years and weekly exercise hours as a nonnegative number. A short extract contains ages 19, 21, 205, and “twenty”; exercise values 2.5, 0, and -3; and transport labels such as “Bus” and “Car.”

Check the types first. Age and exercise hours are quantitative variables, while transport is categorical. The text “twenty” is not currently stored as a numerical age, so it should be flagged for review. It might be a text-entry error, but its intended value should not be assumed without checking a source or applying a documented rule.

Check the ranges against the study definition. The permitted age range is 18 to 25 years. The values 19 and 21 fall within it, while 205 falls outside it. The value 205 may be a typing error, but a range check alone cannot establish that it should be 20, or even that the age was measured correctly. The exercise value -3 violates the stated nonnegative condition, while 0 and 2.5 meet it.

The range check is a comparison with the documented limits: \(18 \leq 19 \leq 25\) and \(18 \leq 21 \leq 25\), but \(205 > 25\). For exercise, \(-3 < 0\), so it fails the stated condition. These checks identify specific values to investigate. They do not justify silently replacing 205 with 20 or deleting the record.

A limit must have a defensible source. If the study had not restricted participants to ages 18 through 25, age 30 would not be invalid merely because it seemed unusual. Documented eligibility rules, units, and variable definitions determine what counts as a range violation.

Worked Example: Reviewing Category Labels

Worked Example: Reviewing Category Labels

Suppose a hypothetical survey’s data dictionary lists the permitted usual-transport categories as “Bus,” “Walk,” and “Car.” Eight nonmissing responses are recorded as “Bus,” “bus,” “Walk,” “Car,” “Bus,” “BUS,” “Walk,” and “Public transit.”

Compare observed labels with the dictionary. “bus” and “BUS” differ from “Bus” in capitalization. They may represent the same category if capitalization is the only difference and the project’s rules say labels are case-insensitive. “Public transit,” however, is not one of the listed labels. It might mean “Bus,” another transit mode, or something else; the recorded text alone does not establish which.

There are 8 nonmissing responses in this check. Four entries are written as “Bus,” “bus,” or “BUS,” two are “Walk,” one is “Car,” and one is “Public transit.” Those counts describe the recorded text as it stands; they do not establish the correct cleaned categories. A permitted, documented standardization could combine the capitalization variants if the meaning is confirmed, while “Public transit” needs clarification against the survey choices or source record.

This distinction matters: standardizing a spelling can preserve meaning, whereas merging categories can change it. A label check should surface inconsistencies and ambiguous values without assuming that every different-looking label is interchangeable.

What Each Check Can and Cannot Tell You

A quality check is most useful when its result is interpreted narrowly. Row counts can reveal a mismatch with a known roster, but a matching total does not prove that the correct records are present. Type checks can reveal values that do not fit a column’s definition, but some software may import data in a misleading type without changing the displayed values. Missing-value counts describe what is absent in the file, not why it is absent.

Similarly, a duplicate check identifies repeated values or identifiers according to the rule being used. It cannot establish the cause of the repetition. Range checks reveal values outside stated limits, but the limits themselves must be justified. Category checks reveal labels outside or inconsistent with a defined set; they do not decide whether two labels have the same meaning.

The practical output of this stage is a clear list of checks performed and items requiring attention. Keep the original data intact while investigating flags. Record the evidence used to resolve them and avoid making a correction simply because it produces a tidier table. Decisions about whether and how to change data should be based on the data’s meaning and the study’s documented rules.

Common Mistakes

  • Assuming the expected row count proves the data are complete. A duplicate and a missing record can cancel each other out. Compare identifiers or another suitable record key as well as the total count.
  • Treating a flagged value as a confirmed error. An unusual age or an unlisted label needs review. Do not replace or remove it solely because it failed a check.
  • Calling a value missing only when a cell is blank. A special code such as “99” or text such as “N/A” may also represent missingness. Interpret such values using the data documentation.
  • Combining labels because they look similar. Differences in capitalization may be cosmetic, but similar wording can still represent distinct responses. Check the intended categories before standardizing.
Key takeaway: Before analyzing a data set, check its structure, types, missing values, potential duplicates, ranges, and category labels against documented expectations. A check identifies what deserves attention; evidence and defined rules determine what, if anything, should change.

Check Your Understanding

Use the checklist to explain what you would investigate in each situation.

  1. A project expects 40 participant records and the file contains 40 rows, but one identifier appears twice. What does the matching row count establish, and what does it not establish?
  2. A variable defined as age in years contains the value “twenty.” Which check flags it, and what information would help resolve it?
  3. There are 5 missing cells among 50 measured-variable cells. What is the missing-cell proportion, and why is it not automatically the proportion of participants with any missing data?
  4. A permitted category is “No,” but the file contains “no.” What should be checked before treating the two labels as equivalent?
  5. A value lies outside a documented valid range. Explain why that is a flag for investigation rather than automatic proof that the value is erroneous.