16 Variable
Average of what?
- What is the average age of the Malagasy population?
- What is the average height of the Malagasy population?
- What is the average salary of the Malagasy population?
This section complements the previous one: to build our statistical framework—and formulate precise research questions—a paired set of concepts is needed. We must define both the population (Chapter 15) and the specific characteristics of that population.
On the surface, a variable is simply a characteristic or feature of interest. Standard textbooks often define it this way because the characteristic varies from one individual or item to another within a population. When working with tabular data in a data frame, a variable typically corresponds to a single column in long-format data.
However, taking a more critical view raises philosophical questions. What, precisely, is a variable? Is it the column header itself (such as “height”), or is it the set of values contained within that column? Are these two ideas identical?
Consider measuring student heights in a single classroom. Height could be collected by asking each student to self-report their height, or by measuring each student directly with a tape measure. Because the measurement methods differ, do these two approaches yield the same variable or two distinct ones? If both methods happen to produce identical values for every student, are the variables then considered identical?
The clearest way to resolve these questions is to define a variable by its measurement process, rather than viewing it merely as a collection of numbers. In statistical terms, a variable is fundamentally a function (Chapter 8). For any mathematical function to be well-defined, it requires a domain, an assignment rule, and a codomain. In statistics, the domain \(X\) represents the population (or sample) under study, the function \(f\) represents the measurement method, and the codomain \(Y\) represents the set of resulting values that populate the data column.
Viewing variables through this functional lens makes classification straightforward. Whether a variable is qualitative (Chapter 18), quantitative (Chapter 17), discrete, or continuous (Chapter 3) depends directly on the properties of its codomain.
Formal
A variable in statistics is a characteristic, attribute, or property of an individual item or subject in a population that can take on different values across different observations.
In formal terms1, if a population or sample is represented as a set of entities \(\Omega\), a variable \(X\) is defined as a function:
\[X: \Omega \rightarrow \mathcal{V}\]
where:
- \(\Omega\) is the domain, representing the set of items, subjects, or experimental units under study.
- \(\mathcal{V}\) is the codomain (or state space), representing the set of all permissible values that the variable can take.
- \(X(\omega)\) assigns a specific measured or observed value in \(\mathcal{V}\) to a particular unit \(\omega \in \Omega\).
Examples
Below are examples of variables2
- When the population consists of study sites: GPS coordinates, elevation, temperature, rainfall, humidity.
- When the population is a village: age, social status, and sex.
- When the population is plants: diameter at breast height (dbh), height, and growth measured between two time points.
Tips and warnings
Is a constant a variable? In practical terms, no, which is precisely why the term “variable” is used in the first place. However, if you measure a characteristic—such as religion in a classroom—expecting it to vary, but discover after collecting data that every individual shares the same religion, should it still be treated as a variable? In mathematics, a constant function like \(f(x) = 1\) is still a valid function. These edge cases could serve as an exercise to think critically about what defines a variable.
Variables are frequently transformed. For instance, a researcher might record age as a continuous numerical (Chapter 17) value and later categorize the data into age brackets like infant, juvenile, and adult (Chapter 18). Once transformed, it becomes a distinct variable with different properties.
A central concept in inferential statistics is the random variable. Its formal treatment is deferred until additional mathematical and statistical foundations are introduced (in future version).
Notation/Semantic/Terminology
Because this book navigates between three subjects—mathematics, statistics, and computer programming—terms with multiple meanings are unavoidable. “Variable” is the most critical example. In mathematics, a variable is an abstract symbol, such as \(x\) or \(y\), linked by a function \(f\). In statistics, it is formalised as a function tied to a specific population and set of measurements. In computer programming, it represents a named reference to an object in memory via variable assignment (Chapter 29).
Whether a variable is described as independent, dependent, or a response variable relates to its role in a relationship—specifically, whether it acts as part of the domain (source set) or the codomain (target set). In contrast, classifying a variable as qualitative, quantitative, discrete, continuous, or boolean reflects the structural properties of the target set itself.