Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Economics

14 Regularization

National Graduate Institute for Policy Studies (GRIPS)

In several sections of this book we touched on the topic of regularization (see, e.g., Section 8.2.1.2 and Section 8.2.3). A variety of statistical procedures and machine learning algorithms employ regularization (under different names) to improve out-of-sample fit. Good out-of-sample fit means generalization from observed data, which, as we’ve stressed before, is the key problem of statistics. This chapter introduces a number of methods that use regularization and discusses their statistical properties.

14.1Nonparametric Density Estimation

Nonparametric density estimation is an application of regularization to the problem of recovering distributions from data. It combines the data with a prior belief that probability mass most likely falls in places other than just the sample points observed so far. As well as being of interest from a theoretical perspective, nonparametric density estimation is used in a great variety of applied studies. We begin our analysis with a review of parametric density estimation and then proceed to nonparametric methods.

14.1.1Introduction

Suppose our data consist of IID observations x1,…,xN\boldx_1, \ldots, \boldx_N from unknown distribution PP on Rd\RR^d. We assume throughout this section that PP is absolutely continuous. Our aim is to estimate the density of PP, denoted below by ff.

We know how to do this in a parametric setting. For example, let’s add the assumption that ff belongs to the class of normal densities on R\RR, so that f=f(⋅ ;μ,σ)=f = f(\cdot \, ; \mu, \sigma) = the normal density for distribution N(μ,σ2)\nN(\mu, \sigma^2). The MLEs of the parameters are μ^N:=xˉN\hat \mu_N := \bar x_N and σ^N:=sN\hat \sigma_N := s_N . Plugging these back into ff gives density estimate f(⋅ ;xˉN,sN)f(\cdot \,; \bar x_N, s_N). Since xˉN\bar x_N and sNs_N are consistent (see Section 9.2.4), the random density f(⋅ ;xˉN,sN)f(\cdot \,; \bar x_N, s_N) will be close to f(⋅ ;μ,σ)f(\cdot \,; \mu, \sigma) with high probability for large NN.

We can clarify convergence of the densities themselves if we extend the notion of consistency from vectors to densities. To extend consistency to densities we need a notion of global deviation between densities. Perhaps the most important measures of global distance are the LpL_p distances. Let’s now define and discuss them.

For any B\bB-measurable function f ⁣:Rd→Rf \colon \RR^d \to \RR and p⩾1p \geq 1, we set

∥f∥p:={∫∣f∣p}1/p:={∫∣f(s)∣p ⁣ds}1/p\| f \|_p := \left\{ \int | f |^p \right\}^{1/p} := \left\{ \int | f(\bolds) |^p \diff \bolds \right\}^{1/p}

where integration is over all of Rd\RR^d. If this expression is finite, then we write f∈Lpf \in L_p. For densities ff and gg on Rd\RR^d the LpL_p distance between these densities is then defined as

dp(f,g):=∥f−g∥pd_p(f, g) := \| f - g \|_p

The norm ∥⋅∥p\| \cdot \|_p satisfies most of the properties of the norms we’ve met so far. For example, we have the triangle inequality

∥f−g∥p⩽∥f−h∥p+∥h−g∥p\| f - g\|_p \leq \|f - h\|_p + \| h - g \|_p

for all p⩾1p \geq 1 and f,g,h∈Lpf, g, h \in L_p. See, for example, theorem 5.1.5 of Dudley (2002).

Specializing to p=1p=1 gives the L1L_1 distance, which sums over absolute deviation. Specializing to p=2p=2 gives the popular L2L_2 distance, which is a variation of the L2L_2 distance we used in Section 5.2.2. See, in particular, (5.28), where distance between random variables is evaluated based on expected deviation.

The L2L_2 distance is popular largely because it’s so tractable, and because it’s similarity to Euclidean vector distance means that we have L2L_2 analogies for a variety of fundamental results on vector space. Nevertheless, the L1L_1 distance is arguably a better choice for studying deviation between densities. For example, the L1L_1 distance between densities is always well-defined (see ex. 14.4.1), which is essential if one hopes to provide universal consistency results.

The bound in (i) is called Pinsker’s inequality, while (ii) is called Scheffé’s identity. Scheffé’s identity tells us that L1L_1 distance measures something that we directly care about: when L1L_1 deviation is small, so is the maximal deviation between probabilities assigned to events.[1]

In what follows, we will say that a sequence {f^N}\{\hat f_N\} of random densities on Rd\RR^d is LpL_p-consistent for a density ff on Rd\RR^d if

∥f^N−f∥p→p0asN→∞\| \hat f_N - f \|_p \toprob 0 \quad \text{as} \quad N \to \infty

14.1.1.1Failure of Consistency

The risk with the parametric approach is that the parametric assumption is incorrect, in the sense that the parametric class doesn’t contain the density generating the data or any good approximation. If this is the case, a parametric approach is typically not consistent. More precisely, if we estimate ff with parametric class {fθ}θ∈Θ\{f_{\boldtheta}\}_{\boldtheta \in \Theta}, then the LpL_p deviation between our estimate and ff is bounded below by

δ(f):=inf⁡θ∈Θ∥f−fθ∥p\delta(f) := \inf_{\boldtheta \in \Theta} \| f - f_{\boldtheta} \|_p

This value will be zero only when ff can be attained as the limit of elements of {fθ}θ∈Θ\{f_{\boldtheta}\}_{\boldtheta \in \Theta}.

14.1.2Kernel Density Estimation

Sometimes we can make good choices for parametric classes by using descriptive statistics or by appealing to some theory with sharp quantitative implications. At other times this is difficult. In such settings it is best to use a nonparametric approach that is consistent under weaker assumptions.

