How should variables in statistics be understood? I had a slightly basic question about variables (particularly in statistics).
We would say that “height” is a variable. In my mind, “height” does not just represent different values, like 2, 45, or 75. It represents values + units: 2 feet, 45 feet, or 75 feet.
However, when we work with variables mathematically, I believe that we think of them as solely representing values / numbers. For example, we will say statements such as:
height = 2
weight = height + 4
weight = 6
It seems slightly confusing to me to have to think about variables in 2 different ways. Am I thinking about variables correctly? Thank you all for your help in advance!
 A: Implicitly, there is a unit-conversion factor in front of the height. Thus, the full way to write it is something like:
$$
\text{weight (lbs)} = \dfrac{1 \text{ lbs}}{1 \text{ ft}}\bigg(\text{Height (ft)}\bigg) + 4\text{ (lbs)}
$$
It is typical to ignore units, and statistics tends to work out fine, but you are correct that the units are there and do sometimes need to be considered. For instance, if you wanted to calculate the weight for a subject who has their height measured in meters, you cannot just plug that number of meters into the equation. You would first have to convert the height in meters to a height in feet.
A: You have to be careful here, because this depends on what exactly you're doing. For example, if you consider just a single variable and you compare two groups, methods such as a two-sample t-test or Wilcoxon test are scale invariant, meaning that their outcome will not depend on the measurement unit, and will be the same if you apply a linear (t-test) or even monotonic (Wilcoxon) transformation to the data, as is a change of measurement units.
Note that in most cases changes of measurement unit are linear, but they may not necessarily be, for example fuel consumption of cars can be measured by "gallons per mile" and "miles per gallon"; and you may get different results even in a t-test (as this is only invariant to linear transformation), depending on which measurement unit you choose, but not in a Wilcoxon.
If you want to test, in a single sample, for example "true mean=5", obviously this needs to use the same measurement unit as your data.
Furthermore, there are methods in statistics that are not scale invariant. Particularly when you're working with more than one variable, multivariate methods that bring information from several variables with potentially different measurement units together may be sensitive to the measurement scales. For example Principal Component Analysis and k-means clustering will implicitly give higher weight to variables that have a larger variance. This means that if one variable is weight in kg and the other one is height, the weight/impact of the height variable for the overall result will be higher if height is in cm than if the same heights are given in m, as this will yield smaller numbers and a smaller variance. In such cases it is normally recommended to standardise the data (standardising removes the effect from linear changes of the measurement units), whereas this is not recommended in some cases if the measurement units for all variables are the same, namely if for some reason in the given situation a larger variance implies that a variable is in fact more informative than the others.
A: Units are often understood to be part of a random variable. If someone writes that "$h_i$ is the height of the $i$th patient ", you're meant to assume that every $i$ uses the same unit and it's a sensible one given the context (say, meters if $i$ indexes over adult humans). This is often omitted for clarity, but it would better if people explicitly wrote it out, as " $h_i$ is the height of the $i$th patient in meters."
This restricts how you can manipulate these variables. You can only directly add or subtract variables with the same units, which yields a result with the same units as the original (but see below). Variables with different units can be multiplied or divided, with the result having compound units. If $X$ is in meters and $Y$ in seconds, $\frac{X}{Y}$ has units of $\frac{\text{m}}{\text{s}}$ and $XY$ has units of $\text{m}\cdot \text{s}$. You can also multiply and divide by unitless values, like the number of data points. This doesn't affect the units. Thus, the mean has the same units as the data from which is calculated, as does the standard deviation. Variance, however, has squared units: if $X$ is in meters, $V(X)$ has units of $\text{m}^2$.
Some statistical operations remove the units. Suppose you have a set of heights $h_i$ measured in meters. If you plug these into into the formula for $Z$-scores
$$z_i = \frac{h_i - \bar{h}}{\sigma_h}$$
you'll notice that the units cancel:
$\frac{\left(\text{meter} - \text{meter}\right) \overset{\Delta}{=} \text{meter}}{\text{meter}} = 1$, so $z_i$ is unitless. In a sense, this is the whole point: the $Z$ score is used to make variables, potentially measured with on different scales and with different units, comparable. Covariance and correlation also make a useful pair of examples. If you grind though the formula, you'll find the the covariance of $X$ and $Y$ has units of $x \cdot y$ and a scale that depends on the original variable. Correlation includes a "normalization" term that rescales this to between -1 and +1, while removing the units. This too is intentional: it lets you use correlation to compare relationships between disparate quantities.
Others find conversions between units. You can interpret regression as finding the "best" way to convert between the dependent and independent variables. Suppose you want to crudely predict people's heights. Using a set of heights (in meters), weights (in kilograms), and sex, you might fit a model like:
$$ \text{height} = \beta_0 + \beta_1 \text{weight} + \beta_2 \text{sex}$$
The coefficient $\beta_1$ needs to have units of $\frac{\text{m}}{\text{kg}}$ for the equation to balance, and that's exactly how you should interpret it. Holding everything else at its baseline level, a $1 \text{ kg}$ increase in weight corresponds to a $\beta_1 \text{ m}$ increase in predicted height! Categorical variables are conceptually similar. We usually encode them as (unitless) numbers, such as male=0, female=1. $\beta_2$  is therefore in units of meters. You can also imagine that it's in the fictitious units of meters per sex-code or something if you want to move the units through the encoding process instead.
This holds for linear models, but you can apply similar logic to other families. A logistic regression, for example, predicts probabilities and finds coefficients that can be interpreted as mapping between the predictors and changes in log odds.
Want to learn more? If you're familiar with dimensional analysis from a natural science class, you may enjoy this article Nick Cox found.
Finney, D. J. (1977). Dimensions of Statistics. Journal of the Royal Statistical Society. Series C (Applied Statistics), 26(3), 285–289. https://doi.org/10.2307/2346969
If you want more practice with dimensional analysis, check out the first chapter of Sanjoy Mahajan's Street Fighting Mathematics, available with open-access here.
A: Largely ignorable--the regression won't care if you measure height in inches or feet. However very small or very large numbers (millions or millionths) can cause issues due to software limitations. So when dealing with a large number such as count of population, or count of road miles, you might divide the total (e.g. 12345678) by a thousand to get 1234.5678. Likewise, if you are dealing with a very small number (e.g. pediatric cancer rate per million of .001234), you might change units to get 1.234.
