PUBH-311 · Lesson 1 of 12 · 26 min
Health data and variable types
▶ Video coming soon A video version of this lesson is on the way.
In January, the fictional Kestrel Valley public health unit received the cleaned file from its new Community Health Survey. It held one row for each of 1,200 adults and 86 columns: age, sex, postal area, household income, smoking status, self-rated health, blood pressure measured by a trained interviewer, height and weight, number of emergency department visits in the past year, whether the person had a flu shot, and dozens more. Dr. Amara Osei, the unit’s biostatistician, opened the file with the region’s new public health student, Jonah Whitcombe. Jonah expected her to start running tests. Instead she spent the first morning reading the data dictionary, checking each variable’s type and range, and writing down how every column had been measured. “Most mistakes in health statistics,” she told him, “happen before anyone calculates anything.”
This lesson introduces biostatistics, the application of statistical methods to questions in health, medicine and biology, and the raw material it works with: data. You will learn where public health data come from, how to classify variables, why the type of a variable decides which summaries and tests are appropriate, and how measurement quality, missing values and coding choices shape every result that follows. The Kestrel Valley survey will return throughout the course as a running example, and the final lesson asks you to analyse it from question to report.
Why public health needs statistics
Public health asks questions about populations: how common is diabetes in this region, is it rising, who is most affected, and does a program reduce it? We almost never observe a whole population, so we study samples and use statistics to make careful statements about the larger group. Statistics also help us separate patterns that reflect real differences from patterns that could easily arise by chance, and to describe how uncertain our conclusions are.
Biostatistics sits beside epidemiology. If you have taken Principles of Epidemiology, you learned how to measure disease frequency, compare groups with risk ratios and odds ratios, and think about bias and confounding. Biostatistics supplies the tools for estimating those quantities from data, attaching confidence intervals to them, testing hypotheses and building models that adjust for several factors at once. The companion course Epidemiologic Methods applies these tools to study design, and Nursing Research and Evidence-Based Practice shows how clinicians read the results in published research. This course concentrates on understanding the methods well enough to choose them, carry out the arithmetic for simple cases and interpret computer output correctly.
Statistics can be divided into two broad activities. Descriptive statistics summarize data that we have: counts, proportions, means, medians and graphs. Inferential statistics use a sample to draw conclusions about a population, using estimates, confidence intervals, hypothesis tests and models. Both matter. A surveillance report that only describes cases can still guide action, and a sophisticated model built on poorly described data can mislead.
Populations, samples, parameters and statistics
A population is the entire group we want to learn about, such as all adults living in Kestrel Valley on a given date. A sample is the subset we actually observe, such as the 1,200 survey respondents. A parameter is a numerical characteristic of the population, such as the true proportion of adults who smoke daily; it is usually unknown. A statistic is the corresponding number calculated from a sample, such as the proportion of respondents who report smoking daily. We use statistics to estimate parameters.
By convention, Greek letters stand for parameters and Roman letters for statistics. The population mean is written \(\mu\) (mu) and the sample mean \(\bar{x}\) (x-bar); the population standard deviation is \(\sigma\) (sigma) and the sample standard deviation \(s\); the population proportion is often written \(p\) or \(\pi\) and the sample proportion \(\hat{p}\) (p-hat). You do not need to memorize every symbol, but recognizing them makes formulas and journal articles much easier to read.
Whether a sample tells us anything useful about a population depends on how it was chosen. A random sample, in which every member of the population has a known, non-zero chance of selection, allows us to quantify sampling error. A convenience sample, such as people who answer an online poll, may differ from the population in ways we cannot measure. Lesson 4 returns to sampling designs in more detail.
Where public health data come from
Public health analysts rarely collect all of their own data. Most work draws on a handful of recurring sources, each with strengths and limitations.
Population health surveys ask a sample of residents about their health, behaviours and circumstances. In Canada, Statistics Canada runs the Canadian Community Health Survey (CCHS), a large cross-sectional survey of health status, health care use and determinants of health, and the Canadian Health Measures Survey (CHMS), which adds direct physical measurements and laboratory tests. Surveys are the main source of information about behaviours such as smoking and physical activity, but they rely mostly on self-report and use complex sampling designs that must be accounted for in analysis.
Vital statistics record births, deaths and their causes. Death certificates code the underlying cause of death using the International Classification of Diseases (ICD), maintained by the World Health Organization. Vital statistics are nearly complete for counts but vary in the accuracy of cause-of-death information.
Disease registries collect detailed information on every case of a condition in a defined population. Cancer registries are the best known example and supply incidence, stage at diagnosis and survival data.
Notifiable disease surveillance collects reports of specified infections from laboratories and clinicians, as required by provincial and territorial public health legislation. These data show trends and outbreaks but undercount cases that never reach testing.
Administrative data are records created to run the health system: hospital discharge abstracts, physician billing claims, prescription records and insurance enrolment files. They cover large populations at low cost but were not designed for research, so diagnoses may be coded for payment rather than accuracy.
Research studies, such as cohort studies and randomized trials, collect data for a specific question with careful protocols. They are usually the highest-quality data for their question but may not represent the general population.
| Source | Typical variables | Main strength | Main limitation |
|---|---|---|---|
| Population health survey | Self-rated health, smoking, income, physical activity | Behaviours and determinants not recorded elsewhere | Self-report bias; complex sampling and weights |
| Vital statistics | Births, deaths, cause of death, age, sex | Near-complete counts | Cause-of-death coding errors |
| Disease registry | Diagnosis date, stage, treatment, survival | Detailed, population-wide | Limited to one condition; reporting delays |
| Notifiable disease reports | Case counts, onset dates, organism | Timely detection of outbreaks | Undercounting; testing practices change |
| Administrative data | Diagnosis codes, procedures, costs, visits | Large populations, low cost | Coded for billing, few clinical details |
| Research study | Exposures and outcomes defined by protocol | Careful measurement for one question | Smaller, may not represent the population |
The structure of a data set
Almost every analysis begins with data arranged as a rectangle. Each row is an observation or record, and each column is a variable, a characteristic that can take different values for different observations. The unit of observation is what a row represents: a person, a hospital stay, a household, a neighbourhood or a week of surveillance. Being clear about the unit avoids errors. If a hospital discharge file has one row per stay, a patient admitted three times appears three times, and the number of rows is not the number of patients.
A data dictionary, sometimes called a codebook, documents each variable: its name, label, type, permitted values, units and how it was collected. Good analysts read the dictionary before the data. Table 2 shows part of the Kestrel Valley dictionary.
| Variable | Label | Type | Values or units |
|---|---|---|---|
| id | Respondent identifier | Identifier (not analysed) | 0001 to 1200 |
| age | Age at interview | Numerical, continuous (recorded in whole years) | 18 to 94 years |
| sex | Sex at birth | Categorical, nominal | 1 = female, 2 = male |
| srh | Self-rated health | Categorical, ordinal | 1 = excellent ... 5 = poor |
| sbp | Systolic blood pressure, mean of 2 readings | Numerical, continuous | mmHg |
| edvisits | Emergency department visits, past 12 months | Numerical, discrete | 0, 1, 2, ... |
| flushot | Influenza vaccine in past 12 months | Categorical, binary | 0 = no, 1 = yes |
| foodsec | Household food security status | Categorical, ordinal | 1 = secure, 2 = moderately insecure, 3 = severely insecure |
Types of variables
The type of a variable determines how it should be summarized, graphed and analysed. The main division is between categorical and numerical variables, each with two subtypes (Figure 1).
Categorical variables
Categorical (qualitative) variables place each observation into one of a set of groups. A nominal variable has categories with no natural order: blood type, region of residence, the organism causing an infection. A binary or dichotomous variable is a nominal variable with only two categories, such as vaccinated or not, alive or dead. Binary outcomes are extremely common in public health, and several of the methods in this course (tests for proportions, chi-square tests and logistic regression) are built for them.
An ordinal variable has categories with a natural order but no fixed distance between them. Self-rated health (excellent, very good, good, fair, poor), cancer stage (I to IV), pain on a mild-moderate-severe scale and level of education are ordinal. The distance between "excellent" and "very good" is not necessarily the same as between "fair" and "poor," so arithmetic such as averaging the codes 1 to 5 must be done cautiously, if at all.
Numerical variables
Numerical (quantitative) variables are measured as numbers on a scale where differences have meaning. A discrete variable takes separate, countable values, usually whole numbers: the number of emergency visits, the number of cigarettes smoked per day, the number of cases reported in a week. A continuous variable can in principle take any value within a range: blood pressure, weight, serum cholesterol, birth weight, time to an event. In practice continuous variables are recorded with limited precision (age in whole years, weight to one decimal place), but they are still treated as continuous.
Statisticians sometimes add a further distinction from the psychologist Stanley Stevens’s levels of measurement. An interval scale has equal distances between values but an arbitrary zero, such as temperature in degrees Celsius: 20 degrees is not "twice as hot" as 10 degrees. A ratio scale has a true zero, so ratios make sense: a person who weighs 80 kilograms weighs twice as much as one who weighs 40. Most biological measurements are ratio scales. For the methods in this course the categorical-versus-numerical distinction is usually what matters.
Why the type matters
Table 3 previews how variable type guides the choice of summary, graph and test. You will meet each method in later lessons, so do not worry if some entries are unfamiliar yet; return to this table as the course goes on.
| Outcome type | Summary | Graph | Comparing groups | Model |
|---|---|---|---|---|
| Binary | Count and proportion | Bar chart | Test for two proportions; chi-square | Logistic regression |
| Nominal (3 or more) | Counts and proportions | Bar chart | Chi-square test | Multinomial logistic regression (beyond this course) |
| Ordinal | Counts, proportions, median | Bar chart | Chi-square; rank-based tests | Ordinal regression (beyond this course) |
| Numerical, roughly symmetric | Mean and standard deviation | Histogram, box plot | t-test; analysis of variance | Linear regression |
| Numerical, skewed | Median and interquartile range | Histogram, box plot | Rank-based tests or transformation | Linear regression after transformation |
| Time to event | Median survival; Kaplan-Meier curve | Survival curve | Log-rank test | Cox regression |
Changing a variable’s type
Analysts often convert numerical variables into categories: age into age groups, body mass index into weight categories, blood pressure into "hypertension yes or no." Categories are easy to communicate and match clinical thresholds, but they throw away information. A person with a systolic pressure of 139 mmHg and one with 101 mmHg are treated as identical if the cut-off is 140, while 139 and 141 are treated as different. Statisticians generally advise keeping continuous variables continuous for analysis and categorizing only for presentation, or when a threshold has a clear meaning for action. When you do create categories, choose the cut-points before looking at the results, because choosing them to produce the most striking difference is a form of data dredging.
A related issue is the difference between a variable and its code. In the Kestrel Valley file, sex is stored as 1 and 2 and self-rated health as 1 to 5. These numbers are labels. Software will happily calculate a "mean sex" of 1.52, which only means that 52 percent of respondents are coded 2. Always check whether a numeric column is really a numerical variable.
Measurement quality
A statistic can be no better than the measurements behind it. Two properties matter most. Validity is the degree to which a measurement captures what it is meant to measure. Self-reported weight is systematically lower than measured weight, especially among people with higher weights, so obesity prevalence estimated from self-report tends to be too low; this is a validity problem. Reliability is the consistency of a measurement when it is repeated under the same conditions. A blood pressure reading varies from minute to minute, so surveys usually take two or three readings and average them, which improves reliability.
Errors in measurement are of two kinds. Random error pushes individual values up or down unpredictably; it averages out in large samples but adds noise and makes associations look weaker. Systematic error, or bias, pushes values consistently in one direction; it does not average out and no amount of extra data will remove it. Principles of Epidemiology called the version of this that affects comparisons between groups information bias or misclassification.
Worked problem
Classifying the Kestrel Valley variables
Classify each variable and suggest an appropriate summary: (a) number of cigarettes smoked per day; (b) whether the respondent has a family doctor or nurse practitioner; (c) household food security (secure, moderately insecure, severely insecure); (d) hemoglobin A1c in percent units as reported by the laboratory; (e) postal area of residence.
Show solution
- (a) Cigarettes per day is a count, so it is numerical and discrete. Because many respondents report zero and a few report 30 or more, the distribution will be strongly skewed, so a median and interquartile range among smokers, plus the proportion who smoke, will describe it better than a single mean.
- (b) Having a regular primary care provider is binary (yes or no), a special case of nominal. Summarize with a count and proportion.
- (c) Food security has ordered categories, so it is ordinal. Report counts and proportions in each category in their natural order.
- (d) Hemoglobin A1c is a laboratory measurement on a continuous scale, so it is numerical and continuous. A mean and standard deviation suit a roughly symmetric distribution; check a histogram first.
- (e) Postal area is nominal: the codes identify places but have no order. Report counts by area, or map rates by area, but never average the codes.
Answer: Discrete numerical; binary; ordinal; continuous numerical; nominal. The type tells you which summaries are meaningful before any calculation begins.
Missing data
Real data sets have gaps. Some respondents refuse the income question, some blood pressure readings were not taken because the cuff was broken, and some people drop out of a cohort. How we handle missing values can change the answer, so the reasons they are missing matter. Statisticians use three categories, introduced by Donald Rubin in the 1970s.
- Missing completely at random (MCAR): the chance that a value is missing has nothing to do with the person’s characteristics or the value itself, such as readings lost because a device failed on random days. Analysing only complete cases loses precision but does not bias results.
- Missing at random (MAR): missingness depends on other observed variables but not on the missing value itself once those are taken into account; for example, older respondents skip the physical activity module more often, but within each age group skipping is unrelated to activity level. Methods such as multiple imputation can give unbiased results if the variables that predict missingness are included.
- Missing not at random (MNAR): missingness depends on the unobserved value itself, such as people with the highest alcohol intake being least likely to report it. No standard method fully fixes this, and analysts use sensitivity analyses to see how conclusions change under different assumptions.
Whatever the approach, report how many values were missing for each key variable and how they were handled. A table that silently drops 20 percent of respondents can give a very different picture from one that accounts for them.
Coding, cleaning and derived variables
Before analysis, data must be checked. Range checks look for impossible values: an age of 207, a systolic blood pressure of 12 or a pregnancy recorded for a 4-year-old. Consistency checks compare variables: a respondent who reports never smoking should not also report smoking 15 cigarettes a day. Duplicate checks look for the same person entered twice. Each correction should be documented so that another analyst can reproduce the cleaned file from the raw one.
Analysts also create derived variables from the raw ones. Body mass index is calculated from measured weight and height, \(\text{BMI} = \text{weight (kg)} / \text{height (m)}^2\). Age groups are derived from age, and a "current smoker" indicator from several smoking questions. Derived variables must be defined in the analysis plan so that the same definitions are used throughout.
Finally, health data are personal. Even a file without names can identify people when it contains date of birth, postal code and rare conditions. Public health agencies use rules such as suppressing small cells (for example, not publishing counts below a set threshold, often 5 or 10) and rounding, and they store record-level data securely. These practices are discussed again in the capstone lesson.
Back to Kestrel Valley
By the end of the first day, Jonah had a list of 14 questions for the survey team: why 37 respondents had no blood pressure reading, whether income had been reported before or after tax, and why 3 respondents were listed as 18 years old with 4 children aged over 10. Dr. Osei was pleased. Only one of the problems turned out to be a true error, but each answer changed how a variable would be analysed. The next lesson takes the cleaned file and begins to describe it.
Common mistakes
MistakeTreating numeric codes as numbers, for example averaging codes for region or sex.
InsteadCheck the data dictionary; codes for categories are labels and should be summarized with counts and proportions.
MistakeAssuming the number of rows is the number of people.
InsteadIdentify the unit of observation first; administrative files often have one row per visit, stay or claim.
MistakeDropping every record with any missing value without saying so.
InsteadReport the amount of missing data, consider why it is missing and describe how it was handled.
MistakeSplitting a continuous variable at whatever cut-point gives the biggest difference.
InsteadKeep continuous variables continuous for analysis where possible, and choose any cut-points in advance.
MistakeBelieving a large sample removes bias.
InsteadMore data reduce random error only; systematic error from poor measurement or selection remains.
Summary and key terms
- Biostatistics applies statistical methods to health questions; descriptive statistics summarize data and inferential statistics generalize from samples to populations.
- Parameters describe populations and are usually unknown; statistics are calculated from samples and used to estimate them.
- Public health data come from surveys, vital statistics, registries, notifiable disease reports, administrative records and research studies, each with typical strengths and weaknesses.
- Variables are categorical (nominal, binary or ordinal) or numerical (discrete or continuous), and the type guides the choice of summary, graph and test.
- Validity and reliability describe measurement quality; random error adds noise, while systematic error introduces bias that does not shrink with sample size.
- Missing data may be MCAR, MAR or MNAR, and the mechanism determines whether complete-case analysis or imputation is reasonable.
- Clean data with documented range, consistency and duplicate checks, define derived variables in advance and protect confidentiality.
- Biostatistics
- The application of statistical methods to health, medical and biological questions.
- Parameter
- A numerical characteristic of a population, such as a true mean or proportion.
- Statistic
- A number calculated from sample data, used to estimate a parameter.
- Unit of observation
- What a single row of a data set represents, such as a person, visit or region.
- Nominal variable
- A categorical variable whose categories have no natural order.
- Ordinal variable
- A categorical variable whose categories have a natural order but unequal or unknown spacing.
- Discrete variable
- A numerical variable taking separate countable values, usually counts.
- Continuous variable
- A numerical variable that can take any value within a range.
- Data dictionary
- Documentation listing each variable’s name, meaning, type, values and units.
- Missing at random
- Missingness that depends only on observed variables, not on the missing value itself.
Practice problems
Work each problem on paper first, then reveal the answer to check.
A data set of hospital discharges has 18,400 rows covering 12,950 patients. What is the unit of observation, and why does it matter for estimating how many patients were admitted?
Show answer
The unit is the hospital stay (discharge). Because some patients were admitted more than once, counting rows overstates the number of patients; you would need to count unique patient identifiers.
Classify: (a) Apgar score from 0 to 10; (b) type of tobacco product used (cigarette, cigar, vaping product); (c) serum sodium in mmol/L.
Show answer
(a) Usually treated as ordinal (a scored scale with ordered categories, though sometimes analysed as discrete numerical); (b) nominal; (c) continuous numerical.
In a survey, people with the heaviest drinking are least likely to answer the alcohol questions. What type of missingness is this and what is the likely effect on the estimated average consumption?
Show answer
Missing not at random. Average consumption among respondents will underestimate the true population average.
Give one reason why self-reported height and weight produce a lower estimate of obesity prevalence than measured values.
Show answer
People tend to overstate height and understate weight, so self-reported BMI is systematically too low: a validity problem (systematic error).
Lesson quiz · 5 questions
Score 60% or more to complete this lesson.
Create a free account to save your progress, take quizzes and earn a certificate.