Let’s start with an intuitive discussion and then turn to theory. Suppose that we have IID data x1,…,xN\boldx_1,\ldots,\boldx_N generated from unknown density ff on Rd\RR^d. To estimate ff using the data we will employ a kernel density estimator (KDE), which takes the form

f^N(s):=1Nhd∑n=1NK(s−xnh)\hat f_N(\bolds) := \frac{1}{N h^d} \sum_{n=1}^N K \left( \frac{\bolds - \boldx_n}{h} \right)

Here KK is called the kernel function of the estimator, and hh is called the bandwidth. The kernel function KK is required to be a density on Rd\RR^d but is otherwise unrestricted. The bandwidth hh is any positive number. Exercise 14.4.4 asks you to confirm that f^N\hat f_N is always a density.

To get a feeling for the estimate f^N\hat f_N in (14.5), let’s look at a simple instance created from just three data points x1,x2,x3x_1, x_2, x_3 on R\RR. For KK we take the standard normal density. Since N=3N=3, the function f^N\hat f_N is the sum of three individual functions, the nnth of which can be written as

gn(s)=1NhK(s−xnh)=1Nh12πexp⁡{−(s−xn)22h2}g_n(s) = \frac{1}{N h} K \left( \frac{s - x_n}{h} \right) = \frac{1}{N h} \frac{1}{\sqrt{2 \pi} } \exp \left\{ - \frac{(s - x_n)^2}{2 h^2} \right\}

This is 1N\frac{1}{N} times the density of a N(xn,h2)\nN(x_n, h^2) random variable. So the three functions gng_n are smooth bumps, each centered on one of the data points and with the degree of concentration around xnx_n governed by hh. The top panel of figure 14.1 shows these three functions along with the data points for when h=1h=1. The black line is the pointwise sum of these functions, which is the density estimate f^N\hat f_N. By construction, it is large near the data points and small away from data points.

Nonparametric KDE, different bandwidths

Figure 14.1:Nonparametric KDE, different bandwidths

The lower panel of figure 14.1 shows the same functions when the bandwidth is increased to 1.41.4. Each gng_n becomes more spread out, and the sum f^N\hat f_N is smoother.

As discussed in more detail below, the role of the bandwidth is to add smoothing to the empirical distribution, so we can generalize from a finite sample. But what is the right amount of smoothing? Figure 14.2 illustrates the trade-off associated with smoothing. The shaded distribution is the density ff, which we imagine to be unknown. 40 observations are drawn from this distribution and represented as dots. The black line in each panel is the KDE f^N\hat f_N built from these observations. The kernel is the standard normal density again, while the bandwidth varies across the panels.

As the bandwidth goes to zero, the kernel density becomes similar to the empirical distribution, with all probability mass in very small regions around the sample points. Hence, when we use a very small bandwidth , we make the mistake of treating the empirical distribution as the true distribution. This is overfitting. At the same time, excessive smoothing adds too much bias, hiding the features of the true distribution.[2]

Effect of changing the bandwidth

Figure 14.2:Effect of changing the bandwidth

The optimal bandwidth in terms of minimizing LpL_p deviation depends on the unknown density ff. For example, if ff is smooth, then a relatively large bandwidth should be used. Of course ff is unknown. As such there are two standard approaches. One is to make assumptions on ff and choose the bandwidth accordingly. Another is to use cross-validation. For a review of both procedures see Scott (2015). We’ll say more about cross-validation in the context of ridge regression below.

14.1.3Theory

A natural way to study kernel density estimates is via the notion of convolutions. The convolution of an arbitrary distribution QQ and a density KK on Rd\RR^d is the density on Rd\RR^d defined by

