A variable's type (nominal, ordinal, discrete or continuous) decides which summaries describe it faithfully. Nominal codes are names: only counts, shares and the mode survive relabeling, and the mean of the NHANES 2017 to 2018 race codes is 3.509 or 2.550 for the same 5,247 adults, by the labels chosen. A 0/1 code is the exception: its mean is a proportion. For ordinal ratings, two groups' mean codes are ordered alike under every increasing coding exactly when one group's cumulative shares lie on or above the other's at every category. Where they cross, as for self-rated health at ages 60 to 69 against 70 and over, the coding decides. Counts and measurements support means, but top-coding and recording rules affect a mean more than a median.
Here is one line of a health survey, the record of a man examined in the National Health and Nutrition Examination Survey (NHANES) of 2017 to 2018:
| Variable | Recorded value |
|---|---|
| Sex | 1 (male) |
| Age | 33 |
| Race and Hispanic origin | 3 (non-Hispanic White) |
| People in the household | 3 |
| Systolic blood pressure, three readings | 134, 134, 134 mm Hg |
| Diastolic blood pressure, mean | 66 mm Hg |
| Height | 185.0 cm |
| Body mass index (BMI) | 30.8 kg/m² |
| Health in general | 3 ("Good") |
Every entry is stored as a number, and a computer will happily average any column. Only some of the averages mean anything. Which ones, and how can we tell before computing them? The answer depends on what each column records, not on its digits, and it can be read from the survey's documentation before any arithmetic is done.
Consider four columns. The average of the sex codes is a proportion. The average of the race codes is nonsense. The average of the health ratings is a number whose meaning depends on an assumption nobody stated. And the average of the blood pressures is the most natural summary there is. The difference lies not in the numbers but in what they record. The type of a variable, in the sense of this article, is the kind of measurement its numbers come from, and it decides which summaries describe the variable faithfully.
First we meet the survey. Then we take the course's four types in turn: nominal, ordinal, discrete and continuous. On the way we prove when a comparison of average ratings can be trusted, and meet ranks. Finally we compare the four types with Stevens's scales of measurement, and see why the classification is a guide rather than a law.
The data
The examples in this unit use the 5,247 adults aged 18 and over who were examined in NHANES 2017 to 2018 and had at least one systolic blood pressure reading. They are the same adults whose blood pressures the later units of the course sample from, for instance in Confidence Intervals and Coverage. Besides blood pressure, the survey's public files record:
- each person's sex, age, race and Hispanic origin and household size (file DEMO_J);
- height, weight and BMI from the examination (BMX_J);
- an answer to the question "Would you say your health in general is ...", with the choices excellent, very good, good, fair and poor (variable HUQ010 in HUQ_J).
All come from the National Center for Health Statistics (2020). As in the rest of the course, these adults are treated as a complete population to be described. NHANES is itself a weighted national sample, and nothing here is an estimate for the United States. The library's Data Collection and Sampling describes the survey's four-stage design and shows that its unweighted hypertension prevalence, 54.7%, differs from the weighted national figure of 48.2%; Survey Weights and the Horvitz–Thompson Estimator proves why weighting by inverse inclusion probabilities gives unbiased estimates.
A variable is a characteristic recorded for each member of a group, and its values over the group are the data. The question this article asks of each variable is what its numbers can be trusted to say. We start with the variable whose numbers say the least.
Nominal data
The race and Hispanic origin variable assigns each adult one of six codes:
| Code | Category | Adults | Share |
|---|---|---|---|
| 1 | Mexican American | 707 | 0.1347 |
| 2 | Other Hispanic | 479 | 0.0913 |
| 3 | Non-Hispanic White | 1,819 | 0.3467 |
| 4 | Non-Hispanic Black | 1,220 | 0.2325 |
| 6 | Non-Hispanic Asian | 744 | 0.1418 |
| 7 | Other race, including multiracial | 278 | 0.0530 |
The codes are names written as digits. The survey documentation notes that code 5 is not used at all (National Center for Health Statistics, 2020), which makes the point. The numbers could be replaced by letters, or by any other six distinct numbers, and no information would be lost. Data whose values are only labels for categories with no order are nominal.
What survives such a relabeling is all that nominal data can say: which category each person is in, how many people are in each, and therefore which category is most common. The mode, the most frequent category, is non-Hispanic White (code 3).
The mean of the codes, 3.509, describes nothing. Relabel the categories in order of size (3 becomes 1, 4 becomes 2, 6 becomes 3, 1 becomes 4, 2 becomes 5 and 7 becomes 6), and the mean is 2.550 for exactly the same people. A statistic that changes when nothing about the people changes is a statistic of the labels, not of the data.
Example (one code changed). Had the survey used code 70 instead of 7 for the last category, only the mean of the codes would change. Each of the 278 adults in that category would add 63 more to the sum of the codes, so the mean would rise by $63 \times 278/5247 = 3.338$, from 3.509 to 6.847, though nothing about the 278 people has changed. The counts, the shares and the mode belong to the categories, not to the digits that name them, and stay as they are.
Binary data and proportions
A nominal variable with two categories is binary (or dichotomous): sex as recorded here, or whether a person has hypertension. Binary data have one special property. If the two categories are coded 0 and 1, the mean of the codes is the proportion of ones.
Among the 5,247 adults, 2,700 are women. The mean of an indicator that is 1 for a woman and 0 for a man is $2700/5247 = 0.5146$, the proportion of women. The reason is one line of arithmetic: the sum of $n$ codes that are each 0 or 1 is the number of ones, so the mean is that number divided by $n$. That is why a proportion can be treated as a sample mean, the starting point of The Normal Approximation to the Binomial. The coding 0 and 1 is a choice, but a natural one, and the course uses it throughout.
So the sex codes can be averaged and the race codes cannot. The next variable sits between the two: its codes carry more than names, but less than quantities.
Ordinal data
The answers to "Would you say your health in general is ..." are recorded as 1 (excellent) to 5 (poor). Unlike the race codes, these numbers carry an order: a 2 is better health than a 3 in the respondent's own judgment.
What they do not carry is distance. Nothing says that the step from "excellent" to "very good" is the same size as the step from "fair" to "poor". Data whose categories are ordered but whose spacing is not defined are ordinal.
| Rating | Adults | Share | Cumulative share |
|---|---|---|---|
| 1 Excellent | 603 | 0.1150 | 0.1150 |
| 2 Very good | 1,376 | 0.2625 | 0.3775 |
| 3 Good | 1,959 | 0.3737 | 0.7512 |
| 4 Fair | 1,095 | 0.2089 | 0.9601 |
| 5 Poor | 209 | 0.0399 | 1.0000 |
These are the 5,242 adults who gave a rating; five refused or did not know. Those answers are stored as further numeric codes, which must be set to missing before any summary; the library's Cleaning Data treats such special codes. Because the categories are ordered, a cumulative share makes sense: 37.75% rated their health very good or better, and 75.12% good or better.
So does the median, the category that contains the middle person. The 50% point is crossed in "Good", so the median rating is good. Percentiles in general are meaningful for ordinal data, because they depend only on the order of the values.
The mean of the codes is 2.796. It is not meaningless in the way the race-code mean is, but it rests on the assumption that the five categories are equally spaced. Does that assumption matter? It depends on what the mean is used for, and it matters most when means are used to compare groups.
When recoding reverses a comparison
Any increasing set of numbers $c_1 < c_2 < c_3 < c_4 < c_5$ records the same order as 1 to 5. A researcher who thinks "poor" health is far worse than "fair" might score poor as 10. One who thinks "excellent" stands far above the rest might score it as $-5$. The table compares group means under three such codings. Since the codes rise toward "poor", a higher mean means worse rated health.
| Group | Adults | Codes 1 to 5 | Poor = 10 | Excellent = $-5$ |
|---|---|---|---|---|
| Ages 18 to 39 | 1,740 | 2.550 | 2.642 | 1.557 |
| Ages 60 and over | 1,923 | 2.987 | 3.278 | 2.547 |
| Ages 60 to 69 | 1,021 | 3.005 | 3.250 | 2.570 |
| Ages 70 and over | 902 | 2.967 | 3.310 | 2.521 |
The younger adults rate their health better than the older ones under every coding. The second pair, the older group split at 70, behaves differently:
- with codes 1 to 5, and with excellent scored as $-5$, the adults aged 60 to 69 have the higher (worse) mean;
- with poor scored as 10, the order reverses, and the adults aged 70 and over have the worse mean.
All three codings respect the order of the categories, and all three are equally faithful to the data. So the ordinal data alone do not say which of the two older groups is in worse health. The difference between the two pairs is visible in their cumulative shares.
What the figure shows for these two pairs is an instance of a general fact, proved below. Here is the idea in plain words. A mean of codes can be rewritten as a sum over the cumulative shares, each weighted by a gap between neighboring codes. If one group's cumulative shares are larger everywhere, every term favors it, whatever the gaps. If the curves cross, a large enough gap at the right place can tip the sum either way.
The formal version. Let a rating have $K$ ordered categories. Let $p_k$ be the share of a group in category $k$, and let $F(k) = p_1 + \cdots + p_k$ be the cumulative share at category $k$ or better, with $F(0) = 0$ and $F(K) = 1$.
Proposition. For any increasing codes $c_1 < \cdots < c_K$, the mean code of a group is
$$\sum_{k=1}^{K} c_k p_k = c_K - \sum_{k=1}^{K-1} (c_{k+1} - c_k)\,F(k).$$
Consequently, suppose group A's cumulative shares are at least group B's at every category, $F_A(k) \ge F_B(k)$ for $k = 1, \ldots, K - 1$. Then:
- A's mean is at most B's under every increasing coding;
- it is strictly smaller under every increasing coding if the inequality is strict at some category;
- the two means are equal under every coding if the cumulative shares are equal at every category.
If instead the curves cross, that is, $F_A(j) > F_B(j)$ at some category $j$ and $F_A(m) < F_B(m)$ at another category $m$, there are increasing codings that order the means either way.
Proof. Write $p_k = F(k) - F(k-1)$ and split the sum:
$$\sum_{k=1}^{K} c_k \bigl(F(k) - F(k-1)\bigr) = \sum_{k=1}^{K} c_k F(k) - \sum_{k=0}^{K-1} c_{k+1} F(k).$$
The term $k = K$ of the first sum is $c_K F(K) = c_K$, and the term $k = 0$ of the second is $c_1 F(0) = 0$. The remaining terms, $k = 1$ to $K - 1$, pair up as $(c_k - c_{k+1})F(k)$, which gives the formula.
Now write $g_k = c_{k+1} - c_k > 0$ for the gaps and $\delta_k = F_A(k) - F_B(k)$. Subtracting the formula for B from the formula for A, the common $c_K$ cancels:
$$\text{mean}_A - \text{mean}_B = -\sum_{k=1}^{K-1} g_k\,\delta_k.$$
If every $\delta_k \ge 0$, every term of the sum is nonnegative, so the difference is at most zero whatever the gaps are. It is negative if some $\delta_k > 0$, and zero if every $\delta_k = 0$.
If instead $\delta_j > 0$ and $\delta_m < 0$, take every gap equal to 1 except $g_j = G$. The difference is $-G\delta_j - \sum_{k \ne j}\delta_k$. Since $-\sum_{k \ne j}\delta_k \le \sum_{k \ne j}|\delta_k|$, the difference is at most $-G\delta_j + \sum_{k \ne j}|\delta_k|$, which is negative once $G > \sum_{k \ne j}|\delta_k| / \delta_j$. So A has the smaller mean.
Taking instead every gap equal to 1 except $g_m = G$, the difference is $-G\delta_m - \sum_{k \ne m}\delta_k = G|\delta_m| - \sum_{k \ne m}\delta_k$, which is at least $G|\delta_m| - \sum_{k \ne m}|\delta_k|$. That is positive once $G > \sum_{k \ne m}|\delta_k| / |\delta_m|$, so A has the larger mean. $\square$
Example (no coding can reverse the younger and older adults). No increasing coding, however lopsided, gives the adults aged 60 and over a better mean rating than the adults aged 18 to 39. The cumulative shares of the younger group, at "excellent", "very good or better", "good or better" and "fair or better", are 0.166, 0.468, 0.834 and 0.982. Those of the older group are 0.073, 0.308, 0.690 and 0.942. The younger group's share is larger at every one of the four categories, so every $\delta_k$ is positive (taking A as the younger group): 0.092, 0.160, 0.145 and 0.040. The proposition then says the younger group's mean is smaller, that is, better, under every increasing coding. The three codings in the table are three instances, and no fourth can disagree.
Example (the two older groups). For the adults aged 60 to 69 (A) and 70 and over (B), the differences $\delta_k$ are $-0.002$, $-0.046$, $-0.010$ and $+0.020$. The curves cross between "good or better" and "fair or better", so the proposition's second part applies, and the table shows both orders. The second worked problem below finds the exact code for "poor" at which the order changes.
Example (a common misstatement). "The median is meaningful for ordinal data and the mean is not" is a common summary, and it is too blunt in both halves. The precise statement is the proposition. A comparison of two groups' mean codes is meaningful, in the sense that every order-preserving coding gives the same answer, exactly when one group's cumulative shares lie on or above the other's at every category. The first group is then said to be stochastically smaller (here, healthier). That holds for the younger and older adults. When the curves cross, as for the two older groups, the ordinal data alone do not say which group is better off, and a mean of codes appears to settle the question only because the codes have quietly decided it. The median has its own limit: all four groups in the table have the same median rating, "good", so it cannot separate even the younger adults from the older ones.
This is also why the comparisons of ordinal outcomes in Nonparametric Methods are built on ranks, which use the order and nothing else.
Ordinal categories made from measurements
Self-rated health is ordinal from the start. Ordinal data also often come from cutting a measured quantity into classes. The 2017 guideline of the American College of Cardiology and the American Heart Association sorts adults into four blood pressure categories (Carey and Whelton, 2018):
- normal: systolic below 120 and diastolic below 80 mm Hg;
- elevated: systolic 120 to 129 and diastolic below 80;
- stage 1 hypertension: systolic 130 to 139 or diastolic 80 to 89;
- stage 2 hypertension: systolic at least 140 or diastolic at least 90.
Because stage 1 and stage 2 are defined with "or", a person whose systolic and diastolic pressures point to different categories is placed in the higher one. The man on the first line of this article, at 134 over 66, is in stage 1. Applied to the mean NHANES readings:
| Category | Adults | Share | Cumulative share |
|---|---|---|---|
| Normal | 2,095 | 0.3993 | 0.3993 |
| Elevated | 816 | 0.1555 | 0.5548 |
| Stage 1 | 1,097 | 0.2091 | 0.7639 |
| Stage 2 | 1,239 | 0.2361 | 1.0000 |
The median category is "elevated". These are categories of the pressure measured on the day of the examination, not diagnoses. The guideline asks clinicians to base their estimate of a person's blood pressure on the average of at least two readings obtained on at least two separate occasions (Carey and Whelton, 2018), and NHANES measures each person on one occasion. (The definition of hypertension used in Inference on Proportions also counts people taking blood pressure medication. That is why its prevalence is higher than the 0.4452 here in stage 1 or 2.)
The figure shows the price of the conversion. A person at 131 mm Hg and one at 180 mm Hg are both "stage 2" if their diastolic pressures are high enough. Once the categories are recorded, the difference is gone. Categories are indispensable for clinical decisions and for reporting. For analysis, it is usually better to keep the measurement and categorize at the end.
Ranks
The proposition above showed that comparisons of ordinal data are safe when they use only the order. Ranks are the tool that keeps only the order, for any data that have one.
Ranking a set of values replaces each by its position in order. Eight adults drawn from the survey (seed 3 in the script) have systolic pressures 120.0, 104.7, 124.0, 116.7, 117.3, 125.3, 118.7 and 134.0 mm Hg, rounded to one decimal. Their ranks, from smallest to largest, are 5, 1, 6, 2, 3, 7, 4 and 8. Tied values share the average of the positions they occupy (the midrank), so two values tied for third and fourth both get 3.5.
Example (a common misstatement). "Ranked data" is often listed as a fifth type of data beside nominal, ordinal, discrete and continuous. Ranks are better thought of as a transformation that turns any data with an order into ordinal data of a standard form: whatever the original scale, the ranks of $n$ values without ties are the numbers 1 to $n$.
That is their strength. A statistic computed from ranks is unaffected by:
- any increasing change of scale;
- the spacing of the original categories;
- how extreme the largest values are.
Its distribution under a null hypothesis can also be found by counting. Nonparametric Methods builds the sign, signed-rank, rank-sum and Kruskal–Wallis tests on exactly this property.
Example (ranks under a change of units and under an error). The ranks of the eight pressures do not change if the pressures are converted to kilopascals, or if the largest one, 134.0, is misrecorded as 1340. Multiplying every value by 0.133322 keeps their order, and 1340 is still the largest of the eight. A rank is determined by the order alone, so the ranks stay 5, 1, 6, 2, 3, 7, 4 and 8 in both cases.
The nominal and ordinal types are about categories. The other two types are about numbers that measure an amount, and they start with counting.
Discrete data
Discrete data are numerical values that can be listed one by one, usually counts: the number of people in a household, of previous pregnancies, of hospital admissions in a year, of new cases of a disease. Unlike ordinal codes, counts have meaningful distances and a meaningful zero. A household of 4 has two more people than a household of 2, and twice as many.
Means and standard deviations of counts are therefore interpretable. The two distributions most used for counts, the binomial and the Poisson, are the subject of Theoretical Probability Distributions.
| People in household | 1 | 2 | 3 | 4 | 5 | 6 | 7 or more |
|---|---|---|---|---|---|---|---|
| Adults | 727 | 1,603 | 977 | 822 | 578 | 305 | 235 |
The mean household size is 3.148 people, the median 3 and the mode 2. The table also shows a common feature of real records. To protect privacy, the survey reports any household of 7 or more people as 7 (National Center for Health Statistics, 2020). The 235 adults in that column, 4.48% of the total, may live in households of 7, 9 or 12.
A value recorded as "at least 7" is said to be top-coded or censored. Its recorded value is a lower bound, and that has consequences for the summaries. Survival times are censored in the same way when a study closes before a death is observed: Censoring, Survival Functions and Hazards sorts out the kinds of censoring, and The Kaplan–Meier Estimator estimates a survival curve that uses the lower bounds rather than discarding them.
Example (what top-coding can change). If the true sizes of the 235 households recorded as 7 were known, only the mean could change, and only upward. Every true size is 7 or more, so the true mean is at least 3.148. The median depends only on which side of 3 each person falls: 2,330 adults live in households of 1 or 2 and 977 in households of 3, so the middle adult of the 5,247 is in a household of 3 wherever the top-coded households lie above it. The mode, 2, keeps its 1,603 adults, and no size of 7 or more can be held by more than the 235 top-coded adults.
Continuous data
Continuous data come from measuring a quantity that can, in principle, take any value in an interval: blood pressure, height, weight, age, the concentration of a substance in the blood, the time until an event. The definition is about the quantity, not the record. Every recorded value has finite precision, and the recording rules leave marks on the data that a careful analyst should know about. The NHANES records show two such marks, and one pair of variables that is almost free of them.
Blood pressure is recorded in even numbers. The NHANES data-capture rules accept only even values of systolic and diastolic pressure (National Center for Health Statistics, 2020). All 15,146 systolic readings of the 5,247 adults are even, between 72 and 238 mm Hg, and only 80 distinct readings occur.
The person's value used in this course is the mean of up to three readings, so it can also be a multiple of 2/3. For instance, $(118 + 120 + 122)/3 = 120$ and $(118 + 120 + 124)/3 = 120.67$. In all, 237 distinct values occur among the 5,247 adults. The variable is continuous, but the data are a lattice of closely spaced values. Tables and Graphs for Data shows the lattice appearing in a histogram drawn with very narrow bars.
Age is recorded in whole years and top-coded. Age is continuous in time but recorded in completed years. The survey also records every participant aged 80 or older as 80, because single years of age above 80 were judged a disclosure risk. The documentation reports that the participants coded 80 had a (weighted) mean age of 85 (National Center for Health Statistics, 2020).
Among the 5,247 adults, 350 (6.67%) are coded 80. Their recorded ages pull the mean age, 49.87 years, down. If all 350 were in fact 85, the mean would be 50.20. The median, 51 years, is the same in both cases. As with household size, a summary based on order is immune to top-coding as long as fewer than half the values are affected. A summary based on the values themselves is not.
Height and weight behave almost ideally. Height is recorded to the nearest 0.1 cm and weight to the nearest 0.1 kg. That is fine enough that ties are rare and the data behave much like ideal continuous measurements.
Because continuous values are almost never exactly equal, a list of them is summarized in one of two ways. One is to group them into intervals, as a frequency table and its histogram do. The other is to compute numerical summaries of center and spread. Those are the subjects of the next two articles.
Interval and ratio scales
The course's four kinds of data merge two distinctions: whether the values are categories or numbers, and whether the numbers are counts or measurements. A finer classification of measurements, due to the psychologist S. S. Stevens (1946), separates numbers with a meaningful zero from numbers without one.
- On an interval scale, differences are meaningful but the zero is a convention. Temperature in degrees Celsius is the standard example. The difference between 10 °C and 20 °C equals that between 20 °C and 30 °C, but 20 °C is not "twice as warm" as 10 °C, since the zero point is arbitrary. Such a scale keeps its form under any change of unit and origin, $x' = ax + b$ with $a > 0$, as when Celsius is converted to Fahrenheit.
- On a ratio scale the zero means "none of the quantity", and ratios are meaningful. Blood pressure in mm Hg, height, weight and counts are ratio scales: a pressure of 160 is twice 80. Such scales keep their form only under multiplication by a positive constant, $x' = ax$, as when millimeters of mercury are converted to kilopascals.
Stevens (1946) arranged the four scales, nominal, ordinal, interval and ratio, in a hierarchy. Each is defined by the empirical operation it requires:
- nominal: deciding equality;
- ordinal: deciding greater or less;
- interval: deciding equality of differences;
- ratio: deciding equality of ratios.
Each is also defined by the transformations that leave it unchanged. His criterion for an appropriate statistic was invariance: a statistic is appropriate for a scale if its meaning survives every transformation the scale allows. His table lists, cumulatively, the number of cases, the mode and contingency correlation for nominal scales; the median and percentiles for ordinal scales; the mean, the standard deviation and rank-order and product-moment correlation for interval scales; and the coefficient of variation for ratio scales. The demonstration with the race codes and the recoding of the health ratings above are instances of this criterion.
Example (the coefficient of variation needs a ratio scale). The coefficient of variation is the standard deviation divided by the mean, and Stevens allows it for blood pressure but not for temperature in degrees Celsius, because only a ratio scale leaves it unchanged. Converting units on a ratio scale multiplies every value by the same $a > 0$, so the standard deviation and the mean both scale by $a$ and their ratio is unchanged. Converting Celsius to Fahrenheit multiplies by 1.8 and also adds 32. The shift moves the mean but not the standard deviation, so the ratio changes: its value depends on where the arbitrary zero was put. Measures of Center and Spread proves both scaling rules.
What the classification is for
| Kind of data | Examples in NHANES | Summaries that respect it | Graphs | Where the course analyzes it |
|---|---|---|---|---|
| Nominal | race and Hispanic origin, sex, hypertension yes or no | counts, proportions, mode | bar chart | Inference on Proportions |
| Ordinal | self-rated health, blood pressure category | the above, median, percentiles, cumulative shares | bar chart in category order | Nonparametric Methods |
| Discrete | people in the household | the above, mean, standard deviation | bar chart or histogram | Theoretical Probability Distributions |
| Continuous | blood pressure, height, BMI, age | the above, and quantities that need a meaningful zero, such as ratios and the coefficient of variation | histogram, box plot, scatter plot | from Confidence Intervals on |
The table is a starting point, and the statistics literature has argued about it since Stevens wrote. Stevens himself conceded the practical point. He wrote that in the strictest propriety means and standard deviations ought not to be used with ordinal scales. Yet for this "illegal" statisticizing "there can be invoked a kind of pragmatic sanction: In numerous instances it leads to fruitful results" (Stevens, 1946). He added that such means and standard deviations are in error to the extent that the intervals of the scale are unequal, and that conclusions drawn from them should be cautious.
Velleman and Wilkinson (1993) went further. They argued that the scale type of data is not fixed by the data alone, but may be determined in part by the questions asked of them and the purposes they serve. They recount Lord's (1953) story of football jersey numbers, nominal labels if anything is. A statistician happily averages them to test the accusation that the freshmen were sold unusually low numbers, and for that question the size of the numbers is exactly what matters. Velleman and Wilkinson also note that the four types do not exhaust the possibilities. Mosteller and Tukey's (1977) list of names, grades, ranks, counted fractions (such as percentages, bounded at both ends), counts, amounts and balances includes kinds of data that fit none of Stevens's scales cleanly.
The view this course takes follows from both. The type of a variable is a fact about how its values were produced and what they record. It should be the first thing an analysis establishes, because it decides which summaries and graphs describe the data faithfully and which inferential methods have their assumptions met.
But the type does not by itself dictate the analysis. What matters is to know which assumption each summary adds, and to check whether the conclusion depends on it.
Worked problems
The first problem is an exercise from the course text's chapter on descriptive statistics (Pagano, Gauvreau and Mattie, 2022), restated in our own words. The other three are posed on this article's NHANES data, and the script named under "In Python" computes every number in them and asserts the ones quoted.
Problem 1 (classifying nine measurements). Classify each measurement as nominal, ordinal, discrete or continuous: (a) the number of suicides in the United States in a given year; (b) response to a treatment, recorded as no response, minor improvement, major improvement or complete recovery; (c) the concentration of lead in a sample of water; (d) political party affiliation; (e) the presence or absence of hepatitis C; (f) the length of time a cancer patient survives after diagnosis; (g) the number of previous miscarriages an expectant mother has had; (h) satisfaction with care during a hospital admission, recorded as poor, fair, good, very good or excellent; (i) the age of a child undergoing tonsillectomy.
Solution. The test for each is what the recorded values can be trusted to say: only which category (nominal), also an order (ordinal), a count (discrete), or an amount on a continuum (continuous).
- (a) and (g) are discrete. Each is a count of events, a whole number with a meaningful zero and meaningful differences.
- (b) and (h) are ordinal. The categories have an order, from no response to complete recovery and from poor to excellent, but nothing fixes the distance between neighboring categories. The satisfaction scale in (h) has the same form as the self-rated health item of this article.
- (c) and (f) are continuous. A concentration and a length of time can take any value in an interval, whatever precision they are recorded to.
- (d) is nominal: parties are names with no order.
- (e) is nominal and binary. Coded 0 and 1, its mean is the proportion with hepatitis C.
- (i) is continuous, since age is elapsed time. It is usually recorded in completed years, and the record is then a discrete version of a continuous quantity, as the NHANES ages are.
Problem 2 (the code at which the comparison reverses). Score the health ratings as 1, 2, 3 and 4 for excellent to fair and as $c > 4$ for poor. For which values of $c$ do the adults aged 60 to 69 have a worse (higher) mean than the adults aged 70 and over?
Solution. The answer is every $c$ with $4 < c < 6.931$. At $c = 6.931$ the two means are equal, and above it the order reverses. Take A as ages 60 to 69 and B as ages 70 and over. Their cumulative shares at the first four ratings are
| Excellent | Very good or better | Good or better | Fair or better | |
|---|---|---|---|---|
| A, ages 60 to 69 | 0.0725 | 0.2870 | 0.6846 | 0.9510 |
| B, ages 70 and over | 0.0743 | 0.3326 | 0.6951 | 0.9313 |
| $\delta_k = F_A(k) - F_B(k)$ | $-0.0018$ | $-0.0456$ | $-0.0105$ | $+0.0198$ |
The gaps between neighboring codes are $g_1 = g_2 = g_3 = 1$ and $g_4 = c - 4$. By the proposition,
$$\text{mean}_A - \text{mean}_B = -\sum_{k=1}^{4} g_k\,\delta_k = -(\delta_1 + \delta_2 + \delta_3) - (c - 4)\,\delta_4 = 0.0579 - 0.0198\,(c - 4).$$
This is positive, so that A has the worse mean, exactly when $c - 4 < 0.0579/0.0198$. With the unrounded shares the quotient is 2.931 (the four-decimal values shown give 2.92), so the means tie at $c = 6.93$. The script confirms the sign on either side: the difference is $+0.0382$ at $c = 5$ and $+0.0184$ at $c = 6$, then $-0.0014$ at $c = 7$ and $-0.0607$ at $c = 10$. A researcher who scores "poor" as 6 and one who scores it as 7 reach opposite conclusions from the same answers.
Problem 3 (midranks with ties). Round the eight systolic pressures of the section on ranks to whole numbers, 120, 105, 124, 117, 117, 125, 119 and 134 mm Hg. Find their ranks, and the sum of the ranks.
Solution. In increasing order the values are 105, 117, 117, 119, 120, 124, 125 and 134. The two values of 117 occupy positions 2 and 3, so each gets the midrank $(2 + 3)/2 = 2.5$. The others take their positions. In the original order the ranks are
$$5,\ 1,\ 6,\ 2.5,\ 2.5,\ 7,\ 4,\ 8,$$
and they sum to 36. That is $n(n+1)/2 = 8 \times 9/2$, the sum of the positions 1 to 8. The sum is the same with or without ties, because a midrank replaces the positions of a tied block by their average, which leaves the block's total unchanged. Rounding changed one thing: before rounding, 116.7 and 117.3 had ranks 2 and 3.
Problem 4 (bounds from top-coded data). The mean household size, with the 235 top-coded households counted as 7, is 3.148. (a) What would the mean be if those households in fact averaged 8 people, or 10? (b) How large would they have to be, on average, for the true mean to reach 3.5? (c) Can the same reasoning bound the median?
Solution. (a) Raising each of the 235 recorded values from 7 to an average of $m$ adds $235\,(m - 7)$ to the sum of the 5,247 sizes, so
$$\text{mean} = 3.148 + \frac{235\,(m - 7)}{5247}.$$
For $m = 8$ this is $3.148 + 0.045 = 3.193$, and for $m = 10$ it is $3.148 + 0.134 = 3.282$.
(b) Setting the mean to 3.5 gives $m = 7 + (3.5 - 3.148) \times 5247/235 = 14.86$, using the unrounded mean. The top-coded households would have to average almost 15 people. The recorded mean of 3.148 is a lower bound for the true mean, and each additional person per top-coded household raises it by only $235/5247 = 0.045$.
(c) No bound is needed: the median is exactly 3 whatever the true sizes are. Of the 5,247 adults, 2,330 live in households of 1 or 2 and 977 in households of 3. Half of 5,247 is 2,623.5, which falls among the adults in households of 3, and top-coding changes no value below 7.
What we have learned
Numbers in a data file are not all quantities. Nominal codes are names, and only counts, shares and the mode survive relabeling; a 0/1 code is the exception that turns a mean into a proportion. Ordinal codes carry order but not distance, so a comparison of average ratings is trustworthy only when one group's cumulative shares lie above the other's, as they do for the younger and older adults and do not for the two older groups. Counts and measurements support means and standard deviations, but recording rules such as top-coding and even-numbered readings leave marks that affect a mean more than a median.
Knowing the type tells us which summaries are allowed, but does not yet show us the data. How 5,247 values become a picture that reveals their shape without inventing features is the subject of the next article, Tables and Graphs for Data.
In Python
Most data files store categories as numbers, and a first step in any analysis is to tell the software which columns are categories. In pandas an ordered categorical keeps the order and refuses arithmetic:
import pandas as pd
levels = ['Excellent', 'Very good', 'Good', 'Fair', 'Poor']
health = pd.Categorical.from_codes(codes - 1, categories=levels, ordered=True)
pd.Series(health).value_counts(sort=False) # counts in category order
Here codes holds the survey's values 1 to 5. The library's Summarizing Data with pandas shows what describe() and value_counts() report for categorical columns and which defaults change the answers. Every number in this article is computed by tools/experiments/applied-statistics/types-of-numerical-data.py in the site's repository, which downloads the NHANES files it uses from the CDC and checks their checksums.
References
- Carey, R. M., and Whelton, P. K. (2018). Prevention, detection, evaluation, and management of high blood pressure in adults: synopsis of the 2017 American College of Cardiology/American Heart Association hypertension guideline. Annals of Internal Medicine, 168(5), 351–358. record
- Lord, F. M. (1953). On the statistical treatment of football numbers. American Psychologist, 8(12), 750–751. https://doi.org/10.1037/h0063675. Cited as Velleman and Wilkinson (1993) recount it. record
- Mosteller, F., and Tukey, J. W. (1977). Data Analysis and Regression: A Second Course in Statistics. Addison-Wesley. Cited as Velleman and Wilkinson (1993) describe it. record
- National Center for Health Statistics (2020). National Health and Nutrition Examination Survey 2017–2018: Demographic Variables and Sample Weights (DEMO_J), Blood Pressure (BPX_J), Body Measures (BMX_J) and Hospital Utilization and Access to Care (HUQ_J) data files and documentation. Centers for Disease Control and Prevention. https://wwwn.cdc.gov/nchs/nhanes/continuousnhanes/default.aspx?BeginYear=2017 record · 109 pages
- Pagano, M., Gauvreau, K., and Mattie, H. (2022). Principles of Biostatistics (3rd ed.). CRC Press. The course text. record · 48 pages
- Stevens, S. S. (1946). On the theory of scales of measurement. Science, 103(2684), 677–680. record · 2 pages
- Velleman, P. F., and Wilkinson, L. (1993). Nominal, ordinal, interval, and ratio typologies are misleading. The American Statistician, 47(1), 65–72. record · 2 pages
Reviewed: verified, 16 Nov 2026 · citations checked, 16 Nov 2026 · editorial review, 23 Nov 2026 · 8 revisions