1. Introduction
Applied researchers are often interested in an outcome per unit. Examples include crop yield (e.g., tons per hectare), the concentration of a chemical in a solution (e.g., moles per liter), student performance (e.g., the percentage of students reading at grade level), or investment returns (profit per dollar invested). When the observations collected vary in size, that is, in the number of units they represent, the statistic of interest is often an average outcome per unit over the entire sample. This quantity can be computed as a weighted mean, where the weights reflect the relative size of each observation contributing to the total. I refer to this quantity as the size-weighted mean.
To illustrate with an example from finance, suppose that one wants to compare the execution cost of shares purchased for two different investment portfolios. The execution cost of a trade is defined as the difference between the prevailing market price at the time the order is placed and the subsequent execution price. These two prices may differ due to factors such as broker fees, bid-ask spreads, and execution delays, among others. Execution costs can have substantial implications for the long-term performance of an investment portfolio, and minimizing them is a key objective for traders and institutional investors. The execution cost per dollar for an observation
is defined as
where
is the execution price and
is the market price at the time the order is placed. To compute the investment-weighted average execution cost over
trades, one calculates
where
represents the proportion of the dollar value of trade
relative to the total value of all trades, and the summation runs from
to
. To test if two portfolios face the same execution costs, it is necessary to understand the statistical properties of the size-weighted mean.
Introducing notation in the context of crop yields, suppose each observation represents an individual farm. For each farm
, the researcher observes total output, denoted by
, and total acreage, denoted by
(for “units”), from which crop yield can be computed as
(for “rate”). The overall average yield can be calculated as total output across all farms divided by total acreage across all farms, or equivalently, as the acreage-weighted average of the individual yields. That is, the size-weighted mean
is given by
(1)
where
.
The weighted mean has been widely discussed in the statistical literature. However, most existing work focuses on weights that are either precision weights (also known as analytical or inverse-variance weights) or survey weights (including the closely related sampling and probability weights). Precision weights improve the estimate of a regular mean by using information on the variance of each observation. Survey weights may be used for survey data to address unequal selection probabilities, non-responses, or other sampling issues. In addition, statistical software introduces a third category, frequency weights (also known as case weights), which are used when individual observations have been aggregated into groups and the weight represents the number of observations within each group.
However, size weights differ fundamentally from other types of weights and must be analyzed accordingly. The absence of readily accessible literature describing the statistical properties of the size-weighted mean—combined with the lack of clear guidance on the interpretation of weights in statistical software—has led to considerable confusion among applied researchers, as evidenced by questions and discussions on online forums.1
To illustrate the issue in software applications, consider the PROC MEANS procedure in SAS (Version 9.4). This procedure includes a WEIGHT option, but the documentation provides little guidance, stating only that the weight “specifies a numeric variable whose values weight the values of the analysis variables.” In fact, the calculation of the standard error of the weighted mean in SAS assumes that the weights are precision weights, and the formula is incorrect when applied to size weights. Consequently, applied researchers who use PROC MEANS with the WEIGHT option may draw misleading conclusions about the precision of their estimates when calculating size-weighted means.
For practitioners, the key result of this paper is presented in Theorem 2. In brief, the size-weighted mean is asymptotically normal, with a standard error that can be approximated by
Surprisingly, this result and its derivation do not appear to have been presented in the literature in a straightforward manner. The most relevant discussions can be found in the sampling literature—for example, [1] [ch. 2.12]—but they are often presented in a rather complicated form. Furthermore, many empirical problems, such as comparing execution costs across two investment portfolios, are not naturally framed as sampling problems. As a result, applied researchers are unlikely to consult sampling textbooks in search of answers.
In addition to the main result, I discuss the implementation of weighted means in statistical software. To date, I am unaware of any software that explicitly addresses size-weighted means or provides procedures to estimate their standard errors. The paper concludes by demonstrating that valid inference for size-weighted means can be obtained by estimating a regression with precision weights while using heteroscedasticity-robust standard errors.
2. Asymptotic Theory
When researchers calculate standard errors for equally weighted means, they typically justify the analysis either by assuming a random sampling scheme in which each observation is independently drawn with equal probability from a known population much larger than the sample, or by invoking an abstract super-population framework. The analysis in this paper adopts a similar assumption. Specifically, I assume that the
pairs
are independently and identically distributed (i.i.d.) with a bivariate probability distribution
. I further assume that the number of units
is strictly positive, so that
is always well-defined. The population means of
,
, and
are denoted
,
, and
, respectively, with corresponding population variances
,
, and
, and covariances
,
, and
.2 Equation (1) above characterizes the size-weighted mean as either the ratio of total observed output to the total number of observed units or as a linear combination of observed rates. It is also useful to express it as the ratio of sample means:
(2)
From Equation (2) it follows that, under mild regularity conditions, the weighted mean
is a consistent estimator of
, where
.
The size-weighted and equal-weighted means capture different parameters, both of which may be of interest to the researcher. In the farm example described above, the equal-weighted mean represents the crop yield of a typical farm, whereas the size-weighted mean represents the crop yield of a typical acre. When farm size and yield are correlated, these two measures do not necessarily coincide. A straightforward derivation shows that the difference between them is given by the covariance between
and
divided by the expectation of
Thus, the size-weighted and equal-weighted means coincide only when the covariance between
and
is zero. At the sample level, the difference between
and the sample mean
is given by the sample covariance between the scaled weights
and the observed rates
:
Equation (2) provides the foundation for the asymptotic theory used to derive the distribution of the size-weighted mean. By the multivariate central limit theorem,
where
,
and
is the variance-covariance matrix with elements
,
, and
. Applying the delta method then allows a straightforward derivation of the following theorem:
Theorem 1 The asymptotic distribution of
is given by:
where
Proof. The first-order Taylor expansion of the function
is given by
The corresponding formula for the variance of
follows directly.
To estimate the variance of
, the population parameters can be replaced with their consistent sample analogs, yielding a result that can be directly applied by researchers.
Theorem 2 Under the assumptions above
where
Proof. The sample analog of
is given by:
By expanding and rearranging terms, the expression inside the parentheses simplifies as follows:
such that
When applying these results, researchers should be aware of several important considerations. First, the size-weighted mean typically requires a larger sample size to achieve approximate normality than the equal-weighted mean. For equal-weighted means a sample size of 30 is often considered sufficient for distributions that are not excessively skewed or fat-tailed. For size-weighted means, this means that if the sample size and distribution of units is such that each observation has a weight smaller than 1/30 the approximation is at least as good as for the equal-weighted mean with a sample size of 30.
Furthermore, the derivation of Theorems 1 and 2 relies on a first-order Taylor expansion. This approximation may be poor if the sample mean
can approach zero with non-negligible probability. Kish [2] [p. 208] suggests, as a rule of thumb, that a coefficient of variation of
below 0.1 is generally sufficient for the approximation to be reliable in empirical applications.
Finally, it is important to note that researchers can make significant errors if they use the formula for precision-weighted means when the size-weighted mean is appropriate. The variance of the precision-weighted mean can be estimated by
(3)
Except for using Bessel’s correction, which replaces
with
, Equation (3) is the formula implemented in SAS and Stata. (See also Equation (5) and the corresponding text below.)
To compare the standard errors of the size-weighted and precision-weighted means, it is convenient to write the sample variance of the size-weighted mean as
and the sample variance of the precision-weighted means as
This highlights that the term
in the first equation is replaced by
in the second. The estimated standard error for the size-weighted mean is either larger or smaller than that for the precision-weighted mean, depending on whether larger values of
tend to be associated with larger or smaller values of
. If
is homoscedastic and thus not systematically related to
, the association tends to be positive, and using the precision-weighted formula will generally underestimate the standard error of the size-weighted mean.
3. Statistical Software
I reviewed several widely used statistical software packages to determine if they include procedures for calculating weighted means and their associated standard errors. Many packages provide built-in procedures for calculating weighted means and for that calculation it does not matter whether the weights are precision, survey, size, or frequency weights. When it comes to estimating the standard error, results vary widely across the packages. Notably, my review identified no package that computes the standard error in accordance with Theorem 2.
Among popular software packages, MATLAB’s mean and R’s weighted.mean core functions can calculate weighted means but there appears to be no core function that calculates its standard error. SPSS appears to support only frequency weights. Python NumPy’s average function can calculate a weighted mean but, like Matlab and R, not its standard error. Python’s popular statsmodels package can calculate a weighted mean as well as its standard error, but only for frequency weights.
SAS, in its PROC MEANS command, calculates standard errors for weighted means but only for precision weights. This is particularly concerning because SAS does not explicitly inform users of what type of weights the WEIGHT option assumes. The WEIGHT option doesn’t even always reflect the same type of weight. For instance, in PROC SURVEYMEANS the WEIGHT option reflects survey weights instead of precision weights.
Stata provides four types of weights: precision weights (which it calls analytical weights), sampling weights, frequency weights, and weights that it calls “importance” weights. Stata describes its importance weights as follows: “iweights, or importance weights, indicate the relative ‘importance’ of the observation. They have no formal statistical definition; this is a catch-all category. Any command that supports iweights will define how they are treated. They are usually intended for use by programmers who want to produce a certain computation.”
Thus, Stata’s notion of importance weights does not necessarily match the definition of size weights used in this paper. Moreover, Stata’s collapse command will compute a standard error for the weighted mean only when using precision weights. It is only slightly more reassuring than SAS—which provides no warning at all—that Stata alerts the user when it assumes analytical (i.e., precision) weights if the intended type of weight is not explicitly specified.
4. A Regression Approach
Notwithstanding the lack of canned commands, in some statistical software applications it is possible to obtain standard errors for the size-weighted mean using a regression framework. Specifically, if the application can run a precision-weighted regression while estimating Eicker-Huber-White heteroscedasticity-robust standard errors, then the resulting estimates are identical to those given by Theorem 2, except possibly for small differences due to finite-sample corrections.
To understand why this works, first note that to estimate a regular equal-weighted mean, one can run the regression:
The estimate
is equal to
, and the estimated variance of
is
, ignoring Bessel’s correction (i.e., replacing
with
). Consequently, the estimated variance of
is
.
Because heteroscedasticity is only a concern when the explanatory variables are correlated with the variance of the error term, the heteroscedasticity-robust standard errors for
are identical to the usual standard errors:
Suppose now that
is heteroscedastic where
is equal to
for some value of
. In that case, precision-weighted means can be estimated using standard OLS as follows:
(4)
because
is homoscedastic. Then
with an estimated variance (ignoring Bessel’s correction) of
(5)
where
Now assume that we are interested in size weights instead of precision weights. Equation (4) can still be estimated using OLS to obtain a size-weighted mean. However, since
is now heteroscedastic, it is appropriate to use heteroscedasticity-robust standard errors. The equation for heteroscedascity-robust standard errors reduces to the formula in Theorem 2:
(6)
This shows that if one has software capable of estimating precision-weighted regressions with heteroscedasticity-robust standard errors, it can also be used to estimate size-weighted means with the correct standard errors.
Furthermore, one can test the equality of the size-weighted means of two populations using a regression with robust standard errors. It is well-known that to test the equality of the equal-weighted means of two groups, A and B, one can run the regression
where
indicates membership of observation
in group B. The analogous weighted regression
(7)
provides the following intermediate results:
and
where
and
indicate that the sums are taken over all observations in group A and group B respectively.
Straightforward calculations show that the estimated coefficients are given by:
and the estimated variances are given by:
This shows that
in Equation (7) is the difference between the size-weighted means of group B and group A. Its variance is estimated as
, identical to the variance obtained by using Theorem 2 directly. The t-statistic for
directly tests the equality of the weighted means for groups A and B.
5. Conclusions and Discussion
Applied researchers frequently calculate and discuss size-weighted means. The statistical literature has often overlooked the interest of applied researchers in size-weighted statistics. This paper shows that under standard regularity conditions, the size-weighted mean for i.i.d. random variables is consistent and asymptotically normal. Its standard error can be estimated using a remarkably simple formula, which in some software can be obtained directly from the output of a weighted regression estimated with heteroscedasticity-robust standard errors. Further research in statistical methodology would be valuable to extend the current analysis to more complex settings.
Statistical software packages have also largely overlooked the interest of researchers in size-weighted statistics and provide limited guidance on the interpretation of weights. Researchers therefore risk substantially misreporting the precision of size-weighted means. Statistical software applications should be improved to avoid unintentional misuse. When a statistical software application provides procedures to calculate weighted means, it should clearly describe what the weights represent and how standard errors are calculated.
Acknowledgements
I thank Erin Smith, Chyhe Becker, and my colleagues in the Office of Litigation Economics at the U.S. Securities and Exchange Commission for valuable comments on drafts of the manuscript. I also like to thank an anonymous reviewer for his/her helpful comments and suggestions. The Securities and Exchange Commission disclaims responsibility for any private publication or statement of any SEC employee or Commissioner. This article expresses the author’s views and does not necessarily reflect those of the Commission, the Commissioners, or other members of the staff.
NOTES
1See also e.g. https://notstatschat.rbind.io/2020/08/04/weights-in-statistics.
2In certain settings, the researcher may encounter observations with
. In these settings, Theorem 1 can still be used as it depends only on the assumption that
. Other results presented below depend on
being well-defined for all
.