(K⋆Q)(s′)=∫K(s′−s)Q( ⁣ds)(s′∈Rd)(K \star Q) (\bolds') = \int K(\bolds' - \bolds) Q(\diff \bolds) \qquad (\bolds' \in \RR^d)

We already encountered this concept in the discrete case in exercise 5.4.10, where you were asked to prove a version of

We will be particularly interested in a certain class of convolutions, induced by densities of the form

Kh(s):=1hdK(sh)K_h(\bolds) := \frac{1}{h^d} K \left( \frac{\bolds}{h} \right)

where KK is any density and h>0h > 0 is a parameter. The density KhK_h in (14.8) is the density of hxh \boldx when x\boldx is a random vector on Rd\RR^d with density KK. (See ex. 14.4.6.)

Smoothing induced by convolutions

Figure 14.3:Smoothing induced by convolutions

Note how in figure 14.3 the distribution of Kh⋆QK_h \star Q is close to QQ when hh is near zero. This makes sense, since Kh⋆QK_h \star Q is the distribution of x+hyx + hy where xx is drawn from QQ and yy is standard normal. As we take h↓0h \downarrow 0, the distribution of x+hyx + hy converges to the distribution of xx. In fact this is always true:

For a proof, see theorem 9.1 of Devroye & Lugosi (2001).

14.1.3.1Convolution and KDEs

Let hh be a positive number and let KhK_h be as defined in (14.8). Using this notation, we can rewrite the KDE in (14.5) as f^N(s)=1N∑n=1NKh(s−xn)\hat f_N(\bolds) = \frac{1}{N} \sum_{n=1}^N K_h(\bolds - \boldx_n). Letting P^N\hat P_N denote the empirical distribution of the sample and recalling the expression for integrals with respect to P^N\hat P_N, we can also write this as f^N(s′)=∫Kh(s′−s)P^N( ⁣ds)\hat f_N(\bolds') = \int K_h(\bolds' - \bolds) \hat P_N(\diff \bolds), or, more simply,

f^N=Kh⋆P^N\hat f_N = K_h \star \hat P_N

This equation says something interesting. In Section 8.2.1.2 we first tried to estimate the density by a naive application of the sample analogue principle. The method failed. In (14.9) we have an alternative method that employs smoothing, or regularization. We apply the "smoothing operator" Kh⋆K_h \star in addition to replacing the target distribution with the empirical distribution. As the next section shows, this method can be successful under very mild assumptions.

14.1.3.2Consistency

It can be proved that, for any density ff and kernel KK, the nonparametric kernel density estimator f^N\hat f_N is L1L_1-consistent for ff. See theorem 9.2 of Devroye & Lugosi (2001). The L1L_1 proof involves a large amount of measure-theoretic machinery. Here we’ll state and prove the corresponding L2L_2 result instead.

Let’s break this claim down into smaller pieces. For the remainder of this section, ∥⋅∥\| \cdot \| is the L2L_2 norm and h:=hNh := h_N. Using the expression for f^N\hat f_N in (14.9) and the triangle inequality in (14.3), we have

∥f^N−f∥⩽∥Kh⋆P^N−Kh⋆f∥+∥Kh⋆f−f∥\| \hat f_N - f \| \leq \| K_h \star \hat P_N - K_h \star f \| + \| K_h \star f - f \|

The first term is called the estimation error, and the second is called the approximation error or bias. The first error is caused by the fact that we only observe the empirical distribution P^N\hat P_N rather than the true distribution ff. The second error is caused by the smoothing we deliberately added to control the estimation error. (Compare with the error decomposition.)

The fact that hN→0h_N \to 0 in condition (ii) of theorem 14.1.1 means that we shrink the amount of smoothing as the sample size increases, thereby reducing the approximation error. The requirement NhNd→∞N h_N^d \to \infty ensures that smoothing is not reduced too quickly, allowing us to control estimation error.

One way to think about the relationship between inference and the sample is that, when viewed as a "generalized density" with all its mass on data points, the empirical distribution is too rough. To generalize we need to add smoothing. At the same time, the need for smoothing decreases as the sample size gets large.

14.1.4Commentary

In some fields of science, researchers have considerable knowledge about parametric classes and specific functional forms. For example, the theory of Brownian motion describes how the location of a tiny particle in liquid is approximately normally distributed. Thus the underlying theory provides an exact parametric class. In this kind of setting the parametric approach excels. It allows us to generalize by combining data with information we have on functional forms.

Unfortunately, the quantitative foundations of economics and other social sciences are looser and more prone to shifting over time. Econometricians usually come to the table with less knowledge of parametric classes and functional forms. These facts make nonparametric techniques attractive.

At the same time, nonparametric methods do not solve all our problems. The theoretical results presented above are purely asymptotic. Finite sample results are available, but it isn’t possible to obtain strong results in this direction without correspondingly strict assumptions on the target density. There is no uniform rate of convergence for all target densities (Devroye & Lugosi (2001), p. 85). This is because nonparametric methods have relatively little structure in the form of prior knowledge and hence require abundant data.

14.2Controlling Complexity

In the last section we discussed flexible estimation methods that perform well asymptotically. In this section we turn our attention to finite sample properties. A common thread will be ridge regression, which is a popular method of estimation in both econometrics and machine learning (see, e.g., Peysakhovich & Naecker (2015), Kim & Swanson (2014), or Varian (2014)). Ridge regression also connects to some deep ideas at the heart of finite sample theory, including complexity, prior knowledge and the bias–variance trade-off.

14.2.1Ridge Regression

Let’s start off in the classical OLS setting of Section 12.1.1, with assumptions 12.1.2–12.1.4 all in force. The usual OLS estimator is β^\hboldbeta as given in (12.3). It can also be expressed as

β^=argmin⁡b∈RK∑n=1N(yn−xn⊺b)2\hboldbeta = \argmin_{\boldb \in \RR^K} \sum_{n=1}^N (y_n - \boldx_n^\T \boldb)^2

As shown in Section 11.1.2, the OLS estimator minimizes the empirical risk under quadratic loss when the hypothesis space is the set of linear functions. Under our current assumptions, it is also unbiased for β\boldbeta (theorem 12.1.1) and, by the Gauss–Markov theorem, it has the lowest variance among all linear unbiased estimators of β\boldbeta (theorem 12.1.3).

While the Gauss–Markov theorem has historical importance, a more natural way to evaluate estimators is to consider their mean squared error, which tells us directly how much probability mass the estimator puts around the object it is trying to estimate (see Section 9.2.3). Recalling (9.9), the MSE of an estimator b^\hat \boldb of β\boldbeta is defined as

mse⁡(b^,β):=E {∥b^−β∥2}\mse(\hat \boldb, \boldbeta) := \EE \left\{ \| \hat \boldb - \boldbeta \|^2 \right\}

As exercise 14.4.8 asks you to show, the following representation is also valid:

mse⁡(b^,β)=E {∥ b^−E [b^] ∥2}+∥ E [b^]−β ∥2\mse(\hat \boldb, \boldbeta) = \EE \left\{ \| \, \hat \boldb - \EE[\hat \boldb] \, \|^2 \right\} + \| \, \EE[\hat \boldb] - \boldbeta \, \|^2

This equation extends (9.10), and tells us that MSE is the sum of a variance and a bias term. Minimization of MSE involves a trade-off between these two terms. Typically, the optimal choice is not at either extreme: MSE is minimized when some amount of bias is admitted.

Applying this idea to the OLS setting, Hoerl & Kennard (1970) showed that there exists a biased linear estimator that has lower mean squared error than β^\hboldbeta. The estimator is defined as the solution to the modified least squares problem

min⁡b∈RK{∑n=1N(yn−xn⊺b)2+λ∥b∥2}\min_{\boldb \in \RR_K} \left\{ \sum_{n=1}^N (y_n - \boldx_n^\T \boldb)^2 + \lambda \| \boldb \|^2 \right\}

where λ⩾0\lambda \geq 0 is called the regularization parameter. In solving (14.14), we are minimizing the empirical risk plus a term that penalizes large values of ∥b∥\| \boldb \|. The effect is to “shrink” the solution relative to the unpenalized solution β^\hboldbeta. Some calculus shows that the solution to (14.14) is

β^λ:=(X⊺X+λI)−1X⊺y\hboldbeta_{\lambda} := (\boldX^\T \boldX + \lambda \boldI)^{-1} \boldX^\T \boldy

The estimator β^λ\hboldbeta_{\lambda} is called the ridge regression estimator. Note that

  1. β^λ\hboldbeta_\lambda is the OLS estimator when λ=0\lambda = 0 and

  2. β^λ\hboldbeta_\lambda is biased whenever λ>0\lambda > 0 (ex. 14.4.9).

The following result is proved in Hoerl & Kennard (1970).

The reduction in MSE over the least squares estimator occurs because, for some intermediate value of λ\lambda, the variance of β^λ\hboldbeta_{\lambda} falls by more than enough to offset the bias induced by regularization.

Note that, for suitable choice of λ\lambda, the ridge regression estimator β^λ\hboldbeta_{\lambda} outperforms β^\hboldbeta even though all of the classical OLS assumptions are valid. At the same time, the right choice of λ\lambda is a nontrivial problem. This problem falls under the heading of model selection, which is the topic treated in the next few sections.

14.2.1.1Interpretation

The traditional view of ridge regression runs as follows: The standard OLS assumptions are treated as valid. There may, however, be instances where X⊺X\boldX^\T \boldX is almost singular due to strong correlation between regressors. In this case the process of inverting X⊺X\boldX^\T \boldX is numerically unstable. We can stabilize the inversion by adding some positive value of λ\lambda in (14.15).

Here’s another view: The standard OLS assumptions are implausible. Since our loss function is quadratic, we would ideally like to obtain the regression function f∗f^* but recovering this infinite dimensional object with a finite amount of data is ill-posed. We need to control the complexity of the candidate functions we use to approximate the regression function. The regularization term in ridge regression provides a means of managing complexity.

14.2.1.2Tikhonov Regularization

Let’s build some more intuition for the result in theorem 14.2.1 by running simulations. We’ll frame the simulations in a general setting, of which ridge regression is a special case.

We know that the least squares estimator is the solution to an overdetermined system of equations. There is an existing theory for solving ill-posed linear systems in high dimensions. The basic idea is that any attempt to back out or infer a complex object by solving a system about which we have limited information requires a degree of regularization.

To illustrate, suppose that

  1. Ab=c\boldA \boldb = \boldc is an overdetermined system, where A\boldA is N×KN \times K with N>KN > K.

  2. Due to measurement error, we only observe an approximation c0\boldc_0 of c\boldc.

  3. b∗\boldb^* is the (unobservable) least squares solution argmin⁡b∥Ab−c∥2\argmin_{\boldb} \| \boldA \boldb - \boldc \|^2.

In the absence of additional information, a natural approach to approximating b∗\boldb^* is to solve Ab=c0\boldA \boldb = \boldc_0 by least squares. An alternative, less obvious approach, is to minimize

m(λ):=∥Ab−c0∥2+λ∥b∥2m(\lambda) := \| \boldA \boldb - \boldc_0 \|^2 + \lambda \| \boldb \|^2

for some small but positive λ\lambda. This second approach is called Tikhonov regularization. We are minimizing least squares plus a penalty term.

Let’s look at a simulation where A\boldA is chosen stochastically but with a tendency towards multicollinearity. To aid clarity, we first set b∗:=(10,10,…,10)⊺\boldb^* := (10,10,\ldots,10)^\T, and then set c:=Ab∗\boldc := \boldA \boldb^*. By construction, b∗\boldb^* is a solution to the system Ab∗=c\boldA \boldb^* = \boldc, and also the least squares solution.

Effect of Tikhonov regularization, \lambda=1

Figure 14.4:Effect of Tikhonov regularization, λ=1\lambda=1

Measurement of c\boldc is corrupted with a Gaussian shock. In particular, c0\boldc_0 is drawn from N(c,σ2I)\nN(\boldc, \sigma^2 \boldI) where σ\sigma is a small positive number. We then plot the OLS solution based on c0\boldc_0, which minimizes ∥Ab−c0∥2\| \boldA \boldb - \boldc_0 \|^2, and the regularized solution, which minimizes m(λ)m(\lambda) in (14.16). The former are plotted against their index in green, while the latter are plotted in blue. The true solution b∗\boldb^* is plotted in black. The result is figure 14.4.

The figure shows 10 solutions each for the ordinary and regularized solutions, corresponding to 10 draws of c0\boldc_0. The regularized solutions are much closer to the true solution on average.

Note that this result is dependent on a reasonable choice for λ\lambda. If you experiment with the code on the text website, you will see that for very small values of λ\lambda, the regularized solutions are almost the same as the unregularized solutions. Conversely, very large values of λ\lambda pull the regularized solutions too close to the zero vector.

14.2.2Subset Selection and Ridge Regression

One problem frequently faced in regression problems is which variables to include. For example, if we are comparing crime rates across different cites, we can think of any number of variables that might be relevant (median wage, unemployment, police density, etc.). The same is true if we are trying to model credit default rates for some group of individuals, or educational attainment across schools. A similar problem arises in time series models, where we want to know how many lags of the state variables to include. The general problem is known as subset selection, since we are trying to choose the right subset of all candidate regressors.

Further dimensions appear when we consider basis functions. Given a set of covariates x\boldx, we have the option to map this into a larger vector ϕ(x)\boldphi(\boldx) using basis functions, as discussed in Section 11.2.1. For example, given a single covariate xx, we may consider mapping it into ϕ(x)=(1,x,x2,…,xd)\boldphi(x) = (1,x,x^2,\ldots,x^d) and regressing yy on ϕ(x)\boldphi(x). As we saw in figures 8.5–8.8, a good choice of dd is crucial. Choosing dd is another example of the subset selection problem because we are trying to decide whether to include the regressor xjx^j for some given jj.

Subset selection is a version of the empirical risk minimization problem. Suppose that we have output yy and inputs x∈RK\boldx \in \RR^K, in the sense that x\boldx contains KK candidate regressors. If we want to include all regressors, then we can minimize empirical risk over Hℓ\llL in (11.4), the hypothesis space of linear functions from RK\RR^K to R\RR. If we wish to exclude some subset of regressors, we can set I⊂{1,…,K}I \subset \{1,\ldots,K\} to be the set of indices of the regressors we want to exclude and regress yy on the remainder, which is equivalent to minimizing the empirical risk over the hypothesis space

H−I:={ all functions f(x)=b⊺x with bk=0 for all k∈I}\hH_{-I} := \left\{ \text{ all functions } f(\boldx) = \boldb^\T \boldx \text{ with } b_k = 0 \text{ for all } k \in I \right\}

We are back to the problem of choosing a suitable hypothesis space over which to minimize empirical risk.

The subset selection problem has been tackled by many researchers. Well-known approaches include the Akaike Information Criterion (AIC), the Bayesian Information Criterion (BIC), and Mallow’s CpC_p statistic. For example, Mallow’s CpC_p statistic consists of two terms, one increasing in the size of the empirical risk, and the other increasing in ∣I∣|I|, the size of the subset selected. The objective is to minimize the statistic, which involves trading off poor fit (large empirical risk) against excess complexity of the hypothesis space (large ∣I∣|I|).

One of the problems with subset selection is that KK regressors means 2K2^K subsets to step through.[3] To avoid this computational problem, one alternative is to use ridge regression. With ridge regression, the regularization term leads us to choose an estimate with smaller norm. What this means, in practice, is that the coefficients of less helpful regressors are driven towards zero, thereby “almost excluding” those regressors. While the model selection problem is not solved, it has been reduced to tuning a single parameter.

We can illustrate the idea by reconsidering the regression problem discussed in Section 8.2.3. Figure 8.5–Figure 8.8 showed the fit we obtained by minimizing empirical risk over larger and larger hypothesis spaces. The hypothesis spaces were the sets Pd\pP_d of degree dd polynomials for different values of dd. For each dd we minimized the empirical risk over Pd\pP_d, which translates into solving

min⁡b∑n=1N[yn−b⊺ϕ(xn)]2whereϕ(x)=(x0,x1,…,xd)\min_{\boldb} \sum_{n=1}^N \left[ y_n - \boldb^\T\boldphi(x_n) \right]^2 \quad \text{where} \quad \boldphi(x) = (x^0, x^1,\ldots, x^d)

As discussed above, choosing the right dd is isomorphic to subset selection, since we are deciding what powers of xx to include as regressors. Figure 8.4 showed that intermediate values of dd did best at minimizing risk.

We can do a similar thing using ridge regression. First, let’s take P14\pP_{14} as our hypothesis space. This space is certainly large enough to provide a good fit to the data, but with empirical risk minimization the result is overfitting (see figure 8.8). Here, instead of using empirical risk minimization, we solve the regularized problem

min⁡b∑n=1N{[yn−b⊺ϕ(xn)]2+λ∥b∥2}\min_{\boldb} \sum_{n=1}^N \left\{ \left[ y_n - \boldb^\T\boldphi(x_n) \right]^2 + \lambda \| \boldb \|^2 \right\}

for different values of λ\lambda. The data used here are exactly the same data used in the original figures 8.5–8.8 from Section 8.2.3. The solution for each λ\lambda we denote by β^λ\hboldbeta_{\lambda}, which is the ridge regression estimator, and the resulting prediction function we denote by f^λ\hat f_{\lambda}, so that f^λ(x)=β^λ⊺ϕ(x)\hat f_{\lambda}(x) = \hboldbeta_{\lambda}^\T \boldphi(x).

The function f^λ\hat f_{\lambda} is plotted in red for increasingly larger values of λ\lambda over figures 14.5–14.7. The black line is the risk-minimizing function. In figure 14.5, the value of λ\lambda is too small to impose any real restriction, and the procedure overfits. In figure 14.6, the value of λ\lambda is larger and the fit is good. In figure 14.7 the value of λ\lambda is too large and the estimate is poor.

As in Section 8.2.3, we can compute the risk of each function f^λ\hat f_{\lambda}, since we know the underlying model (see (8.25)). The risk is plotted against λ\lambda in figure 14.8. The xx-axis is on log-scale. The risk is smallest for small but nonzero values of λ\lambda.

Fitted polynomial, \lambda \approx 0

Figure 14.5:Fitted polynomial, λ≈0\lambda \approx 0

Fitted polynomial, \lambda \approx 0.0004

Figure 14.6:Fitted polynomial, λ≈0.0004\lambda \approx 0.0004

Fitted polynomial, \lambda \approx 18

Figure 14.7:Fitted polynomial, λ≈18\lambda \approx 18

Risk of \hat f_{\lambda} plotted against \lambda

Figure 14.8:Risk of f^λ\hat f_{\lambda} plotted against λ\lambda

14.2.3Bayesian Methods and Regularization

The ideal case with model selection is that we have clear guidance from economic theory on which regressors to include, which functional forms to use, which values of our regularization parameter to choose, and so on. If theory or prior knowledge provides this information, then every effort should be made to exploit it. One technique for injecting prior information into statistical estimation is via Bayesian analysis. Let’s now look at Bayesian linear regression and how it compares to ridge regression.

Suppose that our regression data take the linear form y=Xβ+u\boldy = \boldX \boldbeta + \boldu. To simplify the presentation we will assume that X\boldX is nonrandom. (Taking X\boldX to be random leads to the same conclusions but with a longer derivation). As before, u\boldu is random and unobservable. The new feature provided by the Bayesian perspective is that we take β\boldbeta to be random and unobservable as well. In addition we are assumed to have subjective prior beliefs regarding likely values for these variates, expressed in the form of probability distributions. Here we take the priors to be L(u)=N(0,σ2I)\lL(\boldu) = \nN(\boldzero, \sigma^2 \boldI) and L(β)=N(0,τ2I)\lL(\boldbeta) =\nN(\boldzero, \tau^2 \boldI).

Given our model y=Xβ+u\boldy = \boldX \boldbeta + \boldu, our prior on u\boldu implies that the density of y\boldy given β\boldbeta is N(Xβ,σ2I)\nN(\boldX \boldbeta, \sigma^2 \boldI). In generic notation, we can write our distributions as

p(y ∣ β)=N(Xβ,σ2I)andp(β)=N(0,τ2I)p(\boldy \given \boldbeta) = \nN(\boldX \boldbeta, \sigma^2 \boldI) \quad \text{and} \quad p(\boldbeta) = \nN(\boldzero, \tau^2 \boldI)

Applying Bayes’ law (see (5.25)) to the pair (y,β)(\boldy, \boldbeta), we obtain

p(β ∣ y)=p(y ∣ β)p(β)p(y)p(\boldbeta \given \boldy) = \frac{p(\boldy \given \boldbeta) p(\boldbeta)}{p(\boldy)}

The left-hand side is the posterior density of β\boldbeta given the data y\boldy, and represents our new beliefs updated from the prior on the basis of the data y\boldy.

One way to summarize the information contained in the posterior is by examining its maximum value. The maximizer of the posterior is called the maximum a posteriori (MAP) probability estimate. Taking logs of (14.18) and dropping the term that does not contain β\boldbeta, it can be expressed as

β^M:=argmax⁡β{ln⁡p(y ∣ β)+ln⁡p(β)}\hboldbeta_{M} := \argmax_{\boldbeta} \left\{ \ln p(\boldy \given \boldbeta) + \ln p(\boldbeta) \right\}

Inserting our functional forms into (14.17), dropping constant terms and multiplying by −1-1, we obtain the expression

β^M=argmin⁡β{∑n=1N(yn−xn⊺β)2+σ2τ2∥β∥2}\hboldbeta_{M} = \argmin_{\boldbeta} \left\{ \sum_{n=1}^N (y_n - \boldx_n^\T \boldbeta)^2 + \frac{\sigma^2}{\tau^2} \| \boldbeta \|^2 \right\}

This is precisely the penalized least squares problem (14.14), where the regularization parameter λ\lambda is equal to (σ/τ)2(\sigma/\tau)^2. In view of (14.15), the solution is

β^M:=(X⊺X+(σ/τ)2I)−1X⊺y\hboldbeta_{M} := (\boldX^\T \boldX + (\sigma/\tau)^2 \boldI)^{-1} \boldX^\T \boldy

Thus Bayesian estimation provides a principled derivation of the penalized objective function from ridge regression. Bayesian analysis provides the same effect as Tikhonov regularization, but now regularization arises out of combining prior knowledge with the data. Moreover, at least in principle, the value (σ/τ)2(\sigma/\tau)^2 is part of our prior knowledge, and hence there is no model selection problem.

In practice, one could of course question the assertion that we have so much prior knowledge that the regularization parameter λ:=(σ/τ)2\lambda := (\sigma/\tau)^2 is pinned down. If such knowledge is lacking, then we are back at the model selection problem. In the next section we forgo the assumption that this strong prior knowledge is available, and consider a more automated approach to choosing λ\lambda.

14.2.4Cross-Validation

A natural way to think about model selection is to think about minimizing risk. Recall that, given loss function LL and a system producing input–output pairs (x,y)∈RK+1(\boldx, y) \in \RR^{K+1} with joint distribution PP, the prediction risk of a function f ⁣:RK→Rf \colon \RR^K \to \RR is the expected loss

R(f):=E [L(y,f(x))]=∫∫L(t,f(s))P( ⁣dt, ⁣ds)R(f) := \EE [ L(y, f(\boldx)) ] = \int \int L(t, f(\bolds)) P(\diff t, \diff \bolds)

that occurs when we use f(x)f(\boldx) to predict yy. Now suppose that we observe NN IID input–output pairs zD:={(x1,y1),…(xN,yN)}\zdata := \{(\boldx_1, y_1), \ldots (\boldx_N, y_N) \}. Given a selection of models, we would like to find the one that takes this data set and returns a predictor f^\hat f such that f^\hat f has lower prediction risk than the predictors returned by the other models.

We have to be precise in defining risk because, if we define it as E [L(y,f^(x))]\EE [ L(y, \hat f(\boldx)) ], then we are taking expectation over all randomness, including that in f^\hat f, which depends on the data set zD\zdata. What we want to do now is take the data set as given, and see how well we can do in terms of predicting new values as evaluated by expected loss. Hence we define the prediction risk of f^\hat f to be the expected loss taking zD\zdata (and hence f^\hat f) as given:

R(f^ ∣ D):=E [L(y,f^(x)) ∣ D]=∫∫L(t,f^(s))P( ⁣dt, ⁣ds)R(\hat f \given \dD) := \EE [ L(y, \hat f(\boldx)) \given \dD] = \int \int L(t, \hat f(\bolds)) P(\diff t, \diff \bolds)

If we have a collection of models MM indexed by mm, and f^m\hat f_m is the predictor produced by fitting model mm with data D\dD, then we would like to find the model m∗m^* such that

R(f^m∗ ∣ D)⩽R(f^m ∣ D)for all m∈MR(\hat f_{m^*} \given \dD) \leq R(\hat f_m \given \dD) \quad \text{for all } m \in M

The obvious problem with this idea is that risk is unobservable. If we knew the joint distribution PP then we could calculate it; but then again, if we knew PP there would be no need to estimate anything in the first place.

Looking at this problem, you might have the following idea: Although we don’t know PP, we do have the data zD\zdata, which consists of IID draws from PP. From the law of large numbers, we know that expectations can be approximated by averages over IID draws, so we could approximate R(f^ ∣ D)R(\hat f \given \dD) by

1N∑n=1NL(yn,f^(xn))\frac{1}{N} \sum_{n=1}^N L(y_n, \hat f(\boldx_n))

where the pairs (xn,yn)(\boldx_n, y_n) are from the data set zD\zdata.

However, this is just the empirical risk, and the empirical risk is a highly biased estimator of the risk. This point was discussed extensively in Section 8.2.3. See, in particular, figure 8.4. The point that figure made was that complex models tend to overfit, producing low empirical risk, but high risk. In essence, the problem is that we are using the data zD\zdata twice, for conflicting objectives. First, we are using it to fit the model, producing f^\hat f. Second, we are using it to evaluate the predictive ability of f^\hat f on new observations.

So what we really need is fresh data. New data will tell us how f^\hat f performs out-of-sample. If we had JJ new observations (yjv,xjv)(y^v_j, \boldx^v_j), then we could estimate the risk by

1J∑j=1JL(yjv,f^(xjv))\frac{1}{J} \sum_{j=1}^J L(y^v_j, \hat f(\boldx^v_j))

Of course, this isn’t a genuine solution because we don’t have any new data in general. One way to work around this problem is to take zD\zdata and split it into two disjoint subsets, called the training set and the validation set. The training set is used to fit f^\hat f and the validation set is used to estimate the risk of f^\hat f. We then repeat this for all models and choose the one with lowest estimated risk.

Since data are scarce, a more common procedure is cross-validation, which attempts to use the whole data set for both fitting the model and estimating the risk. To illustrate the idea, suppose that we partition the data set into two subsets D1\dD_1 and D2\dD_2. First, we use D1\dD_1 as the training set and D2\dD_2 as the validation set. Next we use D2\dD_2 as the training set, and D1\dD_1 as the validation set. The estimate of the risk is the average of the estimates of the risk produced in these two steps.

Of course, we could divide the data into more than two sets. The extreme is to partition the data into NN subsets. This procedure is called leave-one-out cross-validation. Letting D−n:=zD∖{(xn,yn)}\dD_{-n} := \zdata \setminus \{ (\boldx_n, y_n) \}, the data set with just the nnth data point (xn,yn)(\boldx_n, y_n) omitted, the leave-one-out cross validation algorithm can be expressed as follows:

At each step inside the loop, we fit the model using all but the nnth data point, and then predict the nnth data point using the fitted model. The prediction quality is evaluated in terms of loss. Repeating this NN times, we produce an estimate of the risk using average loss. On an intuitive level, the procedure is attractive because we are using the available data intensively but still evaluating based on out-of-sample error.

In terms of model selection, the idea is to run each model through the cross-validation procedure, and then select the one that produces the lowest value of rr, the estimated risk. Let’s illustrate this idea, by considering again the ridge regression procedure used in Section 14.2.2. In this problem the set of models is indexed by λ\lambda, the regularization parameter in the ridge regression. The data set zD\zdata is the set of points shown in figures 14.5–14.7. For each λ\lambda, the fitted function f^λ\hat f_{\lambda} is

f^λ(x)=β^λ⊺ϕ(x)whereβ^λ:=argmin⁡b∑n=1N{(yn−b⊺ϕ(xn))2+λ∥b∥2}\hat f_{\lambda}(x) = \hboldbeta_{\lambda}^\T \boldphi(x) \quad \text{where} \quad \hboldbeta_{\lambda} := \argmin_{\boldb} \sum_{n=1}^N \left\{ (y_n - \boldb^\T\boldphi(x_n))^2 + \lambda \| \boldb \|^2 \right\}

Recall here that ϕ(x)=(x0,x1,…,xd)\boldphi(x) = (x^0, x^1,\ldots, x^d) with dd fixed at 14, so we are fitting a polynomial of degree 14 to the data by minimizing regularized least squares error. The amount of regularization is increasing in λ\lambda. The resulting functions f^λ\hat f_{\lambda} were shown for different values of λ\lambda in figures 14.5–14.7. Intermediate values of λ\lambda produced the best fit in terms of minimizing risk (see figures 14.6 and 14.8).

In that discussion, we used the fact that we knew the underlying model to evaluate the risk, and hence the values of λ\lambda that produce low risk (figure 14.8). In real estimation problems, risk is unobservable, and we need to choose λ\lambda on the basis of the data alone (assuming we don’t have prior knowledge, as in the Bayesian case—see Section 14.2.3). Let’s see how a data-based procedure such as cross-validation performs in terms of selecting a good value of λ\lambda.

In this experiment, for each λ\lambda in the grid exp(seq(-22, 10, length=10)) we perform leave-one-out cross-validation. The fit at each step within the loop is via ridge regression, omitting the nnth data point, and the resulting polynomial is used to predict yny_n from xnx_n. The prediction error is measured by squared loss. In other words, for each λ\lambda in the grid, we use the following algorithm to estimate the risk:

The value of λ\lambda producing the smallest estimated risk rλr_{\lambda} is around 0.015. This is in fact very close to the value that minimizes the actual risk (see figure 14.8). The associated function f^λ\hat f_{\lambda} is plotted in red in figure 14.9, and indeed the fit is close. In this instance, our fully automated procedure is successful.

Fitted polynomial, \lambda \approx 0.015

Figure 14.9:Fitted polynomial, λ≈0.015\lambda \approx 0.015

14.3Further Reading

Textbook treatments of nonparametric methods in econometrics can be found in Pagan & Ullah (1999), Li & Racine (2006), Ullah (1989), Henderson & Parmeter (2015) and Hansen (2015). Bosq (1996) covers nonparametrics for time series models. Recent studies in the econometrics literature using nonparametric or semiparametric methods include Chen & Hong (2012), Jeong et al. (2012), Henderson et al. (2012), Christensen (2014), Canay et al. (2013), Su & Ullah (2013), Bajari et al. (2013), Newey (2013), Hansen (2014), Mastromarco & Simar (2015), Hickman & Hubbard (2015), Matzkin (2015), Bhattacharya (2015), and Du & Escanciano (2015). A beautiful overview of nonparametrics and the method of sieves can be found in Geman & Hwang (1982).

Good discussions of ridge regression and cross-validation can be found in Friedman et al. (2009) and Abu-Mostafa et al. (2012). One alternative to ridge regression is the LASSO method (Tibshirani (1996)), where the term λ∑k=1Kbk2\lambda \sum_{k=1}^K b_k^2 in (14.14) is replaced with an absolute deviation penalty λ∑k=1K∣bk∣\lambda \sum_{k=1}^K |b_k|. Also related is penalized maximum likelihood estimation. A recent application can be found in Gentzkow et al. (2015).

An important contribution to the literature on subset selection is the least angle regression of Efron et al. (2004). A discussion of this method in relation to other subset techniques can be found in Hesterberg et al. (2008).

Recent papers treating regularization and related topics within the econometrics literature include Florens (2003), Carrasco et al. (2007), Chen & Reiss (2011), Florens & Simoni (2014), Darolles et al. (2011), Hoderlein & Holzmann (2011), Horowitz (2014), Hautsch et al. (2012), Li et al. (2015), Lunde et al. (n.d.), Chernozhukov et al. (2015), and Ando & Bai (n.d.).

Regarding implementations, one powerful and increasingly popular package for Bayesian learning is Stan. See http://mc-stan.org/. A popular and high-quality routine for cross validation in the context of ridge regression can be found in the sklearn.linear_model.RidgeCV method in Python’s scikit-learn package.

14.4Exercises

14.4.1Solutions to Selected Exercises

Footnotes
  1. For a proof, see p. 39 of Devroye & Lugosi (2001).

  2. Figure 14.2 is produced using scikit-learn. In R, KDEs can be constructed from the density function. Try, for example, plot(density(runif(200))).

  3. Remember Martin (1997) and his two million growth regressions?

  4. Hint: It is a basic property of integration that g⩽hg \leq h pointwise implies ∫g⩽∫h\int g \leq \int h.

  5. Hint: Try a change-of-variables argument.

References
  1. Dudley, R. M. (2002). Real Analysis and Probability (2nd ed.). Cambridge, UK: Cambridge University Press.
  2. Scott, D. W. (2015). Multivariate Density Estimation: Theory, Practice, and Visualization (2nd ed.). Hoboken, NJ: Wiley.
  3. Devroye, L., & Lugosi, G. (2001). Combinatorial Methods in Density Estimation. New York: Springer.
  4. Peysakhovich, A., & Naecker, J. (2015). Machine learning and behavioral economics: evaluating models of choice under risk and ambiguity [Techreport].
  5. Kim, H. H., & Swanson, N. R. (2014). Forecasting financial and macroeconomic variables using data reduction methods: New empirical evidence. Journal of Econometrics, 178, 352–367.
  6. Varian, H. R. (2014). Big data: New tricks for econometrics. The Journal of Economic Perspectives, 28, 3–27.
  7. Hoerl, A. E., & Kennard, R. W. (1970). Ridge regression: biased estimation for non\-orthogonal problems. Technometrics, 12(1), 55–67.
  8. Pagan, A., & Ullah, A. (1999). Nonparametric Econometrics. Cambridge, UK: Cambridge University Press.
  9. Li, Q., & Racine, J. S. (2006). Nonparametric Econometrics: Theory and Practice. Princeton: Princeton University Press.
  10. Ullah, A. (1989). Semiparametric and Nonparametric Econometrics. Heidelberg: Physica.
  11. Henderson, D. J., & Parmeter, C. F. (2015). Applied Nonparametric Econometrics. Cambridge, UK: Cambridge University Press.
  12. Hansen, B. E. (2015). Econometrics. Textbook in preparation. http://www.ssc.wisc%20edu/~bhansen/econometrics
  13. Bosq, D. (1996). Nonparametric Statistics for Stochastic Processes: Estimation and Prediction (Vol. 110). New York: Springer.
  14. Chen, B., & Hong, Y. (2012). Testing for smooth structural changes in time series models via nonparametric regression. Econometrica, 80(3), 1157–1183.
  15. Jeong, K., Härdle, W. K., & Song, S. (2012). A consistent nonparametric test for causality in quantile. Econometric Theory, 28(04), 861–887.