From 912e20efb62f87bd5053ee8cccd52c404f3694fa Mon Sep 17 00:00:00 2001 From: thomassargent30 Date: Fri, 20 Nov 2026 20:27:22 -0500 Subject: [PATCH 1/3] Add three lectures applying information projections Add approximation_errors, specification_tests, and turbulence_inference after information_projections in the Statistics and Information section. - approximation_errors: misspecified time series estimation as m-projection with the KL divergence rate; Hansen and Sargent (1993), and Sims (1971, 1974, 1993) on sampling, seasonal noise, and seasonal adjustment. - specification_tests: Wu, Hausman, Hausman-McFadden, and Hansen-Sargent (1980) specification tests as comparisons of m-projections, and a frequency-band Hausman test. - turbulence_inference: the laissez-faire economy of Ljungqvist and Sargent (1998), Gottschalk and Moffitt's decomposition as an m-projection, a binding function in the turbulence parameter, a layoff-rate alternative, and Moffitt and Gottschalk's (2011) covariance-structure model. Add links to the new lectures from 16 existing lectures, label the normal KL formula in exponential_families, make the verbal KL convention "divergence of p from q" consistent, correct the description of the criterion in phillips_misspecified, and add 12 bibliography entries. Co-Authored-By: Claude Opus 5.5 --- lectures/_static/quant-econ.bib | 116 +++ lectures/_toc.yml | 3 + lectures/approximation_errors.md | 1192 ++++++++++++++++++++++ lectures/divergence_measures.md | 6 +- lectures/exponential_families.md | 6 +- lectures/gallant_tauchen.md | 8 +- lectures/hansen_singleton_1983.md | 2 + lectures/information_projections.md | 2 + lectures/likelihood_ratio_process.md | 4 +- lectures/likelihood_ratio_process_2.md | 4 +- lectures/likelihood_var.md | 6 +- lectures/lq_permanent_income.md | 2 + lectures/lucas_prescott_search.md | 2 + lectures/mccall_model_with_separation.md | 2 + lectures/ols.md | 2 + lectures/phillips_drifts_volatilities.md | 2 + lectures/phillips_misspecified.md | 8 +- lectures/phillips_policy_evaluation.md | 4 + lectures/phillips_self_confirming.md | 4 + lectures/sargent_surico.md | 2 + lectures/specification_tests.md | 700 +++++++++++++ lectures/turbulence_inference.md | 1172 +++++++++++++++++++++ 22 files changed, 3238 insertions(+), 11 deletions(-) create mode 100644 lectures/approximation_errors.md create mode 100644 lectures/specification_tests.md create mode 100644 lectures/turbulence_inference.md diff --git a/lectures/_static/quant-econ.bib b/lectures/_static/quant-econ.bib index 096d267ee..57e71e5d8 100644 --- a/lectures/_static/quant-econ.bib +++ b/lectures/_static/quant-econ.bib @@ -7008,3 +7008,119 @@ @article{VanCampenhoutCover1981 pages = {483--489}, doi = {10.1109/TIT.1981.1056374} } + +@article{Sims1971, + author = {Sims, Christopher A.}, + title = {Discrete Approximations to Continuous Time Distributed Lags in Econometrics}, + journal = {Econometrica}, + volume = {39}, + number = {3}, + pages = {545--563}, + year = {1971} +} + +@article{Sims1974, + author = {Sims, Christopher A.}, + title = {Seasonality in Regression}, + journal = {Journal of the American Statistical Association}, + volume = {69}, + number = {347}, + pages = {618--626}, + year = {1974} +} + +@article{Sims1993, + author = {Sims, Christopher A.}, + title = {Rational Expectations Modeling with Seasonally Adjusted Data}, + journal = {Journal of Econometrics}, + volume = {55}, + number = {1--2}, + pages = {9--19}, + year = {1993} +} + +@article{Hausman1978, + author = {Hausman, Jerry A.}, + title = {Specification Tests in Econometrics}, + journal = {Econometrica}, + volume = {46}, + number = {6}, + pages = {1251--1271}, + year = {1978} +} + +@article{HausmanMcFadden1984, + author = {Hausman, Jerry and McFadden, Daniel}, + title = {Specification Tests for the Multinomial Logit Model}, + journal = {Econometrica}, + volume = {52}, + number = {5}, + pages = {1219--1240}, + year = {1984} +} + +@article{Wu1973, + author = {Wu, De-Min}, + title = {Alternative Tests of Independence between Stochastic Regressors and Disturbances}, + journal = {Econometrica}, + volume = {41}, + number = {4}, + pages = {733--750}, + year = {1973} +} + +@article{LjungqvistSargent2008, + author = {Ljungqvist, Lars and Sargent, Thomas J.}, + title = {Two Questions about European Unemployment}, + journal = {Econometrica}, + volume = {76}, + number = {1}, + pages = {1--29}, + year = {2008} +} + +@article{GottschalkMoffitt1994, + author = {Gottschalk, Peter and Moffitt, Robert}, + title = {The Growth of Earnings Instability in the {U.S.} Labor Market}, + journal = {Brookings Papers on Economic Activity}, + volume = {1994}, + number = {2}, + pages = {217--272}, + year = {1994} +} + +@article{MoffittGottschalk2011, + author = {Moffitt, Robert A. and Gottschalk, Peter}, + title = {Trends in the Covariance Structure of Earnings in the {U.S.}: 1969--1987}, + journal = {Journal of Economic Inequality}, + volume = {9}, + pages = {439--459}, + year = {2011} +} + +@article{JacobsonLaLondeSullivan1993, + author = {Jacobson, Louis S. and LaLonde, Robert J. and Sullivan, Daniel G.}, + title = {Earnings Losses of Displaced Workers}, + journal = {American Economic Review}, + volume = {83}, + number = {4}, + pages = {685--709}, + year = {1993} +} + +@book{Hannan1970, + author = {Hannan, E. J.}, + title = {Multiple Time Series}, + publisher = {Wiley}, + address = {New York}, + year = {1970} +} + +@article{Sims1972JASA, + author = {Sims, Christopher A.}, + title = {The Role of Approximate Prior Restrictions in Distributed Lag Estimation}, + journal = {Journal of the American Statistical Association}, + volume = {67}, + pages = {169--175}, + year = {1972} +} diff --git a/lectures/_toc.yml b/lectures/_toc.yml index 83d2635e5..30c85b37d 100644 --- a/lectures/_toc.yml +++ b/lectures/_toc.yml @@ -36,6 +36,9 @@ parts: - file: divergence_measures - file: exponential_families - file: information_projections + - file: approximation_errors + - file: specification_tests + - file: turbulence_inference - file: likelihood_ratio_process - file: likelihood_ratio_process_2 - file: likelihood_var diff --git a/lectures/approximation_errors.md b/lectures/approximation_errors.md new file mode 100644 index 000000000..cff9ac3be --- /dev/null +++ b/lectures/approximation_errors.md @@ -0,0 +1,1192 @@ +--- +jupytext: + text_representation: + extension: .md + format_name: myst + format_version: 0.13 + jupytext_version: 1.16.4 +kernelspec: + display_name: Python 3 (ipykernel) + language: python + name: python3 +--- + +(approximation_errors)= +```{raw} jupyter + +``` + +# Approximation Errors in Time Series Models + +```{contents} Contents +:depth: 2 +``` + +## Overview + +When an econometrician estimates a model that does not contain the process that generated the data, the maximum likelihood estimator converges, under regularity conditions, to the member of the model that is closest to the true process in the sense of Kullback–Leibler (KL) divergence. + +In {doc}`information_projections` we called that member the **m-projection** of the true distribution onto the model. + +We organize this lecture around one consequence of that fact: by choosing the model, the data, and any filter that transforms the data, an econometrician chooses which projection an estimator computes. + +For stationary Gaussian processes, the KL divergence per observation converges to an integral over frequencies, so the m-projection trades off approximation errors at different frequencies. + +{cite:t}`Sims1971`, {cite:t}`Sims1974`, {cite:t}`Sims1993`, and {cite:t}`HansenSargent1993` study the errors that an econometrician makes when fitting a misspecified time series model, and they show how sampling, seasonal noise, and seasonal adjustment change those errors. + +The lecture has four sections. + +* {ref}`ae_kl_section` describes the KL divergence between two stationary Gaussian processes as an integral over frequencies. +* {ref}`ae_ar_section` describes misspecified autoregressions as projections of spectral densities, and describes how filtering the data and the model, filtering the data alone, and deleting frequency bands change the projection. +* {ref}`ae_lag_section` describes least squares estimates of distributed lags as m-projections weighted by the spectral density of the regressor, and describes Sims's results on sampling and on seasonal noise. +* {ref}`ae_seasonal_section` describes seasonal adjustment in dynamic rational expectations models. + +{doc}`specification_tests` continues this lecture: it describes specification tests as comparisons of two projections. + +Each section uses the notation of the papers that it describes, so a few symbols change meaning from one section to another. + +In particular, $A$ denotes Hansen and Sargent's criterion and Sims's moving-average operator; $c$ denotes a filter, Sims's lag distribution of seasonal noise, and consumption; $w$ denotes a finite Fourier transform and Sims's seasonal noise; $Y$ denotes a sampled series and income; $\gamma$ denotes an autocovariance and a productivity parameter; $d$ denotes a lag distribution and an endowment shock; and $v$ denotes the seasonal innovation and Sims's noise in $z$. + +{doc}`The lecture on covariance stationary processes ` describes spectral densities. + +{doc}`phillips_misspecified` uses Hansen and Sargent's criterion {eq}`ae_hs_criterion` to compute the beliefs of agents who forecast with a misspecified model. + +We use the following imports. + +```{code-cell} ipython3 +import numpy as np +import matplotlib.pyplot as plt +from scipy import integrate +from scipy.linalg import toeplitz, cho_factor, cho_solve +from scipy.optimize import minimize +``` + +(ae_kl_section)= +## Kullback–Leibler divergence between Gaussian processes + +### Spectral densities + +Let $\{y_t\}$ be a covariance stationary process with mean zero and autocovariances $\gamma_k = E[y_t y_{t-k}]$. + +Its **spectral density** is + +$$ +f(\omega) = \sum_{k=-\infty}^{\infty} \gamma_k e^{-i \omega k} , +\qquad +\gamma_k = \frac{1}{2\pi} \int_{-\pi}^{\pi} f(\omega) e^{i \omega k} \, d\omega . +$$ (ae_spectral) + +We follow the convention of {cite:t}`HansenSargent1993`. + +{doc}`sargent_surico` and {doc}`phillips_drifts_volatilities` put a factor $1/(2\pi)$ in front of the sum; the factor rescales $f$ and leaves ratios such as $f/g$ unchanged. + +Setting $k = 0$ in the second formula shows that $f$ distributes the variance $\gamma_0$ of $y_t$ across frequencies $\omega \in [-\pi, \pi]$. + +The first-order autoregression $y_t = \rho y_{t-1} + \sigma \varepsilon_t$ with $|\rho| < 1$ and white noise $\varepsilon_t$ of unit variance has spectral density $\sigma^2 / |1 - \rho e^{-i\omega}|^2$. + +More generally, the autoregression $a(L) y_t = \sigma \varepsilon_t$ with $a(L) = 1 - a_1 L - \cdots - a_p L^p$ has spectral density $\sigma^2 / |a(e^{-i\omega})|^2$. + +We evaluate spectral densities on a fine grid of frequencies in $[0, 2\pi)$, on which the average of a function approximates $\frac{1}{2\pi}$ times its integral over a period. + +```{code-cell} ipython3 +n_grid = 2**14 +ω = 2 * np.pi * (np.arange(n_grid) + 0.5) / n_grid +z = np.exp(-1j * ω) + + +def ar_poly(a): + """a(e^{-iω}) = 1 - a_1 e^{-iω} - ... - a_p e^{-ipω} on the grid.""" + return 1 - sum(a_j * z**(j + 1) for j, a_j in enumerate(np.atleast_1d(a))) + + +def ar_spectrum(a, σ2=1.0): + return σ2 / np.abs(ar_poly(a))**2 + + +def autocov(f, n_lags): + """γ_0, ..., γ_{n_lags} from the spectral density f on the grid.""" + return np.array([np.mean(f * np.cos(ω * k)) for k in range(n_lags + 1)]) + + +def kl_rate(f, g, keep=None): + """(1/4π) ∫ [f/g - 1 - log(f/g)] dω over the frequencies in keep.""" + ratio = f / g + integrand = ratio - 1 - np.log(ratio) + if keep is not None: + integrand = np.where(keep, integrand, 0.0) + return 0.5 * np.mean(integrand) +``` + +### Divergence rate + +Let $f$ and $g$ be the spectral densities of two stationary Gaussian processes with mean zero, and suppose that both are bounded and bounded away from zero. + +Under the first process, the vector $y^T = (y_1, \ldots, y_T)$ of the first $T$ observations is $N(0, \Gamma_T(f))$, where $\Gamma_T(f)$ is the $T \times T$ matrix with entries $\gamma_{j-k}$; under the second it is $N(0, \Gamma_T(g))$. + +The KL divergence between these two multivariate normal distributions is $\frac{1}{2}[\operatorname{tr}(\Gamma_T(g)^{-1}\Gamma_T(f)) - T - \log\det(\Gamma_T(g)^{-1}\Gamma_T(f))]$, and it grows approximately in proportion to $T$. + +Divided by $T$, it converges to + +$$ +D(f \| g) = \frac{1}{4\pi} \int_{-\pi}^{\pi} \left[ \frac{f(\omega)}{g(\omega)} - 1 - \log \frac{f(\omega)}{g(\omega)} \right] d\omega . +$$ (ae_kl_rate) + +We call $D(f \| g)$ the **KL divergence rate** of the process with spectral density $f$ from the process with spectral density $g$. + +{doc}`likelihood_ratio_process` and {doc}`likelihood_var` write this rate $h_{KL}(f, g)$ and compute it in the time domain, for Markov chains and for Gaussian vector autoregressions; for two first-order vector autoregressions with mean zero, the vector formula {eq}`ae_kl_rate_vector` below equals {eq}`eq:var_kl_rate`. + +**The KL divergence rate is the average over frequencies of the KL divergences between normal distributions whose variances are the two spectral densities at each frequency.** + +The transforms $w_j = T^{-1/2} \sum_{t=1}^T y_t e^{-i \omega_j t}$ at the frequencies $\omega_j = 2\pi j / T$ with $0 < \omega_j < \pi$ are, for large $T$, approximately independent complex normal random variables with variances $f(\omega_j)$. + +So the KL divergence between the two distributions of a sample of $T$ observations is approximately the sum, over about $T/2$ frequencies, of the divergences between the two distributions of $w_j$. + +At each frequency, the divergence is the divergence between two normal distributions with mean zero and variances $f(\omega_j)$ and $g(\omega_j)$, which by formula {eq}`ef_kl_normal` of {doc}`exponential_families` is $\frac{1}{2}[f/g - 1 - \log(f/g)]$ for a real normal random variable and twice that for a complex one. + +Summing over the $T/2$ frequencies and dividing by $T$ gives {eq}`ae_kl_rate`. + +We check {eq}`ae_kl_rate` by computing the exact divergence between the distributions of $T$ observations from two first-order autoregressions with $\rho = 0.9$ and $\rho = 0.5$. + +```{code-cell} ipython3 +def ar1_autocov(ρ, T): + return ρ**np.arange(T) / (1 - ρ**2) + + +def kl_normal_vectors(Σ1, Σ2): + """KL divergence of N(0, Σ1) from N(0, Σ2).""" + M = cho_solve(cho_factor(Σ2), Σ1) + return 0.5 * (np.trace(M) - len(M) - np.linalg.slogdet(M)[1]) + + +ρ1, ρ2 = 0.9, 0.5 +for T in (25, 100, 400, 1600): + Σ1 = toeplitz(ar1_autocov(ρ1, T)) + Σ2 = toeplitz(ar1_autocov(ρ2, T)) + print(f"T = {T:5d}: divergence / T = {kl_normal_vectors(Σ1, Σ2) / T:.5f}") +print(f"divergence rate: {kl_rate(ar_spectrum(ρ1), ar_spectrum(ρ2)):.5f}") +``` + +For a vector process with spectral density matrices $F$ and $G$ and means $\nu$ and $\mu$, the same argument gives + +$$ +\frac{1}{4\pi} \int_{-\pi}^{\pi} \left[ \operatorname{tr}\left(G(\omega)^{-1} F(\omega)\right) - n - \log \det \left(G(\omega)^{-1} F(\omega)\right) \right] d\omega ++ \frac{1}{2} (\nu - \mu)^\top G(0)^{-1} (\nu - \mu) , +$$ (ae_kl_rate_vector) + +where $n$ is the dimension of the process. + +The means enter through the transform at frequency zero, $w_0 = T^{1/2} \bar y$, whose covariance matrix is approximately $G(0)$ under the second process. + +{doc}`phillips_misspecified` describes a model with mean zero that fits a nonzero mean by raising $G(0)$, which shrinks the mean term. + +### Hansen and Sargent's approximation criterion + +{cite:t}`HansenSargent1993` write: + +> We want to study the errors of economic interpretation that an econometrician makes when he estimates a misspecified model. It is well-known that there is an important link between likelihood estimation and the Kullback–Leibler (1951) information criterion. + +They let $F(\omega)$ and $\nu$ be the spectral density matrix and mean of a vector of observables, and $G(\omega, \delta)$ and $\mu(\delta)$ be the spectral density matrix and mean that an approximating model with parameter vector $\delta$ implies. + +They show that, when the minimizer is unique, the Gaussian maximum likelihood estimator of $\delta$ converges almost surely to the minimizer of their **approximation criterion** + +$$ +A(\delta) = \frac{1}{2\pi} \int_{-\pi}^{\pi} \log \det G(\omega, \delta) \, d\omega ++ \frac{1}{2\pi} \int_{-\pi}^{\pi} \operatorname{trace}\left[G(\omega, \delta)^{-1} F(\omega)\right] d\omega ++ [\nu - \mu(\delta)]^\top G(0, \delta)^{-1} [\nu - \mu(\delta)] . +$$ (ae_hs_criterion) + +Subtracting from $A(\delta)$ the quantity $\frac{1}{2\pi}\int \log \det F(\omega) \, d\omega + n$, which does not depend on $\delta$, leaves twice the divergence rate {eq}`ae_kl_rate_vector`. + +Hence **the probability limit of the misspecified maximum likelihood estimator is the m-projection of the true process onto the model, with divergence measured by the KL divergence rate.** + +{cite:t}`HansenSargent1993` apply at each frequency $\omega$ what they call "the familiar information inequality for normally distributed random variable": + +$$ +\log \det G(\omega, \delta) + \operatorname{trace}\left[G(\omega, \delta)^{-1} F(\omega)\right] +\geq \log \det F(\omega) + n . +$$ + +Integrating over frequencies shows that the first two terms of $A(\delta)$ are at least $\frac{1}{2\pi}\int \log \det F(\omega) \, d\omega + n$, with equality when $G(\cdot, \delta) = F$; the mean term is nonnegative and equals zero when $\mu(\delta) = \nu$. + +### Periodogram and likelihood + +{cite:t}`HanSar1980`, following {cite:t}`Hannan1970`, use a frequency-domain approximation to the Gaussian log likelihood of a sample of $T$ observations, often called the Whittle likelihood after {cite:t}`Whittle1953`: + +$$ +- \frac{1}{2} \sum_{j=0}^{T-1} \log \det G(\omega_j, \delta) - \frac{1}{2} \sum_{j=0}^{T-1} \operatorname{tr}\left[ G(\omega_j, \delta)^{-1} I(\omega_j) \right] +$$ (ae_whittle) + +plus a constant, where $\omega_j = 2\pi j / T$ and $I(\omega_j) = T^{-1} \left(\sum_t y_t e^{-i\omega_j t}\right)\left(\sum_t y_t e^{i\omega_j t}\right)^\top$ is the **periodogram**. + +Hansen and Sargent write $S$ for the model's spectral density matrix; we keep the notation $G(\omega, \delta)$ of their 1993 paper. + +{doc}`kalman_filter_var` evaluates the exact Gaussian log likelihood of a state-space model from its innovations; {eq}`ae_whittle` approximates the same likelihood frequency by frequency. + +Maximizing {eq}`ae_whittle` minimizes a sample version of the first two terms of {eq}`ae_hs_criterion`, with the periodogram in place of the true spectral density $F$. + +In {doc}`information_projections` the maximum likelihood estimator is the m-projection of the empirical distribution onto the model; in {eq}`ae_whittle` the periodogram takes the place of the empirical distribution. + +The periodogram does not converge to $F(\omega)$ at any frequency: for a scalar process its variance stays near $f(\omega)^2$. + +Averages of $\operatorname{tr}[G(\omega_j, \delta)^{-1} I(\omega_j)]$ over frequencies do converge to the corresponding averages of $\operatorname{tr}[G(\omega, \delta)^{-1}F(\omega)]$, and the convergence of the estimator to the minimizer of {eq}`ae_hs_criterion` requires only those averages. + +(ae_ar_section)= +## Misspecified autoregressions + +### Projection onto autoregressions + +Suppose that an econometrician fits the autoregression $a(L) y_t = \sigma \varepsilon_t$ to a scalar process with spectral density $f$, so that the model's spectral density is $g(\omega) = \sigma^2 / |a(e^{-i\omega})|^2$. + +For a fixed polynomial $a$, the variance $\sigma^2$ that minimizes the divergence rate {eq}`ae_kl_rate` is + +$$ +\sigma^2(a) = \frac{1}{2\pi} \int_{-\pi}^{\pi} f(\omega) |a(e^{-i\omega})|^2 \, d\omega = E\left[ \left( a(L) y_t \right)^2 \right] , +$$ + +the mean squared one-step-ahead forecast error of the rule $\hat y_t = a_1 y_{t-1} + \cdots + a_p y_{t-p}$. + +When the roots of $a$ lie outside the unit circle, Kolmogorov's formula gives $\frac{1}{2\pi}\int \log |a(e^{-i\omega})|^2 \, d\omega = 0$. + +Substituting $\sigma^2(a)$ into {eq}`ae_kl_rate` then gives + +$$ +D(f \| g) = \frac{1}{2} \left[ \log \sigma^2(a) - \frac{1}{2\pi} \int_{-\pi}^{\pi} \log f(\omega) \, d\omega \right] . +$$ + +By Kolmogorov's formula, $\frac{1}{2\pi}\int_{-\pi}^{\pi} \log f(\omega) \, d\omega = \log \sigma^2_\infty$, where $\sigma^2_\infty$ is the variance of the one-step-ahead forecast error of $y_t$ given its infinite past, so $D(f \| g) = \frac{1}{2} \log [\sigma^2(a)/\sigma^2_\infty]$. + +For a vector process, the spectral factorization identity {eq}`eq:sf_identity` of {doc}`kalman_filter_var` gives the counterpart: the average over frequencies of the log determinant of the spectral density matrix of a state-space model's observables equals the log determinant of its innovation covariance matrix, $G\Sigma G^\top + R$ in that lecture's notation. + +The second term does not depend on $a$, so **the m-projection of a stationary process onto the autoregressions of order $p$ chooses the coefficients that minimize the mean squared one-step-ahead forecast error.** + +Those coefficients solve the Yule–Walker equations $\sum_{k=1}^p a_k \gamma_{j-k} = \gamma_j$ for $j = 1, \ldots, p$; for $p = 1$, $a_1 = \gamma_1 / \gamma_0$. + +In the frequency-domain likelihood {eq}`ae_whittle`, the autoregressions of order $p$ form an exponential family whose sufficient statistics are the autocovariances at lags $0, \ldots, p$. + +As in {doc}`information_projections`, the m-projection matches moments: its autocovariances at lags $0, \ldots, p$ equal those of $y_t$. + +The same argument applies to any model whose moving-average operator is a ratio of polynomials with leading coefficient one and roots outside the unit circle; with a nonzero mean, the concentrated variance adds the squared mean of the forecast errors. + +{doc}`phillips_misspecified` uses it to compute the forecasting rules of agents whose models are misspecified. + +The function below computes the m-projection by minimizing the divergence rate directly. + +Its argument `keep` restricts the criterion to a subset of frequencies. + +Replacing a root of $a$ by its reciprocal leaves the shape of the spectral density unchanged, so the criterion also has minimizers outside the stationary region. + +We restrict the search to stationary autoregressions by parameterizing them with partial autocorrelations in $(-1, 1)$. + +```{code-cell} ipython3 +def yule_walker(γ, p): + return np.linalg.solve(toeplitz(γ[:p]), γ[1:p + 1]) + + +def pacf_to_ar(pacf): + """AR coefficients from partial autocorrelations (Durbin–Levinson).""" + a = np.zeros(0) + for φ_kk in pacf: + a = np.append(a - φ_kk * a[::-1], φ_kk) + return a + + +def ar_to_pacf(a): + a, pacf = np.array(a, dtype=float), [] + while len(a): + φ_kk = a[-1] + pacf.append(φ_kk) + a = (a[:-1] + φ_kk * a[:-1][::-1]) / (1 - φ_kk**2) + return np.array(pacf[::-1]) + + +def ar_projection(f, p, keep=None): + """Stationary AR(p) coefficients and innovation variance that minimize + the divergence rate of f from the AR model, over the frequencies in keep.""" + keep = np.ones(n_grid, bool) if keep is None else keep + + def criterion(θ): + a2 = np.abs(ar_poly(pacf_to_ar(np.tanh(θ)))[keep])**2 + return np.log(np.mean(f[keep] * a2)) - np.mean(np.log(a2)) + + θ0 = np.arctanh(ar_to_pacf(yule_walker(autocov(f, p), p))) + θ = minimize(criterion, θ0, method="BFGS", options={"gtol": 1e-8}).x + a = pacf_to_ar(np.tanh(θ)) + σ2 = np.mean((f * np.abs(ar_poly(a))**2)[keep]) + return a, σ2 +``` + +### Seasonal example + +Let the observed quarterly series be the sum $y_t = x_t + s_t$ of a nonseasonal component and a seasonal component that are independent of each other: + +$$ +x_t = 0.9 \, x_{t-1} + e_t , +\qquad +(1 + \varphi L + \varphi^2 L^2 + \varphi^3 L^3) \, s_t = v_t , +\qquad \varphi = 0.98 . +$$ + +The roots of the seasonal polynomial lie just outside the unit circle at the seasonal frequencies $\pi/2$ and $\pi$, so the spectral density of $s_t$ has narrow peaks there. + +We scale $v_t$ so that the variance of $s_t$ is one quarter of the variance of $x_t$. + +An econometrician fits a first-order autoregression to $y_t$. + +```{code-cell} ipython3 +ρ_x, φ = 0.9, 0.98 +f_x = ar_spectrum(ρ_x) +f_s = ar_spectrum([-φ, -φ**2, -φ**3]) +f_s = f_s * 0.25 * np.mean(f_x) / np.mean(f_s) +f_y = f_x + f_s + +a_full, σ2_full = ar_projection(f_y, 1) +g_full = ar_spectrum(a_full, σ2_full) +γ_y = autocov(f_y, 1) +print(f"m-projection: ρ* = {a_full[0]:.4f}, γ_1/γ_0 = {γ_y[1] / γ_y[0]:.4f}") +print(f"divergence rate at the projection: {kl_rate(f_y, g_full):.4f}") +print(f"g/f at frequency zero: {g_full[0] / f_y[0]:.2f}") +``` + +The m-projection has $\rho^* = 0.62$, well below the coefficient $0.9$ of the nonseasonal component. + +The left panel of the figure plots the logarithms of the spectral densities of $y_t$, of $x_t$, and of the projection. + +The right panel plots $\frac{1}{2}[f/g - 1 - \log(f/g)]$ at each frequency; its average over frequencies is the divergence rate. + +In the right panel, vertical lines mark the seasonal frequencies $\pi/2$ and $\pi$. + +```{code-cell} ipython3 +--- +mystnb: + figure: + caption: Spectral densities (left) and the contribution of each frequency to the divergence rate (right) for an AR(1) fitted to a series with a seasonal component + name: fig-ae-seasonal-ar1 +--- +half = ω <= np.pi +π_ticks = (np.arange(5) * np.pi / 4, + ["0", r"$\pi/4$", r"$\pi/2$", r"$3\pi/4$", r"$\pi$"]) + +fig, axes = plt.subplots(1, 2, figsize=(11, 4)) +ax = axes[0] +ax.plot(ω[half], np.log(f_y[half]), lw=2, label="$y_t$") +ax.plot(ω[half], np.log(f_x[half]), "--", label="$x_t$") +ax.plot(ω[half], np.log(g_full[half]), lw=2, + label=rf"AR(1) projection, $\rho^*$ = {a_full[0]:.2f}") +ax.set_xticks(*π_ticks) +ax.set_xlabel(r"$\omega$") +ax.set_ylabel("log spectral density") +ax.legend(loc="lower center", bbox_to_anchor=(0.5, 1.0), ncol=2, fontsize=9, + frameon=False) + +ax = axes[1] +ratio = f_y / g_full +ax.semilogy(ω[half], 0.5 * (ratio - 1 - np.log(ratio))[half], lw=2) +ax.set_ylim(1e-3, 30) +ax.set_xticks(*π_ticks) +ax.set_xlabel(r"$\omega$") +ax.set_ylabel(r"KL divergence at frequency $\omega$") +for c in (np.pi / 2, np.pi): + ax.axvline(c, color="0.7", lw=0.8) +plt.tight_layout() +plt.show() +``` + +A first-order autoregression cannot produce a peak at $\pi/2$ or a narrow peak at $\pi$, so the divergence is largest at those frequencies. + +For a given $\sigma^2$, lowering $\rho$ raises the model's spectral density at high frequencies and lowers it near frequency zero. + +The first effect reduces the divergence at $\pi/2$ and $\pi$; the second raises it near frequency zero, where $x_t$ has most of its power. + +With $r = f/g$, the integrand $\frac{1}{2}(r - 1 - \log r)$ grows linearly in $r$ and only logarithmically in $1/r$, so understating the spectral density at the seasonal peaks costs more than overstating it elsewhere; {doc}`likelihood_var` makes the same observation about shock variances. + +At $\rho^* = 0.62$ the projection's spectral density at frequency zero is about 28 percent of the spectral density of $y_t$. + +### Deleting seasonal bands + +{cite:t}`HansenSargent1993` describe what they call ideal seasonal adjustment. + +Let $K$ be the set of frequencies outside bands around the seasonal frequencies, and let $1_K(\omega)$ equal one for $\omega \in K$ and zero otherwise; Hansen and Sargent write $C(\omega)$ for this indicator. + +They replace {eq}`ae_hs_criterion` by + +$$ +A(\delta) = \frac{1}{2\pi} \int_{-\pi}^{\pi} 1_K(\omega) \left\{ \log \det G(\omega, \delta) + \operatorname{trace}\left[ G(\omega, \delta)^{-1} F(\omega) \right] \right\} d\omega ++ [\nu - \mu(\delta)]^\top G(0, \delta)^{-1} [\nu - \mu(\delta)] . +$$ (ae_hs_ideal) + +With the seasonal bands deleted, the econometrician projects the part of the process that lies outside the bands onto the part of the model that lies outside them. + +The divergence rate restricted to $K$ is at most the full divergence rate, because the information inequality makes every deleted term nonnegative. + +If, for some $\delta_0$, the model matches $F$ outside the seasonal bands and matches the mean, $\mu(\delta_0) = \nu$, then $\delta_0$ is among the minimizers of {eq}`ae_hs_ideal`, whatever the model does inside the bands. + +Hansen and Sargent add that omitting frequencies might hinder identification by introducing additional minimizers, and that, when the model remains identified, omitting frequencies will typically increase the asymptotic variance of the estimator unless the seasonal frequencies are contaminated by measurement error. + +When the model is correctly specified at all frequencies, the estimator that uses all frequencies is efficient, and by Hausman's lemma the increase in asymptotic variance equals the variance of the difference between the two estimators. + +{doc}`specification_tests` turns that difference into a test. + +In our example, no first-order autoregression matches the spectral density of $y_t$ outside the bands, because the seasonal component has some power at every frequency. + +But about 94 percent of the seasonal component's variance lies in bands of width $\pi/8$ around the seasonal frequencies. + +```{code-cell} ipython3 +def seasonal_keep(Δ): + """True outside bands of width Δ centered on π/2, π, and 3π/2.""" + def dist(c): + return np.minimum(np.abs(ω - c), 2 * np.pi - np.abs(ω - c)) + inside = ((dist(np.pi / 2) < Δ / 2) | (dist(np.pi) < Δ / 2) + | (dist(3 * np.pi / 2) < Δ / 2)) + return ~inside + + +keep_8 = seasonal_keep(np.pi / 8) +print(f"share of the seasonal variance in bands of width π/8: " + f"{1 - np.mean(f_s * keep_8) / np.mean(f_s):.2f}") +print(f"divergence rate of the AR(1) projection: all frequencies " + f"{kl_rate(f_y, g_full):.4f}, outside the bands " + f"{kl_rate(f_y, g_full, keep_8):.4f}") +for Δ in (np.pi / 16, np.pi / 8, np.pi / 4): + a_K, _ = ar_projection(f_y, 1, seasonal_keep(Δ)) + print(f"band width {Δ / np.pi:.4f}π: ρ* = {a_K[0]:.4f}") +``` + +Deleting bands of width $\pi/8$ raises $\rho^*$ from $0.62$ to $0.87$. + +The remaining gap between $0.87$ and $0.9$ comes from seasonal power that lies outside the deleted bands, and it shrinks as the bands widen. + +### Filtering + +Let $c(L)$ be a filter whose frequency response $c(e^{-i\omega})$ never equals zero. + +Filtering the data by $c(L)$ multiplies $f$ by $|c(e^{-i\omega})|^2$, and filtering the model by $c(L)$ multiplies $g$ by the same factor. + +The ratio $f/g$ at each frequency is unchanged, so filtering the data and the model by the same invertible filter leaves the divergence rate {eq}`ae_kl_rate` and the projection unchanged. + +Two other operations change the projection. + +* **Deleting frequencies**, as in {eq}`ae_hs_ideal`, removes the bands from the criterion and leaves the other frequencies unchanged. In a regression, filtering both variables with a filter that is zero in the bands and one elsewhere is equivalent to deleting the bands. That filter is not invertible, so the invariance argument does not apply. +* **Filtering the data but not the model** replaces $f$ by $|c(e^{-i\omega})|^2 f$ and leaves $g$ alone, so the econometrician projects a different process onto the same model. + +The code below confirms the invariance and computes the effect of filtering the data alone by $c(L) = 1 - 0.5L$. + +```{code-cell} ipython3 +c2 = np.abs(1 - 0.5 * z)**2 +print(f"D(f || g) = {kl_rate(f_y, g_full):.6f}, " + f"D(|c|²f || |c|²g) = {kl_rate(c2 * f_y, c2 * g_full):.6f}") +a_c, _ = ar_projection(c2 * f_y, 1) +print(f"AR(1) projection of the data filtered by 1 - 0.5L: ρ* = {a_c[0]:.4f}") +print(f"share of the filtered variance from the seasonal component: " + f"{np.mean(c2 * f_s) / np.mean(c2 * f_y):.2f}") +``` + +The filter multiplies $f$ by $|1 - 0.5 e^{-i\omega}|^2 = 1.25 - \cos\omega$. + +It cuts the spectral density at frequency zero, where $x_t$ has most of its power, to one quarter, and it multiplies the spectral density at the seasonal peak $\pi$ by $2.25$. + +The seasonal component, whose first-order autocorrelation is negative, then accounts for more than half of the variance of the filtered series, and the AR(1) projection of the filtered series has $\rho^* = -0.08$. + +(ae_lag_section)= +## Distributed lags + +### Least squares as weighted projection + +Let + +$$ +y_t = \sum_{s=-\infty}^{\infty} b_s x_{t-s} + u_t , +$$ (ae_lag) + +where $\{x_t\}$ and $\{u_t\}$ are stationary and $u_t$ is uncorrelated with $x_{t-s}$ for every $s$. + +Write $\tilde b(\omega) = \sum_s b_s e^{-i\omega s}$ for the Fourier transform of the lag distribution and $S_x$ for the spectral density of $x$. + +An econometrician estimates the lag distribution by least squares, subject to constraints such as a finite length or a parametric form. + +In large samples the constrained estimate $\hat b$ converges to the lag distribution $d$ that minimizes + +$$ +E\left[ \left( y_t - \sum_s d_s x_{t-s} \right)^2 \right] += \frac{1}{2\pi} \int_{-\pi}^{\pi} S_x(\omega) \left| \tilde b(\omega) - \tilde d(\omega) \right|^2 d\omega + E[u_t^2] +$$ (ae_sims_criterion) + +over the lag distributions that satisfy the constraints. + +Least squares is the maximum likelihood estimator for the Gaussian model in which $y_t$, given the path of $x$, has mean $\sum_s d_s x_{t-s}$ and serially uncorrelated deviations with variance $\sigma^2$. + +Minimizing the KL divergence rate of the true conditional distribution from this model over $\sigma^2$ leaves one half the logarithm of the mean squared error {eq}`ae_sims_criterion`, plus a term that does not depend on the lag distribution $d$. + +The constrained least squares estimator therefore converges to the m-projection of the true conditional distribution onto the constrained model. + +The spectral density $S_x$ weights the projection: errors in $\tilde d$ cost most at the frequencies at which $x$ has most of its power. + +### Sampling continuous-time lags + +{cite:t}`Sims1971` studies a continuous-time distributed lag $y(t) = \int b(s) x(t - s) \, ds + u(t)$ observed at integer dates $t$. + +He uses the Fourier transform $\tilde b(\omega) = \int e^{-i\omega t} b(t) \, dt$ and the spectral density $S_x$ of the continuous-time process $x$, both defined on the whole real line. + +Sampling at integer dates makes the frequencies $\omega, \omega \pm 2\pi, \omega \pm 4\pi, \ldots$ indistinguishable, a phenomenon called aliasing. + +The least squares regression of the sampled $Y_t = y(t)$ on current, past, and future values of the sampled $X_t = x(t)$ has the discrete-time lag distribution $B$ whose Fourier transform is + +$$ +\tilde B(\omega) = \frac{\sum_{k=-\infty}^{\infty} S_x(\omega + 2\pi k) \, \tilde b(\omega + 2\pi k)}{\sum_{k=-\infty}^{\infty} S_x(\omega + 2\pi k)} . +$$ (ae_folding) + +In Sims's words, "$\tilde B(\omega)$ is a weighted average of $\tilde b(\omega + 2k\pi)$." + +By the argument of the preceding subsection, $B$ is the m-projection of the true conditional distribution of the sampled $Y$ onto the discrete-time distributed lag models, and the weights in {eq}`ae_folding` are the values of $S_x$ that sampling folds onto frequency $\omega$. + +An econometrician who estimates $B$ and interprets it as the continuous-time lag distribution $b$ makes the approximation error $B - b$. + +Sims's Table I reports $B$ for $b(t) = e^{-0.5t}$, $t \geq 0$. + +Its column (1) is $b(t)$, and its columns (2) through (5) correspond to four assumptions about $x$, of which we reproduce three: + +* column (2): the autocovariance function of $x$ is linear between integer dates, which makes $B(t) = \int b(s) \max(1 - |t - s|, 0) \, ds$; +* column (3): $x$ has the autocovariance function $e^{-0.5|t|}$ and spectral density $S_x(\omega) = 2 r / (r^2 + \omega^2)$ with $r = 0.5$; +* column (5): $S_x$ is positive on $(-\pi, \pi)$ and zero outside it, which makes $\tilde B(\omega) = \tilde b(\omega)$ on $(-\pi, \pi)$. + +In column (4), Sims averages the process of column (3) over each unit interval before sampling it. + +```{code-cell} ipython3 +def sampled_lag(b_ft, S_x, t_vals, K=400, n=512): + """Discrete lag B(t) of formula (ae_folding), by summing over aliases.""" + w = -np.pi + 2 * np.pi * (np.arange(n) + 0.5) / n + W = w[None, :] + 2 * np.pi * np.arange(-K, K + 1)[:, None] + B_ft = (S_x(W) * b_ft(W)).sum(axis=0) / S_x(W).sum(axis=0) + return np.array([np.mean(B_ft * np.exp(1j * w * t)).real for t in t_vals]) + + +def band_limited_lag(b_ft, t_vals, n=512): + w = -np.pi + 2 * np.pi * (np.arange(n) + 0.5) / n + return np.array([np.mean(b_ft(w) * np.exp(1j * w * t)).real + for t in t_vals]) + + +def triangle_lag(b, t_vals): + return np.array([integrate.quad(lambda s: b(s) * (1 - abs(t - s)), + max(t - 1, 0), max(t + 1, 0))[0] + for t in t_vals]) + + +def print_lag_table(t_vals, *columns): + print(" t b(t) (2) (3) (5)") + for t, *row in zip(t_vals, *columns): + print(f"{t:4d} " + " ".join(f"{np.round(v, 2) + 0.0:6.2f}" for v in row)) + + +t_vals = np.arange(-4, 9) +b_exp = lambda t: np.where(t >= 0, np.exp(-0.5 * np.maximum(t, 0)), 0.0) +b_exp_ft = lambda w: 1 / (0.5 + 1j * w) +S_ou = lambda w: 2 * 0.5 / (0.5**2 + w**2) + +col2 = triangle_lag(b_exp, t_vals) +col3 = sampled_lag(b_exp_ft, S_ou, t_vals) +col5 = band_limited_lag(b_exp_ft, t_vals) +print_lag_table(t_vals, b_exp(t_vals), col2, col3, col5) +``` + +```{code-cell} ipython3 +--- +mystnb: + figure: + caption: A continuous-time lag distribution and two discrete-time lag distributions that least squares estimates from sampled data + name: fig-ae-sampled-lag +--- +t_fine = np.linspace(-4, 8, 600) +fig, ax = plt.subplots() +ax.plot(t_fine, b_exp(t_fine), "k", lw=1.5, label="continuous-time $b(t)$") +ax.plot(t_vals, col3, "o-", label=r"$B(t)$, autocovariance $e^{-0.5|t|}$") +ax.plot(t_vals, col5, "s--", label=r"$B(t)$, $S_x$ zero outside $(-\pi, \pi)$") +ax.axhline(0, color="0.7", lw=0.8) +ax.set_xlabel("$t$") +ax.set_ylabel("lag coefficient") +ax.legend() +plt.show() +``` + +The coefficient $B(0)$ at lag zero is between $0.42$ and $0.45$, while $b(0) = 1$, because the sampled regression assigns to date zero an average of $b$ over nearby dates. + +When $x$ has no power above frequency $\pi$, the one-sided lag $b$ projects onto a two-sided discrete lag with coefficients of alternating sign at negative $t$. + +An econometrician who tested whether the discrete-time lag distribution is one-sided, or who read $B(0)$ as the instantaneous response, would draw wrong conclusions about $b$ from a correctly estimated $B$. + +{ref}`ae_ex_sampling` derives the sign pattern. + +### Seasonal noise in regressors + +{cite:t}`Sims1974` studies the regression {eq}`ae_lag` when both variables contain seasonal noise. + +He lets $y = x * b + u$ and $z = w * c + v$, where $*$ denotes convolution, $v$ is uncorrelated with $w$, the seasonal noises $z$ and $w$ are uncorrelated with $x$ and $u$, and the econometrician observes $y' = y + z$ and $x' = x + w$. + +The least squares regression of $y'$ on all leads and lags of $x'$ has the unconstrained lag distribution $b'$ with + +$$ +\tilde b' = \tilde b \, \frac{S_x}{S_x + S_w} + \tilde c \, \frac{S_w}{S_x + S_w} , +$$ (ae_sims_bias) + +a weighted average of $\tilde b$ and $\tilde c$ whose weights vary with frequency. + +When the noise in $y$ is unrelated to the noise in $x$, so that $c = 0$, $\tilde b'$ is close to $\tilde b$ except at the seasonal frequencies, where $S_w$ is large and $\tilde b'$ falls toward zero. + +{cite:t}`Sims1974` states the large-sample behavior of constrained least squares as his equation (2.7), crediting {cite:t}`Sims1972JASA`: when we estimate the lag distribution "by least squares subject to prior constraints, the estimate $\hat b$ will minimize, subject to the constraints, the quantity" + +$$ +\int_{-\pi}^{\pi} S_{x'}(\omega) \left| \tilde{\hat b}(\omega) - \tilde b'(\omega) \right|^2 d\omega , +$$ + +which is, up to the factor $1/2\pi$ and an additive constant, {eq}`ae_sims_criterion` with $S_{x'} = S_x + S_w$ in place of $S_x$, $\tilde b'$ in place of $\tilde b$, and $\hat b$ in place of $d$. + +The criterion puts heavy weight on fitting $\tilde b'$ at the seasonal frequencies, where $\tilde b'$ is most biased. + +Sims draws the consequence: + +> because $|\tilde{\hat b} - \tilde b'|^2$ at seasonal frequencies is given especially strong weight in the criterion function (2.7), constraints preventing *sharp* peaks or dips in $\tilde{\hat b}$ at seasonals only result in estimates which have *wide* peaks or dips at seasonals, trading relatively more error at values away from the seasonal for a good fit very close to the seasonal. + +Sims considers two true lag distributions: the identity lag, with $b_0 = 1$ and $b_s = 0$ for $s \neq 0$, and the Koyck lag $b_s = 0.9^s$ for $s \geq 0$. + +He sets the autocovariance function of $x$ to $0.9^{|t|}$. + +The seasonal noise $w$ is a moving average of white noise whose weights Sims gives in his footnote 6. + +The weights are the convolution of a filter that averages five values four quarters apart with a filter that subtracts from each value the average of the sixteen surrounding quarters. + +Sims scales $w$ to have one-fourth the variance of $x$. + +The noise has peaks at the seasonal frequencies and no power at frequency zero. + +```{code-cell} ipython3 +# moving average weights of w, lags -16, ..., 16 (Sims 1974, footnote 6) +h1 = np.zeros(17) +h1[8 + 4 * np.arange(-2, 3)] = 1 / 5 +h2 = -np.ones(17) / 16 +h2[8] = 1.0 +h_w = np.convolve(h1, h2) +h_w_ft = sum(h * np.exp(-1j * ω * k) for k, h in zip(range(-16, 17), h_w)) + +S_x74 = (1 - 0.9**2) * ar_spectrum(0.9) # unit variance +S_w74 = np.abs(h_w_ft)**2 +S_w74 = S_w74 * 0.25 / np.mean(S_w74) # one-fourth the variance of x +S_xp74 = S_x74 + S_w74 + + +def lag_from_ft(B_ft, t_vals): + return np.array([np.mean(B_ft * np.exp(1j * ω * t)).real for t in t_vals]) + + +t74 = np.arange(-8, 13) +b_identity_ft = np.ones(n_grid) +b_koyck_ft = 1 / (1 - 0.9 * z) +bp_identity = lag_from_ft(b_identity_ft * S_x74 / S_xp74, t74) +bp_koyck = lag_from_ft(b_koyck_ft * S_x74 / S_xp74, t74) +print(f"unconstrained coefficient at lag zero, identity lag: " + f"{bp_identity[t74 == 0][0]:.2f}") +``` + +```{code-cell} ipython3 +--- +mystnb: + figure: + caption: Spectral densities of the regressor with and without seasonal noise (left), and the lag distributions that unconstrained least squares estimates (right) + name: fig-ae-sims-1974 +--- +fig, axes = plt.subplots(1, 2, figsize=(11, 4)) +ax = axes[0] +ax.plot(ω[half], np.log(S_x74[half]), label="$S_x$") +ax.plot(ω[half], np.log(S_xp74[half]), label="$S_{x'} = S_x + S_w$") +ax.set_xticks(*π_ticks) +ax.set_xlabel(r"$\omega$") +ax.set_ylabel("log spectral density") +ax.legend() + +ax = axes[1] +ax.plot([0], [1.0], "kx", ms=8, label="true identity lag at $t = 0$") +ax.plot(t74, bp_identity, "o-", label="estimated, identity lag") +koyck_t = t74[t74 >= 0] +ax.plot(koyck_t, 0.9**koyck_t, "k+", ms=10, label="true Koyck lag $0.9^t$") +ax.plot(t74, bp_koyck, "s-", label="estimated, Koyck lag") +ax.set_xticks(np.arange(-8, 13, 4)) +ax.set_xlabel("$t$") +ax.set_ylabel("lag coefficient") +ax.legend(loc="lower center", bbox_to_anchor=(0.5, 1.0), ncol=2, fontsize=9, + frameon=False) +plt.tight_layout() +plt.show() +``` + +The seasonal noise leaves the sum of the coefficients unbiased, because the noise has no power at frequency zero. + +It lowers the coefficient at lag zero of the identity lag to about $0.63$, and it adds seasonal ripples to both lag distributions, including coefficients on future values of $x'$. + +{doc}`sargent_surico` uses the same argument: a component with no power at frequency zero leaves the sum of the lag coefficients $h(0) = S_{yz}(0)/S_z(0)$ unchanged. + +The function below solves the large-sample normal equations of a regression of $y'$ on a set of lags of $x'$ in the frequency domain. + +Its optional argument `weight` multiplies the spectral density of $x'$ and the cross spectrum of $y'$ and $x'$ by $|\tilde k(\omega)|^2$, which is the effect of filtering both $y'$ and $x'$ by a filter $k$; {ref}`ae_ex_filter` uses it. + +```{code-cell} ipython3 +def constrained_lag(b_ft, lags, weight=None): + """Large-sample least squares coefficients on x'(t - j), j in lags, + for the true lag with Fourier transform b_ft and c = 0.""" + wt = np.ones(n_grid) if weight is None else weight + M = np.array([[np.mean(wt * S_xp74 * np.cos(ω * (j - k))) for k in lags] + for j in lags]) + m = np.array([np.mean(wt * S_x74 * b_ft * np.exp(1j * ω * j)).real + for j in lags]) + return np.linalg.solve(M, m) + + +print("identity lag, x'(t) only: ", + np.round(constrained_lag(b_identity_ft, [0]), 3)) +print("identity lag, x'(t) and x'(t - 1):", + np.round(constrained_lag(b_identity_ft, [0, 1]), 3)) +``` + +With only $x'(t)$ as a regressor, the coefficient tends to $0.80$, the attenuation factor $1/(1 + 1/4)$ of the classical errors-in-variables model. + +That coefficient is less biased than the unconstrained coefficient $0.63$ at lag zero, but the sum of the coefficients, which the unconstrained regression estimates without bias, falls from $1$ to $0.80$. + +Adding $x'(t-1)$ gives coefficients that tend to $0.58$ and $0.34$, although the true lag distribution puts all its weight on date zero. + +{cite:t}`Sims1974` reports $0.80$, and $0.58$ and $0.31$. + +Our computation, which follows his footnote 6 and formula (2.6), gives $0.34$ for the second coefficient, and the other variants that we have tried give between $0.33$ and $0.34$. + +He writes: + +> If these were estimates of, say, a short-run demand function for labor, the evidence for "short-run increasing returns to scale" would appear very strong, and by keeping the lag distribution short, evidence of the presence of seasonal bias would be suppressed. + +His remedy is to filter both variables with the same filter $k$, which he writes $a$, that removes power near the seasonal frequencies. + +Filtering both variables leaves the unconstrained lag distribution $b'$ unchanged, and it replaces the weight $S_{x'}$ in the constrained criterion by $|\tilde k|^2 S_{x'}$. + +Constrained least squares then fits $\tilde b'$ at nonseasonal frequencies, where $\tilde b'$ is close to $\tilde b$. + +{doc}`sargent_surico` describes the opposite choice of filter. + +Lucas's two-sided moving average with parameter $\beta$ concentrates the weight $|\tilde k|^2 S_x$ near frequency zero. + +A regression of one filtered series on the other with a single coefficient converges to the average of $\tilde b$ weighted by $|\tilde k|^2 S_x$, and that average approaches the sum $\tilde b(0)$ of the lag coefficients as $\beta \to 1$. + +(ae_seasonal_section)= +## Seasonal adjustment in dynamic models + +### Filtering in dynamic systems + +{cite:t}`Sims1993` points out that a complete dynamic system lacks the invariance of the regression of {ref}`ae_lag_section`. + +If $y(t) = A * \varepsilon(t)$ is the moving average representation of a vector process and the econometrician uses the filtered data $c * y$, the moving average operator becomes $c * A$: + +> Thus in contrast to the result in the regression case – where $b$ is unaffected by filtering – for a complete dynamic system the basic estimated parameter $A$ is altered by filtering. + +In a regression, the econometrician models only the conditional distribution of $y$ given $x$. + +Filtering $y$ and $x$ by the same filter multiplies the cross spectrum and the spectrum of $x$ by $|\tilde c|^2$, so $\tilde b = S_{yx}/S_x$ does not change. + +In a dynamic system, the econometrician models the joint distribution of all the variables, whose spectral density matrix is $\tilde A \tilde A^*$, and filtering replaces $\tilde A$ by $\tilde c \tilde A$. + +The cross-equation restrictions of a rational expectations model tie the coefficients of agents' decision rules to the parameters of the processes that agents forecast, and so they tie the parameters of preferences and technology to the whole operator $A$. + +Fitting an unfiltered model to filtered data therefore moves the estimates of those parameters. + +Filtering the model as well would restore the invariance described in {ref}`ae_ar_section` when the frequency response of the filter vanishes only at isolated frequencies, as {ref}`ae_ex_invariance` shows. + +Sims's econometrician instead treats the filtered data as if they were unadjusted. + +{cite:t}`HansenSargent1993` compare the operations of {ref}`ae_ar_section` in terms of their criterion {eq}`ae_hs_criterion`. + +In the formulation that they attribute to Sims, the econometrician filters the data but not the model, so the spectral density $F^a(\omega) = c(e^{-i\omega}) F(\omega) c(e^{i\omega})^\top$ of the filtered data replaces $F(\omega)$, and $G(\omega, \delta)$ stays as it was. + +In ideal seasonal adjustment {eq}`ae_hs_ideal`, the econometrician deletes the seasonal bands. + +Hansen and Sargent state Sims's argument for adjusted data in terms of the second term of {eq}`ae_hs_criterion`: + +> The argument is that the term $A_2(\delta) = (1/2\pi)\int_{-\pi}^{\pi} \operatorname{trace}[G(\omega, \delta)^{-1} F^a(\omega)] \, d\omega$ assigns the most weight to approximation error at frequencies at which $F^a(\omega)$ [or $F(\omega)$, if unadjusted data are used] is large. Since $F(\omega)$ is large at precisely those frequencies where $G(\omega, \delta)$ is most misspecified, the effects of misspecification on the estimates of the parameters of preferences and technologies will be diminished by weighting by $F^a(\omega)$ rather than $F(\omega)$. + +They add in a footnote that seasonal adjustment has an efficiency cost: the overidentifying restrictions that a rational expectations model imposes across equations and across frequencies are most informative at the high-power seasonal frequencies that adjustment suppresses. + +{cite:t}`Sims1993` describes the limit of an autoregression fitted to filtered data. + +The limiting coefficients minimize a quadratic distance between the model's one-step-ahead prediction filter and that of the filtered data, weighted by the spectral density of the filtered data. + +Suppose that the parameterization can match the filtered data's prediction filter closely outside the seasonal bands but cannot vary sharply over intervals as short as the bands, and that the bands are narrow. + +Then, as adjustment drives the spectral density of the filtered data toward zero in the bands, the best-fitting filter fits well outside the bands and interpolates across them. + +Sims shows that fitting a filter that is arbitrary in the bands to data with near-zero power there inflates the one-step-ahead forecast error by "one plus the ratio of the aggregate length of the seasonal bands to $2\pi$." + +### Hansen and Sargent's experiment + +{cite:t}`HansenSargent1993` study a linear-quadratic version of a stochastic growth model in which a planner chooses consumption, investment, and capital. + +In the true model, the productivity parameter $\gamma_{s(t)}$ varies periodically with the quarter $s(t)$, taking the values $0.13$, $0.1$, $0.1$, and $0.08$; the adjustment cost parameter is $\phi_1 = 0.3$; and the endowment shock $d_t$ follows a first-order autoregression with coefficient $0.4$. + +The econometrician fits a model that is correct in all respects except that it has a constant productivity parameter $\gamma$. + +The econometrician imposes the true values of all the other parameters and estimates $\gamma$, $\phi_1$, and the coefficients $a_1$, $a_4$, and $a_5$ of an autoregression for the endowment shock with lags $1$, $4$, and $5$. + +Hansen and Sargent apply {eq}`ae_hs_criterion` to the process that stacks the four observations of each year, so the mean $\nu$ contains the four seasonal means. + +A model with a constant $\gamma$ implies the same mean in every quarter. + +Their equation (4.11) writes the mean term as a sum over the frequencies $0$, $\pi/2$, $\pi$, and $3\pi/2$ of the Fourier components of the errors in the seasonal means, each divided by the model's spectral density of $y_t$ at that frequency. + +Hansen and Sargent compare three kinds of data: + +* unadjusted data, for which the criterion is {eq}`ae_hs_criterion`; +* data from which the econometrician has removed seasonal means by regressing on seasonal dummies, for which the criterion drops the mean term of {eq}`ae_hs_criterion`; and +* ideally adjusted data, for which the criterion deletes the seasonal bands from the first two terms and drops the mean term. + +Their Table 1 reports the minimizers of the three criteria: + +| parameter | seasonally unadjusted | seasonal means removed | seasonally adjusted | truth | +|---|---|---|---|---| +| $\gamma$ | 0.0996 | 0.1030 | 0.1025 | $\gamma_{s(t)}$ | +| $\phi_1$ | 0.4132 | 0.2854 | 0.3007 | 0.3000 | +| $a_1$ | 0.931 | 0.3250 | 0.3987 | 0.4000 | +| $a_4$ | 0.4383 | 0.1598 | −0.0003 | 0.000 | +| $a_5$ | −0.4298 | −0.1261 | −0.0005 | 0.000 | + +With unadjusted data, the estimates of $a_1$, $a_4$, and $a_5$ put into the endowment process the seasonality that periodic productivity generates, and the estimate of $\phi_1$ overstates the adjustment cost. + +With seasonal means removed, the estimates of $a_4$ and $a_5$ still put some seasonality into the endowment process, and the estimates of $\phi_1$ and $a_1$ fall below the truth. + +Hansen and Sargent explain the estimates from data with seasonal means removed, where $c_t$ and $i_t$ are consumption and investment: + +> In order to diminish the errors at the seasonal bands, the estimates put some seasonality into $\{c_t, i_t\}$ the only way that the model permits, namely, through the endowment process. Doing that helps the model 'match' at the seasonal frequencies at the cost of worse fit at the nonseasonal frequencies. + +Hansen and Sargent attribute the larger errors with unadjusted data, compared with data with seasonal means removed, to the mean term. + +The model can shrink that term only by raising its spectral density at the seasonal frequencies, which the larger estimates of $a_4$ and $a_5$ do. + +With ideally adjusted data, the estimates of $\phi_1$ and of the endowment process are close to the truth, and the estimate $0.1025$ of $\gamma$ equals the average $(0.13 + 0.1 + 0.1 + 0.08)/4$ of the quarterly productivity parameters. + +### Sims's permanent income examples + +{cite:t}`Sims1993` uses a permanent income model to give one example in which adjusted data reduce the error and one in which they increase it. + +A consumer with quadratic utility and discount factor $\beta$ faces a gross interest rate $\beta^{-1}$, so that consumption $C_t$ is a martingale and + +$$ +\Delta C_t = (1 - \beta) \sum_{j=0}^{\infty} \beta^j (E_t - E_{t-1}) Y_{t+j} , +$$ + +where $Y_t$ is income. + +Income is the sum $Y_t = Y^N_t + Y^S_t$ of a nonseasonal component + +$$ +Y^N_t = 1.8 \, Y^N_{t-1} - 0.81 \, Y^N_{t-2} + \varepsilon_t , +$$ + +normalized to have unit variance, and a deterministic seasonal component that repeats the pattern $\sqrt{2}, 0, -\sqrt{2}, 0$. + +The deterministic seasonal is perfectly predictable, so it never revises expected income and does not affect $\Delta C_t$. + +If $Y^N_t = \psi(L) \varepsilon_t$, then $\Delta C_t = (1 - \beta)\psi(\beta) \varepsilon_t$, and the coefficient of a regression of the income innovation $\varepsilon_t$ on $\Delta C_t$ is $1/[(1 - \beta)\psi(\beta)]$. + +{doc}`lq_permanent_income` derives this formula as {eq}`eq:sprob13`, with $d$ in place of $\psi$. + +Sims does not state $\beta$; we use $\beta = 0.95$, the value implied by his coefficient of $20$ in his second example below. + +With $\psi(L) = (1 - 0.9L)^{-2}$, the coefficient is $(1 - 0.9\beta)^2 / (1 - \beta) = 0.4205$, the value that Sims reports. + +An econometrician who fits an autoregression $a(L) Y_t = e_t$ to income and believes the permanent income model computes the coefficient $a(\beta)/(1 - \beta)$. + +Sims first supposes that the econometrician fits a ninth-order autoregression to unadjusted data, with no seasonal dummies. + +The large-sample autoregression is the m-projection of the income process onto the ninth-order autoregressions, so it solves the Yule–Walker equations with the autocovariances $R^N(s) + R^S(s)$, where $R^N$ is the autocovariance function of $Y^N$ and $R^S(s) = \cos(\pi s/2)$ is that of the seasonal pattern. + +```{code-cell} ipython3 +β = 0.95 +fN_ar2 = ar_spectrum([1.8, -0.81]) +fN_ar2 = fN_ar2 / np.mean(fN_ar2) # unit variance + + +def seasonal_autocov(n_lags, gain2=1.0): + """R^S(s) = cos(π s / 2), times the squared gain of a filter at π/2.""" + return gain2 * np.cos(np.pi * np.arange(n_lags + 1) / 2) + + +def implied_coefficient(a): + """Coefficient of ε on ΔC implied by the autoregression a(L) Y = e.""" + a_β = 1 - sum(a_j * β**(j + 1) for j, a_j in enumerate(a)) + return a_β / (1 - β) + + +a9 = yule_walker(autocov(fN_ar2, 9) + seasonal_autocov(9), 9) +print("AR(9) coefficients:", np.round(a9, 4)) +print(f"true coefficient {(1 - 0.9 * β)**2 / (1 - β):.4f}, " + f"implied by the AR(9): {implied_coefficient(a9):.4f}") +``` + +Our projection gives the coefficients of Sims's equation (17), except for the coefficient on $Y_{t-8}$: we obtain $-0.2084$, and Sims prints $+0.2084$. + +Only the negative sign reproduces his implied coefficient of $0.4925$, a bias factor of $1.17$. + +The ninth-order autoregression forecasts most of the deterministic seasonal, but it attributes part of the innovation in income to a stochastic seasonal component, and the permanent income model then implies that consumption responds less to an income innovation than it actually does. + +Sims observes that the regression of the autoregression's forecast errors on $\Delta C_t$ in the data still recovers $0.4205$. + +The autoregression's forecast error is the true innovation plus a component orthogonal to it, and $\Delta C_t$ is proportional to the true innovation. + +An econometrician who used the ninth-order autoregression would therefore conclude, wrongly, that consumption reacts to income more strongly than the theory implies. + +Sims next adjusts both $C$ and $Y$ by subtracting the seasonal component that the filter $\kappa(L)\kappa(L^{-1})$ extracts, where + +$$ +\kappa(L) = 0.25 \, \frac{1 - L^{16}}{1 - L^4} - 0.0625 \, \frac{1 - L^{16}}{1 - L} +$$ + +is the filter that he writes $F(L)$, and he treats the adjusted series as if they were unadjusted data. + +The adjusted data have spectral density $(1 - |\kappa(e^{-i\omega})|^2)^2$ times that of the unadjusted data. + +Sims reports that a second-order autoregression fitted to adjusted income gives a bias factor of only $1.0137$. + +With the filter as we read it, we obtain a bias factor of $0.893$ for that computation, and other readings that we tried do not reproduce $1.0137$ either; the same reading gives $17.08$ for his second example below, within $0.02$ of his $17.06$. + +We add a computation that Sims does not report: deleting the seasonal bands from the criterion and fitting a second-order autoregression recovers the truth, because $Y^N$ is a second-order autoregression and the deterministic seasonal has all its power at frequency $\pi/2$. + +```{code-cell} ipython3 +κ_ft = (0.25 * sum(z**(4 * k) for k in range(4)) + - 0.0625 * sum(z**k for k in range(16))) +adjust2 = (1 - np.abs(κ_ft)**2)**2 # squared gain of 1 - κκ* +z_q = np.exp(-1j * np.pi / 2) # the seasonal frequency π/2 +κ_q = (0.25 * sum(z_q**(4 * k) for k in range(4)) + - 0.0625 * sum(z_q**k for k in range(16))) +gain2_q = (1 - np.abs(κ_q)**2)**2 # zero: the seasonal is removed + +a2_adj = yule_walker(autocov(fN_ar2 * adjust2, 2) + + seasonal_autocov(2, gain2_q), 2) +print(f"AR(2), adjusted data: implied coefficient " + f"{implied_coefficient(a2_adj):.4f}, bias factor " + f"{implied_coefficient(a2_adj) / 0.4205:.3f}") + +keep_B = seasonal_keep(np.pi / 8) +a2_B, _ = ar_projection(fN_ar2, 2, keep_B) # the seasonal lies in a deleted band +print("AR(2), seasonal bands deleted:", np.round(a2_B, 4), + f" implied coefficient {implied_coefficient(a2_B):.4f}") +``` + +In Sims's second example, an econometrician who uses adjusted data does worse than one who uses unadjusted data. + +Sims replaces $Y^N$ by unit-variance white noise, for which the true coefficient is $1/(1 - \beta) = 20$, and he reports that a ninth-order autoregression fitted to unadjusted data implies a coefficient of $20.62$ and that adjusted data imply $17.06$. + +Sims does not state the order of the autoregression that he fits to adjusted data in this example; we fit a second-order autoregression, as in his first example, and also report a ninth-order autoregression. + +```{code-cell} ipython3 +f_white = np.ones(n_grid) +a9_w = yule_walker(autocov(f_white, 9) + seasonal_autocov(9), 9) +a2_adj_w = yule_walker(autocov(f_white * adjust2, 2) + + seasonal_autocov(2, gain2_q), 2) +a9_adj_w = yule_walker(autocov(f_white * adjust2, 9) + + seasonal_autocov(9, gain2_q), 9) +a2_band_w, _ = ar_projection(f_white, 2, keep_B) +print(f"true coefficient: {1 / (1 - β):.2f}") +print(f"AR(9), unadjusted data: {implied_coefficient(a9_w):.2f}") +print(f"AR(2), data adjusted with κκ*: {implied_coefficient(a2_adj_w):.2f}") +print(f"AR(9), data adjusted with κκ*: {implied_coefficient(a9_adj_w):.2f}") +print(f"AR(2), seasonal bands deleted: {implied_coefficient(a2_band_w):.2f}") +γ_adj = autocov(f_white * adjust2, 4) +print("autocorrelations of adjusted white noise, lags 1 to 4:", + np.round(γ_adj[1:] / γ_adj[0], 3)) +print("AR(2) coefficients, adjusted data:", np.round(a2_adj_w, 3)) +``` + +Our computation gives $20.64$ for unadjusted data, close to Sims's $20.62$. + +Sims's adjustment filter removes the seasonal, but it also reduces the spectral density of the data in neighborhoods of the seasonal frequencies, so the econometrician fits the second-order autoregression to a process whose spectral density has dips that white noise does not have. + +Adjusted white noise has positive autocorrelations, between $0.08$ and $0.10$ at lags 1 to 3, so the second-order autoregression has positive coefficients, $0.076$ and $0.082$, and $a(\beta) = 0.854$. + +The econometrician attributes persistence to income innovations that have none, and infers that consumption responds more to an income innovation than it does. + +Deleting the seasonal bands from the criterion leaves the other frequencies unchanged, and the second-order autoregression fitted outside the bands has coefficients equal to zero, which imply the true coefficient $20$. + +In {ref}`ae_ex_invariance`, the econometrician filters the model as well as the data. + +Sims concludes: + +> Use of unadjusted data and a correctly specified model of seasonal variation is always the best option. But treating seasonality casually, as a 'nuisance' component of the model, can lead to worse errors than those produced by use of adjusted data. + +## Concluding remarks + +The maximum likelihood estimator of a misspecified time series model converges to the m-projection of the true process onto the model. + +The KL divergence rate {eq}`ae_kl_rate` charges each frequency according to the ratio of the data's spectral density to the model's; in a distributed-lag regression, the spectral density of the regressor weights the error in the lag distribution at each frequency, as in {eq}`ae_sims_criterion`. + +A first-order autoregression fitted to a series whose nonseasonal component has coefficient $0.9$ and whose seasonal component has one quarter of the variance of the nonseasonal component has $\rho^* = 0.62$; deleting seasonal bands of width $\pi/8$ raises $\rho^*$ to $0.87$. + +Filtering the data and the model with the same invertible filter leaves the projection unchanged; deleting frequency bands, or filtering the data alone, changes it. + +In the example of {cite:t}`Sims1971`, least squares on sampled data puts a coefficient of about $0.43$ at lag zero, where the continuous-time lag distribution has $1$. + +In the example of {cite:t}`Sims1974`, seasonal noise in the regressor, together with a constraint that keeps the estimated lag distribution short, produces coefficients that, read as a short-run demand function for labor, would suggest short-run increasing returns to scale. + +In the first example of {cite:t}`Sims1993`, a misspecified seasonal model of unadjusted data understates the response of consumption to income by a factor of $1.17$; in his second example, adjusted data produce a larger error than unadjusted data. + +{doc}`phillips_misspecified` describes an equilibrium in which agents' beliefs are the m-projection, in the sense of {eq}`ae_hs_criterion`, of the process that those beliefs generate; {cite:t}`EspondaPouzo2016` call an equilibrium of this kind a Berk–Nash equilibrium. + +{doc}`specification_tests` describes tests that compare two projections. + +## Exercises + +```{exercise} +:label: ae_ex_sampling + +Table III of {cite:t}`Sims1971` reports the discrete-time lag distributions $B$ for the hump-shaped continuous-time lag distribution $b(t) = 4 t e^{-2t}$, $t \geq 0$. + +1. Show that $\tilde b(\omega) = 4/(2 + i\omega)^2$. +2. Use the functions `triangle_lag`, `sampled_lag`, and `band_limited_lag` to compute columns (2), (3), and (5) of the table for $t = -4, \ldots, 8$, and compare $B(0)$ and $B(1)$ with $b(0)$ and $b(1)$. +3. In column (5), $B(t) = \int b(s) \frac{\sin \pi (t - s)}{\pi (t - s)} \, ds$. Show that at an integer $t$, $B(t) = (-1)^t \int b(s) \frac{\sin \pi s}{\pi (s - t)} \, ds$, and use this formula to predict the signs of $B(t)$ at negative $t$. +``` + +```{solution-start} ae_ex_sampling +:class: dropdown +``` + +Here is one solution. + +For part 1, $\tilde b(\omega) = 4 \int_0^\infty t e^{-(2 + i\omega) t} \, dt = 4 / (2 + i\omega)^2$. + +```{code-cell} ipython3 +b_hump = lambda t: np.where(t >= 0, 4 * t * np.exp(-2 * t), 0.0) +b_hump_ft = lambda w: 4 / (2 + 1j * w)**2 + +print_lag_table(t_vals, b_hump(t_vals), triangle_lag(b_hump, t_vals), + sampled_lag(b_hump_ft, S_ou, t_vals), + band_limited_lag(b_hump_ft, t_vals)) +``` + +The computed columns agree with Sims's Table III, whose heading prints the lag distribution as $\exp(-2t)$, while its figure and its column (1) correspond to $4t\exp(-2t)$. + +The continuous-time lag is zero at $t = 0$ and peaks at $t = 0.5$, between two sampling dates. + +In columns (2) and (3), $B(0) \approx 0.27$ although $b(0) = 0$, and $B(1) \approx 0.5$ is close to $b(1) = 0.54$; in column (5), $B(0) = 0.29$ and $B(1) = 0.60$. + +Least squares on sampled data assigns part of the response that occurs between dates $0$ and $1$ to date $0$. + +For part 3, at an integer $t$, $\sin \pi (t - s) = (-1)^{t+1} \sin \pi s$, so $B(t) = (-1)^t \int b(s) \frac{\sin \pi s}{\pi (s - t)} \, ds$. + +For $t < 0$, the factor $1/(s - t)$ is positive for every $s \geq 0$. + +For large $|t|$, the integral is approximately $\frac{1}{\pi |t|} \int b(s) \sin \pi s \, ds = \frac{\operatorname{Im} \tilde b(-\pi)}{\pi |t|}$, and $\operatorname{Im} \tilde b(-\pi) = \operatorname{Im} \, 4/(2 - i\pi)^2 > 0$. + +So $B(t)$ has the sign of $(-1)^t$ at negative $t$: positive at $t = -2$ and $-4$ and negative at $t = -1$ and $-3$, as the table shows. + +```{code-cell} ipython3 +print(f"Im b(-π) = {b_hump_ft(-np.pi).imag:.3f}") +exact = integrate.quad(lambda s: b_hump(s) * np.sin(np.pi * s) / (np.pi * (s + 1)), + 0, 40, limit=200)[0] +print(f"t = -1: integral {exact:.3f}, " + f"large-|t| approximation {b_hump_ft(-np.pi).imag / np.pi:.3f}") +``` + +The approximation is rough at $t = -1$, but the sign is right there too. + +```{solution-end} +``` + +```{exercise} +:label: ae_ex_filter + +Return to Sims's 1974 example with the identity lag distribution and $c = 0$. + +Suppose that the econometrician filters both $y'$ and $x'$ with an ideal seasonal adjustment filter $k$ whose frequency response is zero in bands of width $\Delta$ around $\pi/2$ and $\pi$ (and in the symmetric band around $-\pi/2$) and one elsewhere. Let $y'' = k * y'$ and $x'' = k * x'$ be the filtered series. + +1. Explain why the large-sample least squares coefficients of a regression of $y''$ on lags of $x''$ satisfy the normal equations that `constrained_lag` solves when its argument `weight` is $|\tilde k|^2$. +2. Compute the large-sample coefficient on $x''(t)$ alone, and the coefficients on $x''(t)$ and $x''(t-1)$, for $\Delta \in \{\pi/16, \pi/8, \pi/4\}$. Compare them with the coefficients $0.80$ and $(0.58, 0.34)$ for unfiltered data and with the true values $1$ and $(1, 0)$. +``` + +```{solution-start} ae_ex_filter +:class: dropdown +``` + +Here is one solution. + +For part 1, filtering both variables by $k$ multiplies the spectral density of $x'$ and the cross spectrum of $y'$ and $x'$ by $|\tilde k|^2$. + +The large-sample moment matrices of the regression of $y''$ on lags of $x''$ are therefore those of the unfiltered regression with both spectra weighted by $|\tilde k|^2$. + +Equivalently, constrained least squares minimizes {eq}`ae_sims_criterion` with $\tilde b'$ in place of $\tilde b$ and the weight $|\tilde k|^2 S_{x'}$ in place of $S_x$. + +```{code-cell} ipython3 +for Δ in (np.pi / 16, np.pi / 8, np.pi / 4): + k2 = seasonal_keep(Δ).astype(float) + one = constrained_lag(b_identity_ft, [0], k2) + two = constrained_lag(b_identity_ft, [0, 1], k2) + share_out = np.mean(S_w74 * seasonal_keep(Δ)) / np.mean(S_w74) + print(f"Δ = {Δ / np.pi:.4f}π: x''(t) alone {one.round(3)}, " + f"with x''(t-1) {two.round(3)}; share of Var(w) outside the bands " + f"{share_out:.2f}") +``` + +Filtering moves the coefficients toward the truth, and wider bands move them further. + +With $\Delta = \pi/8$, the band width that Sims recommends for quarterly data, the coefficient on $x''(t)$ alone is $0.95$ and the pair is $(0.80, 0.18)$, against $0.80$ and $(0.58, 0.34)$ for unfiltered data. + +The filter removes the frequencies at which the seasonal noise $w$ has most of its power, so the remaining variation in $x''$ is mostly variation in $x$, and the errors-in-variables bias falls. + +The bias does not disappear, because the noise $w$ of Sims's example has power outside the seasonal bands: about 19 percent of its variance lies outside bands of width $\pi/8$. + +Sims's footnote 6 puts the width of the seasonal peaks of $w$ at about $\pi/5$, and he recommends a band wider than the widest seasonal peak in the spectral density of $x'$. + +With $\Delta = \pi/4$, 12 percent of the variance of $w$ lies outside the bands. + +```{solution-end} +``` + +```{exercise} +:label: ae_ex_invariance + +In the version of Sims's second permanent income example computed above, the econometrician filtered the data with $1 - \kappa(L)\kappa(L^{-1})$ but fitted a second-order autoregression as if the data were unadjusted. + +1. Suppose instead that the econometrician applies the same filter to the model, so that the model's spectral density is $(1 - |\kappa|^2)^2 \sigma^2/|a(e^{-i\omega})|^2$. Write the divergence rate between the filtered data and the filtered model, and explain why its minimizer over $(a, \sigma^2)$ is the minimizer for the unfiltered data without the seasonal component. +2. Confirm numerically that the minimizer has $a = 0$ and implies the coefficient $20$. +``` + +```{solution-start} ae_ex_invariance +:class: dropdown +``` + +Here is one solution. + +For part 1, the filter removes the deterministic seasonal, so the filtered data have spectral density $(1 - |\kappa|^2)^2 f$ with $f = 1$. + +With $g = \sigma^2/|a(e^{-i\omega})|^2$, the divergence rate of the filtered data from the filtered model is + +$$ +\frac{1}{4\pi} \int_{-\pi}^{\pi} \left[ \frac{(1 - |\kappa|^2)^2 f}{(1 - |\kappa|^2)^2 g} - 1 - \log \frac{(1 - |\kappa|^2)^2 f}{(1 - |\kappa|^2)^2 g} \right] d\omega . +$$ + +At every frequency at which $1 - |\kappa|^2 \neq 0$, the ratio inside the brackets is $f/g$, as in the invariance argument of {ref}`ae_ar_section`. + +The squared gain $(1 - |\kappa|^2)^2$ vanishes only at finitely many frequencies: the seasonal frequencies $\pm\pi/2$ and $\pi$, and two frequencies near $\pm 0.485\pi$ at which $|\kappa|$ crosses one. + +A finite set has measure zero, so the divergence rate equals $D(f \| g)$ for white noise $f$, which is zero at $a = 0$ and $\sigma^2 = 1$. + +```{code-cell} ipython3 +def filtered_criterion(θ, f, gain2): + """Divergence rate of the filtered data from the filtered AR(2) model.""" + a, σ2 = pacf_to_ar(np.tanh(θ[:2])), np.exp(θ[2]) + return kl_rate(gain2 * f, gain2 * ar_spectrum(a, σ2)) + + +res = minimize(filtered_criterion, [0.3, -0.2, 0.0], args=(f_white, adjust2), + method="Nelder-Mead", options={"xatol": 1e-10, "fatol": 1e-14}) +a_fm = pacf_to_ar(np.tanh(res.x[:2])) +print("AR(2) coefficients:", np.round(a_fm, 6) + 0.0, + f" implied coefficient {implied_coefficient(a_fm):.3f}") +``` + +Filtering the model as well as the data removes the bias that filtering the data alone produced. + +```{solution-end} +``` diff --git a/lectures/divergence_measures.md b/lectures/divergence_measures.md index 791a1bba4..d5e7b4f95 100644 --- a/lectures/divergence_measures.md +++ b/lectures/divergence_measures.md @@ -692,6 +692,8 @@ The expected score is the negative gradient of the KL divergence, and it vanishe {doc}`gallant_tauchen` builds an estimator on this fact. +{doc}`approximation_errors` computes pseudo-true values of misspecified time series models in the frequency domain. + {doc}`mle` describes how to compute maximum likelihood estimates. {ref}`div_ex3` fits a misspecified Beta model to data drawn from a mixture. @@ -708,6 +710,8 @@ This lecture has introduced tools that we'll encounter elsewhere. - {doc}`merging_of_opinions` uses the Bhattacharyya coefficient, under the name Hellinger affinity, to decide when two Bayesians' opinions merge. +- {doc}`approximation_errors`, {doc}`specification_tests`, and {doc}`turbulence_inference` apply m-projections to misspecified time series models, specification tests, and indirect inference. + - {doc}`exponential_families` and {doc}`information_projections` study the geometry of KL divergence: the exponential family, maximum entropy, and projections of distributions onto families of distributions, with applications to estimation, robust control, matrix balancing, and Chernoff information. ## Exercises @@ -1022,7 +1026,7 @@ for N in [10**2, 10**3, 10**4, 10**5, 10**6]: The estimates approach $(a^*, b^*)$, the member of the Beta family closest to $h$ in KL divergence. -{doc}`mix_model` studies a Bayesian whose model contains only $f$ and $g$ and who sees data from $h$; KL divergences from $h$ to $f$ and to $g$ determine where that Bayesian's beliefs settle. +{doc}`mix_model` studies a Bayesian whose model contains only $f$ and $g$ and who sees data from $h$; KL divergences of $h$ from $f$ and from $g$ determine where that Bayesian's beliefs settle. {doc}`gallant_tauchen` uses the pseudo-true value of an auxiliary model as the target of an estimator. diff --git a/lectures/exponential_families.md b/lectures/exponential_families.md index 0ec6c07d3..eb3561578 100644 --- a/lectures/exponential_families.md +++ b/lectures/exponential_families.md @@ -874,12 +874,14 @@ For the normal family, writing out $B_F(\theta_2, \theta_1)$ recovers the famili $$ D_{KL}\left( N(\mu_1, \sigma_1^2) \| N(\mu_2, \sigma_2^2) \right) = \log \frac{\sigma_2}{\sigma_1} + \frac{\sigma_1^2 + (\mu_1 - \mu_2)^2}{2 \sigma_2^2} - \frac{1}{2} , -$$ +$$ (ef_kl_normal) which reduces to the expression $(\mu_1 - \mu_2)^2/(2\sigma^2)$ that we used for the four normal distributions when $\sigma_1 = \sigma_2 = \sigma$. The multivariate version of this formula appears in {doc}`advanced:entropy`. +{doc}`approximation_errors` applies {eq}`ef_kl_normal` frequency by frequency to compute the KL divergence rate between two stationary Gaussian processes. + ### Fisher information is the curvature of KL divergence When $\theta_2$ is close to $\theta_1$, a second-order Taylor expansion of {eq}`ef_kl_bregman` gives @@ -904,6 +906,8 @@ If $\theta$ is a function of another parameter $\xi$, with Jacobian $J = \partia The quadratic approximations in the two coordinate systems agree to second order in the size of a displacement and differ for large displacements. +{doc}`specification_tests` shows that the likelihood ratio, Lagrange multiplier, and Hausman statistics of a test of independence of irrelevant alternatives are $2m$ times a KL divergence and quadratic approximations of this kind in three coordinates. + The figure shows this for the Poisson family, comparing $D_{KL}(p_{\lambda_0} \| p_\lambda)$ with its quadratic approximations in natural parameters, $\frac{1}{2} \lambda_0 (\log \lambda - \log \lambda_0)^2$, and in expectation parameters, $\frac{1}{2} (\lambda - \lambda_0)^2 / \lambda_0$. ```{code-cell} ipython3 diff --git a/lectures/gallant_tauchen.md b/lectures/gallant_tauchen.md index 19a63b9d8..86f24bca8 100644 --- a/lectures/gallant_tauchen.md +++ b/lectures/gallant_tauchen.md @@ -242,7 +242,7 @@ The order condition is necessary but not sufficient, and {ref}`gt_ex3` construct (gt_why_score)= ## Why the score is the right thing to match -{doc}`divergence_measures` shows that maximum likelihood minimizes the cross-entropy of the parametric model relative to the empirical distribution of the data, the sample analogue of the KL divergence from the data-generating distribution to the model. +{doc}`divergence_measures` shows that maximum likelihood minimizes the cross-entropy of the parametric model relative to the empirical distribution of the data, the sample analogue of the KL divergence of the data-generating distribution from the model. Step 1 projects the data onto the auxiliary family by minimizing KL divergence. @@ -259,6 +259,8 @@ the point in the auxiliary family closest to the structural model at $\rho$ {cit The function $\theta^0(\cdot)$ maps structural parameters into auxiliary parameters. +In the language of {doc}`information_projections`, $\theta^0(\rho)$ is the m-projection of the structural model's distribution onto the auxiliary family. + As $n$ grows, $\tilde\theta_n$ converges to $\theta^0 = \theta^0(\rho^0)$. Now differentiate the divergence with respect to $\theta$: @@ -355,6 +357,8 @@ Indirect inference names the class of estimators that compare observed and simul {cite:t}`GourierouxMonfortRenault1993` call $\theta^0(\rho)$ the **binding function**. +{doc}`turbulence_inference` computes a binding function for a calibrated search model, with a Gaussian random-effects model of earnings as the auxiliary model. + Their estimator is $$ @@ -876,6 +880,8 @@ Gallant and Tauchen emphasize this second use of the machinery. An auxiliary model that approximates the data well makes the test powerful against structural model error, and the individual score components say *which* features of the data a rejected model fails to match. +{doc}`specification_tests` describes other tests that compare two projections. + Gallant and Tauchen's **quasi-t-ratios** divide each component of $\sqrt{n}\, m(\hat\rho_n, \tilde\theta_n)$ by its standard error. The asymptotic variance of $\sqrt{n}\, m(\hat\rho_n, \tilde\theta_n)$ is diff --git a/lectures/hansen_singleton_1983.md b/lectures/hansen_singleton_1983.md index 72b45694b..e8189db5f 100644 --- a/lectures/hansen_singleton_1983.md +++ b/lectures/hansen_singleton_1983.md @@ -1066,6 +1066,8 @@ LR = 2(\ell_u - \ell_r) \Rightarrow \chi^2_d, where $\ell_u$ and $\ell_r$ are the maximized log-likelihoods of the unrestricted and restricted models, and $d$ is the difference in the number of free parameters. +When the unrestricted model is a Gaussian vector autoregression estimated by least squares, $LR$ equals twice the sum over dates of the KL divergences between the one-step conditional distributions that the unrestricted and restricted fits imply; {doc}`specification_tests` describes such tests as comparisons of two projections. + Both likelihoods must be evaluated on the same effective sample for the LR distribution to be valid. {cite:t}`hansen1983stochastic` report that for the value-weighted aggregate stock return, the $\chi^2$ test statistics provide little evidence against the model. diff --git a/lectures/information_projections.md b/lectures/information_projections.md index bb993cd2c..47877e8c2 100644 --- a/lectures/information_projections.md +++ b/lectures/information_projections.md @@ -1342,6 +1342,8 @@ The lecture applied m-projections to maximum likelihood estimation and mutual in The worst-case models of robust control, the biproportional tables of RAS, and the regularized transport plans are all exponential tilts of the kind that attains the logit formula {eq}`ef_logit_base` of {doc}`exponential_families`. +{doc}`approximation_errors` applies m-projections to misspecified time series models and to seasonal adjustment, {doc}`specification_tests` describes specification tests as comparisons of m-projections, and {doc}`turbulence_inference` uses them to interpret a check of a calibrated search model against evidence on earnings instability. + Other applications include the EM algorithm, which {cite:t}`CsiszarTusnady1984` interpret as alternating projections, and the hierarchical decomposition of interactions among many random variables of {cite:t}`Amari2001`, which {ref}`ip_ex_interactions` takes up. ## Exercises diff --git a/lectures/likelihood_ratio_process.md b/lectures/likelihood_ratio_process.md index 7b4c3e8f9..3e4b1544b 100644 --- a/lectures/likelihood_ratio_process.md +++ b/lectures/likelihood_ratio_process.md @@ -716,8 +716,8 @@ when $h$ governs the data. A key tool here is called **Kullback–Leibler divergence** we studied in {doc}`divergence_measures`. -In our application, we want to measure how much $f$ or $g$ -diverges from $h$ +In our application, we want to measure how much $h$ +diverges from $f$ or from $g$ Two Kullback–Leibler divergences pertinent for us are $K_f$ and $K_g$ defined as diff --git a/lectures/likelihood_ratio_process_2.md b/lectures/likelihood_ratio_process_2.md index e26504287..33f996890 100644 --- a/lectures/likelihood_ratio_process_2.md +++ b/lectures/likelihood_ratio_process_2.md @@ -103,7 +103,7 @@ The likelihood ratio process satisfies the recursion $L(w^t) = \ell (w_t) L (w^{ Suppose that a density $h$ generates the data. -Let $K_f = KL(h, f)$ and $K_g = KL(h, g)$ be the Kullback–Leibler divergences of $f$ and $g$ from $h$. +Let $K_f = KL(h, f)$ and $K_g = KL(h, g)$ be the Kullback–Leibler divergences of $h$ from $f$ and from $g$. The strong law of large numbers applied to $\log L_t = \sum_{i=1}^t \log \ell(w_i)$ implies @@ -978,7 +978,7 @@ The far $g$ has $KL(h,g) = 0.241 > KL(h,f)$, so agent 1's consumption share goes Agent 1 loses to the close $g$ and wins against the far $g$. -In each case the winner is the agent whose beliefs have the smaller KL divergence from $h$. +In each case the winner is the agent whose beliefs are closer to $h$ in KL divergence. These outcomes agree with formula {eq}`eq:be_survival` and with {ref}`KL_link` in {doc}`likelihood_ratio_process`. diff --git a/lectures/likelihood_var.md b/lectures/likelihood_var.md index 89a7b0795..42d88d22e 100644 --- a/lectures/likelihood_var.md +++ b/lectures/likelihood_var.md @@ -491,6 +491,8 @@ The average slopes of the log likelihood ratio paths in the figures above are Ku They are VAR counterparts of the {ref}`KL divergence rate for Markov chains ` in {doc}`likelihood_ratio_process`. +{doc}`approximation_errors` writes the same rate as an integral over frequencies of KL divergences between normal distributions whose variances are the two spectral densities. + {doc}`divergence_measures` describes Kullback–Leibler divergence. Let $\Sigma_f = C_f C_f^\top$ and $\Sigma_g = C_g C_g^\top$, and let $V_f$ solve the discrete Lyapunov equation @@ -1187,12 +1189,12 @@ From the stationary distributions, the medians of $\log L_{50}$ are within $0.5$ From $Y_0 \approx 100$, it selects the correct model in all $50$ samples from each model. -Under $f$, $E_f [\log L_t] = KL_0 + t \, h_{KL}(f, g)$, where $KL_0$ is the Kullback–Leibler divergence of the stationary distribution of $(Y_0, Y_{-1})$ under $g$ from that under $f$. +Under $f$, $E_f [\log L_t] = KL_0 + t \, h_{KL}(f, g)$, where $KL_0$ is the Kullback–Leibler divergence of the stationary distribution of $(Y_0, Y_{-1})$ under $f$ from that under $g$. ```{code-cell} ipython3 def kl_gauss(μ_1, Σ_1, μ_2, Σ_2): """ - KL divergence of N(μ_2, Σ_2) from N(μ_1, Σ_1) + KL divergence of N(μ_1, Σ_1) from N(μ_2, Σ_2) """ n = len(μ_1) Σ_2_inv = np.linalg.inv(Σ_2) diff --git a/lectures/lq_permanent_income.md b/lectures/lq_permanent_income.md index 5e1d139fa..b9c5518a2 100644 --- a/lectures/lq_permanent_income.md +++ b/lectures/lq_permanent_income.md @@ -269,6 +269,8 @@ moving-average coefficients**. Thus, consumption is a **random walk** with innovation $(1-\beta)d(\beta)w_{t+1}$. +{doc}`approximation_errors` describes {cite:t}`Sims1993`'s use of this formula to show how a misspecified seasonal model of income biases the inferred response of consumption to income. + Combining {eq}`eq:sprob13` and {eq}`eq:sprob7` gives $$ diff --git a/lectures/lucas_prescott_search.md b/lectures/lucas_prescott_search.md index 3b6f0cdaa..b240b2e13 100644 --- a/lectures/lucas_prescott_search.md +++ b/lectures/lucas_prescott_search.md @@ -1058,6 +1058,8 @@ Lucas and Prescott end their discussion of a moving cost with a conjecture, that Why average unemployment differs across countries became a central question for this class of models; {cite:t}`LjungqvistSargent1998`, for example, trace the rise of European unemployment to generous unemployment benefits interacting with a more turbulent economic environment. +{doc}`turbulence_inference` computes the laissez-faire version of their model and asks how much of the rise in U.S. earnings instability turbulence can deliver. + {cite:t}`BaleyLjungqvistSargent2025` call the **returns to labor mobility**, how much more a worker produces where he is going than where he is, "important intermediating forces in all modern macroeconomic models with frictional labour markets". {cite:t}`BaleyLjungqvistSargent2023` show that the same quantity decides what a layoff tax does to unemployment, and whether skill losses at the time of a quit can reverse the effect of turbulence on unemployment. It is a property of the shock and of the technology that intermediates it, taken together. diff --git a/lectures/mccall_model_with_separation.md b/lectures/mccall_model_with_separation.md index fc39e1b51..fc1b2b756 100644 --- a/lectures/mccall_model_with_separation.md +++ b/lectures/mccall_model_with_separation.md @@ -649,6 +649,8 @@ If the separation rate is high, then the benefit of holding out for a higher wag Hence the reservation wage is lower. +{doc}`turbulence_inference` studies a search model in which a separation can also destroy skills, and asks whether evidence on earnings can distinguish a higher separation rate from larger skill losses. + ## Exercises ```{exercise-start} diff --git a/lectures/ols.md b/lectures/ols.md index 14c895994..e3e6b098b 100644 --- a/lectures/ols.md +++ b/lectures/ols.md @@ -627,6 +627,8 @@ print(reg2.summary()) The output shows that the coefficient on the residuals is statistically significant, indicating $avexpr_i$ is endogenous. +The square of the $t$ statistic on $\hat \upsilon_i$ is Wu's statistic $T_2$ of {doc}`specification_tests`, the ratio of the squared lengths of the two legs of a right triangle whose Pythagorean theorem is the one for m-projections. + ```{solution-end} ``` diff --git a/lectures/phillips_drifts_volatilities.md b/lectures/phillips_drifts_volatilities.md index c9196c8ec..0d8b17181 100644 --- a/lectures/phillips_drifts_volatilities.md +++ b/lectures/phillips_drifts_volatilities.md @@ -1788,6 +1788,8 @@ as much as they do here. Low power is not surprising. +Andrews's tests compare estimates of a time-invariant model before and after a candidate break date, which are projections of two distributions onto the same model in the sense of {doc}`specification_tests`; drift that moves those projections little leaves the tests little power. + The drifting-coefficient model nests time invariance at $Q=0$: for $Q$ near zero power is close to size, for very large $Q$ the tests reject almost surely, and in between lies a range of economically meaningful drift that the tests usually diff --git a/lectures/phillips_misspecified.md b/lectures/phillips_misspecified.md index 985110b7c..86d2fa9b1 100644 --- a/lectures/phillips_misspecified.md +++ b/lectures/phillips_misspecified.md @@ -259,6 +259,8 @@ A(c, \sigma_\epsilon^2) = \frac{1}{N}\sum_{j=0}^{N-1} where $\omega_j = \frac{2\pi j}{N}$ and $G(\omega, c) = |g(e^{i\omega})|^2 \sigma_\epsilon^2$ is the spectral density of the perceived model. +{doc}`approximation_errors` derives this criterion: it is twice the KL divergence rate of the true process from the perceived model, plus a term that does not depend on $(c, \sigma_\epsilon^2)$. + The term $\frac{\nu^2}{G(0)} = \frac{\nu^2 (1 - \rho)^2}{c^2 \sigma_\epsilon^2}$ charges the perceived model for the squared mean of its forecast errors; this is how the model is made to use its near-unit root to fit the mean. Concentrating out $\sigma_\epsilon^2$ sets it equal to the mean square forecast error @@ -357,7 +359,7 @@ The fixed point $C = B(C)$ has several names in the later literature, each empha * It is a **restricted-perceptions equilibrium** ({cite:t}`EvansHonkapohja2001`, chapter 13): forecasts are optimal within a restricted class of models that excludes the truth. * For given $C$, the best estimate $c$ is a **pseudo-true value** in the sense of {cite:t}`White1982`, the parameter of a misspecified model that comes closest to the truth. Unlike in White's setting, here the truth itself depends on the agents' parameter, through $C$. -* Up to constants, criterion {eq}`pm_criterion` is the frequency-domain (Whittle) form of the Kullback–Leibler divergence of the perceived model from the true process. So the fixed point is also a **Berk–Nash equilibrium** in the sense of {cite:t}`EspondaPouzo2016`, with the forecasting rule as the agents' action. +* Criterion {eq}`pm_criterion` is twice the KL divergence rate of the true process from the perceived model, plus a constant ({doc}`approximation_errors`), so the best estimate $c$ is the m-projection of the true process onto the perceived models, in the sense of {doc}`information_projections`, and the fixed point is also a **Berk–Nash equilibrium** in the sense of {cite:t}`EspondaPouzo2016`, with the forecasting rule as the agents' action. {doc}`learning_approximation` computes the same kind of object, which it calls an approximate equilibrium, for a saving rule restricted to a polynomial family. @@ -387,6 +389,8 @@ With enough data, appropriate statistical tests would eventually tell agents how The answer lies in how far apart the true and approximating spectral densities are, which we now study. +{doc}`specification_tests` describes tests that need no specified alternative: each compares two projections of the data, and it has power only against misspecifications that move those projections apart. + ## Comparing the true and forecasting models For the equilibrium $C$, we plot the equilibrium spectral densities of the true and approximating models. @@ -666,7 +670,7 @@ For Gaussian processes, the expected log-likelihood ratio per observation of the :class: dropdown ``` -The Kullback–Leibler divergence rate of a mean-zero Gaussian model with spectral density $G$ from a Gaussian process with mean $\nu$ and spectral density $F$ is +The Kullback–Leibler divergence rate {eq}`ae_kl_rate_vector` of a Gaussian process with mean $\nu$ and spectral density $F$ from a mean-zero Gaussian model with spectral density $G$ is $$ \frac{1}{2}\left\{ \frac{1}{N}\sum_j \left[\frac{F(\omega_j)}{G(\omega_j)} - 1 - \log\frac{F(\omega_j)}{G(\omega_j)}\right] + \frac{\nu^2}{G(0)} \right\} . diff --git a/lectures/phillips_policy_evaluation.md b/lectures/phillips_policy_evaluation.md index 464ca5f1b..cebfc48f2 100644 --- a/lectures/phillips_policy_evaluation.md +++ b/lectures/phillips_policy_evaluation.md @@ -419,6 +419,8 @@ and the natural rate $U^*$ has a large standard error. The Keynesian scheme has a much higher likelihood. +Divided by the sample size, the gap between the two maximized log likelihoods estimates the difference between the KL divergence rates of the data's distribution from the two schemes' m-projections ({doc}`approximation_errors`); the gap ranks the two misspecified models and does not test either. + Our gap between the two schemes is smaller than the book's; the levels of $\log L$ are not comparable, because of the misprinted constant and different data vintages, but the sign of the gap is the same. The residuals show where the gap comes from, and why $U^*$ is hard to pin down: @@ -712,6 +714,8 @@ The reason is the coefficient $\beta_1$ on current unemployment in the Keynesian With one lag of unemployment it is clearly negative in 1973–1979; with two lags it is about half as large with end-of-quarter sampling and about zero with quarterly averages. +{cite:t}`Sims1971`, described in {doc}`approximation_errors`, shows that point sampling and averaging project the same continuous-time relationship onto different discrete-time lag distributions. + Inverting the curve then divides by a number near zero, so the believed unemployment dynamics become erratic and the government's short-run response to the inflation it inherits swings with them; that is why the one-step misses shrink in those columns. Monthly data fail for a more basic reason. diff --git a/lectures/phillips_self_confirming.md b/lectures/phillips_self_confirming.md index bc686e461..36c4d2308 100644 --- a/lectures/phillips_self_confirming.md +++ b/lectures/phillips_self_confirming.md @@ -364,6 +364,8 @@ The Keynesian case is the same, with slope $1/(1 + \beta_1^2)$ in the equation f **E-stability.** Write the classical equilibrium as a fixed point $\gamma = T(\gamma)$ of the map from beliefs to the population regression coefficients they generate. +Population regression coefficients are m-projections of the true conditional distribution onto Gaussian linear regressions ({doc}`approximation_errors`), so $T$ and the best-estimate map of {doc}`phillips_misspecified` are both maps from beliefs to m-projections. + The associated differential equation $d\gamma/d\tau = T(\gamma) - \gamma$ is the E-stability condition of {ref}`br_one_recursion`, and {doc}`ls_learning` shows that its stability governs whether least squares learning converges. Because $T_1$ does not depend on beliefs, the Jacobian of $T - I$ at the equilibrium is triangular, with eigenvalues $-1$ (slope) and $\theta^2/(1 + \theta^2) - 1 = -1/(1 + \theta^2)$ (intercept). @@ -831,6 +833,8 @@ print(f"one-step RMSE of the approximating model / true innovation s.d. = " f"{np.sqrt(σ_ε2) / mp.σ2:.4f}") ``` +By the argument of {ref}`pmis_ex3`, the logarithm of the printed ratio is the KL divergence rate of the true inflation process from the public's perceived model. + The approximating model's one-step forecast errors are only slightly larger than the true innovations, so there is a nearly self-confirming model with much better than Nash outcomes. But the optimism is conditional. diff --git a/lectures/sargent_surico.md b/lectures/sargent_surico.md index 7b0534c13..3cdc9d006 100644 --- a/lectures/sargent_surico.md +++ b/lectures/sargent_surico.md @@ -143,6 +143,8 @@ $$ (eq:ss_h0) Whiteman showed that as $\beta \to 1$ the regression coefficient of $\bar y_t(\beta)$ on $\bar z_t(\beta)$ converges to $h(0)$. +{doc}`approximation_errors` describes least squares with filtered data as a projection that weights each frequency by the filtered spectral density of the regressor; Lucas's filter puts nearly all of that weight at frequency zero. + So Lucas's two illustrations are claims that $$ diff --git a/lectures/specification_tests.md b/lectures/specification_tests.md new file mode 100644 index 000000000..ddb4d34cb --- /dev/null +++ b/lectures/specification_tests.md @@ -0,0 +1,700 @@ +--- +jupytext: + text_representation: + extension: .md + format_name: myst + format_version: 0.13 + jupytext_version: 1.16.4 +kernelspec: + display_name: Python 3 (ipykernel) + language: python + name: python3 +--- + +(specification_tests)= +```{raw} jupyter + +``` + +# Specification Tests + +```{contents} Contents +:depth: 2 +``` + +## Overview + +The specification tests in this lecture compare two estimators. + +When the model is correctly specified, both estimators converge to the true parameter. + +When the model is misspecified, the two estimators converge to two m-projections in the sense of {doc}`information_projections`: projections of the true distribution onto two different models, or projections of two distributions derived from the true distribution onto the same model. + +In large samples, a test has power against a misspecification only if the misspecification makes the parameters of those two projections differ; for alternatives near the null hypothesis, its power grows with the distance between them, measured in the metric $V(\hat q)^{-1}$ that we define below. + +We organize this lecture around that idea. + +{doc}`approximation_errors` computes the pseudo-true values of misspecified time series models; this lecture describes tests that compare two pseudo-true values. + +* {cite:t}`Wu1973` compares ordinary least squares with instrumental variables. With the variance held fixed, his statistic is the ratio of the squared lengths of the two legs of a right triangle, in the sense of the Pythagorean theorem of {doc}`information_projections`. +* {cite:t}`Hausman1978` compares an efficient estimator with an estimator that remains consistent under the alternative. His lemma, that the efficient estimator is uncorrelated with the difference between the two estimators, makes the variance of that difference a Pythagorean theorem in the inner product defined by asymptotic covariances. +* {cite:t}`HausmanMcFadden1984` compare two estimators of a multinomial logit model. In their three-choice example, the likelihood ratio statistic is a multiple of a KL divergence, and the Lagrange multiplier and Hausman statistics are the same multiple of quadratic approximations to it in different coordinates. +* {cite:t}`HanSar1980` propose a test of the strict exogeneity of variables in a rational expectations model by comparing two fitted models. +* We construct a test that compares the frequency-domain maximum likelihood estimator that uses all frequencies with the one that deletes seasonal bands. + +{doc}`turbulence_inference` applies the comparison of projections to a calibrated search model. + +We use the following imports. + +```{code-cell} ipython3 +import numpy as np +import matplotlib.pyplot as plt +from scipy.optimize import minimize_scalar +from scipy.signal import lfilter +from scipy.stats import chi2, ncx2, binom +from scipy.stats import f as f_dist +``` + +(st_wu_section)= +## Wu's statistic + +{cite:t}`Wu1973` studies the regression $y = Y_2 \beta + Z_1 \gamma + u$, in which the $G$ regressors in $Y_2$ may be correlated with the disturbance $u$ and the $K_1$ regressors in $Z_1$ are exogenous. + +The regressors satisfy $Y_{i2} = \mu_i + V_i$, where the $\mu_i$ are unknown nonstochastic vectors and $(u_i, V_i)$ are jointly normal; in a simultaneous equations system, $\mu_i$ is a linear function of a vector $Z_i$ of instruments that contains $Z_{i1}$. + +The null hypothesis is that $Y_2$ and $u$ are independent, $E[V_i u_i] = 0$. + +Let $\sigma_{11} = \operatorname{Var}(u_i)$, $\delta = E[V_i u_i]$, and $\Sigma_{22} = \operatorname{Var}(V_i)$. + +Under the alternative, joint normality makes $E[u_i \mid V_i] = V_i^\top \alpha$ with $\alpha = \Sigma_{22}^{-1} \delta$, so the disturbance $u_i - V_i^\top \alpha$ is independent of $V_i$ and of $Y_{i2}$. + +{cite:t}`Hausman1978`, in his equations (2.18)–(2.23), writes Wu's comparison as a regression. + +He splits $Y_2$ into its fitted values from the regression on the instruments, which are asymptotically uncorrelated with $u$ under both hypotheses, and the matrix $\hat V$ of residuals from that regression. + +He then regresses $y$ on $Y_2$, $Z_1$, and $\hat V$ and tests whether the coefficient $\alpha$ on $\hat V$ is zero; the coefficient on $Y_2$ in that regression is the instrumental variables estimator. + +His general version (2.23) adds the fitted values instead of $\hat V$; the two regressions have the same fitted values and the same test of $\alpha = 0$. + +{doc}`ols` applies this regression to the data of Acemoglu, Johnson, and Robinson, with one endogenous regressor. + +Consider two families of normal conditional distributions of $y$ given the regressors, both with a variance fixed at $\sigma_{11}$: + +* the null model, with mean $Y_2 \beta + Z_1 \gamma$; and +* the larger model, with mean $Y_2 \beta + Z_1 \gamma + \hat V \alpha$. + +Under the alternative, the larger model's disturbance $u_i - V_i^\top \alpha$ has a variance smaller than $\sigma_{11}$; fixing both variances at $\sigma_{11}$ makes the two families nested with a common variance. + +These are nested exponential families, and the null model is the exponential subfamily with $\alpha = 0$. + +Ordinary least squares and the least squares regression of $y$ on $Y_2$, $Z_1$, and $\hat V$ are the maximum likelihood estimators in the two families, so they are the m-projections of the data onto them. + +The Pythagorean theorem {eq}`ip_pythagoras_m` of {doc}`information_projections`, in the log-likelihood form {eq}`ip_lr_kl` that holds for continuous outcomes, therefore applies, and in this Gaussian setting it is the Pythagorean theorem for least squares: + +$$ +Q_4 = Q_2 + Q^* . +$$ (st_wu) + +We keep Wu's subscripts. + +Here $Q_4$ is the sum of squared residuals from ordinary least squares, $Q_2$ is the sum of squared residuals from the larger regression, and $Q^*$ is the squared distance between the two vectors of fitted values. + +Divided by $\sigma_{11}$, $Q_4 - Q_2$ is twice the log likelihood ratio of the two fits and $Q^*$ is twice the sum over observations of the KL divergences between the two fitted conditional distributions; {eq}`ip_lr_kl` equates them. + +Wu computes $Q^*$ from the difference between the ordinary least squares estimator $b_1$ and the instrumental variables estimator $b_2$ of $\beta$, + +$$ +Q^* = (b_1 - b_2)^\top \left[ (Y_2^\top A_2 Y_2)^{-1} - (Y_2^\top A_1 Y_2)^{-1} \right]^{-1} (b_1 - b_2) , +$$ + +where $Z = [Z_1, Z_2]$ is the $N \times (K_1 + K_2)$ matrix of all $K_1 + K_2$ instruments, $A_1 = I - Z_1(Z_1^\top Z_1)^{-1}Z_1^\top$, and $A_2 = Z(Z^\top Z)^{-1}Z^\top - Z_1(Z_1^\top Z_1)^{-1}Z_1^\top$. + +Wu defines $Q_2 = Q_4 - Q^*$ as his equation (2.19) and proves that, under the null hypothesis and conditional on $Y_2$, $Q^*/\sigma_{11}$ and $Q_2/\sigma_{11}$ are independent chi-square variables. + +$Q_2$ is also the sum of squared residuals of Hausman's larger regression. + +After $Z_1$ is partialled out, the regressors $A_1 Y_2$ split into the orthogonal pieces $A_2 Y_2$ and $\hat V$, and Hausman's equation (2.21) shows that the test of $\alpha = 0$ reproduces $Q^*$. + +Wu's statistic + +$$ +T_2 = \frac{Q^* / G}{Q_2 / (N - K_1 - 2G)} +$$ + +is the ratio of the squared lengths of the two legs of the right triangle {eq}`st_wu`, each divided by its degrees of freedom, where $N$ is the number of observations. + +Wu proves that, under the null hypothesis, $T_2$ has the $F$ distribution with $G$ and $N - K_1 - 2G$ degrees of freedom whenever $N - K_1 > 2G$. + +His statistics $T_4$ and $T_3$ divide $Q^*$ by the least squares and the instrumental variables estimates of $\sigma_{11}$. + +He shows that the ratios $G T_2 / T_4$ and $T_4 / T_3$ converge in probability to constants that are at least one and equal one only when $\delta = 0$. + +In his large-sample approximations to the power functions, $G T_2$ therefore rejects at least as often as $T_4$, and $T_4$ at least as often as $T_3$, at a common $\chi^2_G$ critical value. + +Wu assumes more instruments than endogenous regressors, $K_2 > G$, throughout; only his statistic $T_1$, whose denominator has $K_2 - G$ degrees of freedom, needs that assumption. + +The code below checks {eq}`st_wu` and the exact $F$ distribution for a model with one regressor in $Y_2$, no regressors in $Z_1$, one instrument, and $N = 25$ observations. + +```{code-cell} ipython3 +N, β_true, Π = 25, 1.0, 0.6 +rng = np.random.default_rng(0) +z_inst = rng.normal(size=N) # nonstochastic instrument + + +def wu_statistics(y, x, z_inst): + x_hat = z_inst * (z_inst @ x) / (z_inst @ z_inst) + b1, b2 = (x @ y) / (x @ x), (x_hat @ y) / (x_hat @ x) + Q_star = (b1 - b2)**2 / (1 / (x_hat @ x_hat) - 1 / (x @ x)) + X = np.column_stack([x, x - x_hat]) + coef = np.linalg.lstsq(X, y, rcond=None)[0] + fit0, fit1 = b1 * x, X @ coef + Q4, Q2 = np.sum((y - fit0)**2), np.sum((y - fit1)**2) + return Q_star, Q4, Q2, np.sum((fit1 - fit0)**2) + + +u = rng.normal(size=N) +x = Π * z_inst + rng.normal(size=N) +Q_star, Q4, Q2, dist2 = wu_statistics(β_true * x + u, x, z_inst) +print(f"Q4 = {Q4:.6f}, Q2 + Q* = {Q2 + Q_star:.6f}, Q* = {Q_star:.6f}, " + f"squared distance between fits = {dist2:.6f}") + +R = 20_000 +T2 = np.empty(R) +for r in range(R): + u = rng.normal(size=N) + x = Π * z_inst + rng.normal(size=N) + Q_star, _, Q2, _ = wu_statistics(β_true * x + u, x, z_inst) + T2[r] = Q_star / (Q2 / (N - 2)) +crit = f_dist.ppf(0.95, 1, N - 2) +print(f"fraction of T2 above the 5% critical value of F(1, {N - 2}): " + f"{np.mean(T2 > crit):.4f}") +``` + +(st_hausman_section)= +## Hausman's lemma + +{cite:t}`Hausman1978` generalizes the comparison to any pair of estimators $\hat \beta_0$ and $\hat \beta_1$ such that, under the null hypothesis, both are consistent and asymptotically normal and $\hat \beta_0$ is asymptotically efficient, while under the alternative only $\hat \beta_1$ is consistent. + +His Lemma 2.1 states: + +> Consider two estimators $\hat\beta_0$, $\hat\beta_1$ which are both consistent and asymptotically normally distributed with $\hat\beta_0$ attaining the asymptotic Cramer–Rao bound so $\sqrt{T}(\hat\beta_0 - \beta) \overset{A}{\sim} N(0, V_0)$ and $\sqrt{T}(\hat\beta_1 - \beta) \overset{A}{\sim} N(0, V_1)$ where $V_0$ is the inverse of Fisher's information matrix. Consider $\hat q = \hat\beta_1 - \hat\beta_0$. Then the limiting distributions of $\sqrt{T}(\hat\beta_0 - \beta)$ and $\sqrt{T}\hat q$ have zero covariance, $C(\hat\beta_0, \hat q) = 0$, a zero matrix. + +Hausman gives the reason: "If this were not the case, a linear combination of $\hat\beta_0$ and $\hat q$ could be taken which would lead to a consistent estimator $\hat\beta_*$ which would have smaller asymptotic variance than $\hat\beta_0$ which is assumed asymptotically efficient." + +Hausman's Corollary 2.6 follows: the two terms in $\hat\beta_1 = \hat\beta_0 + \hat q$ are uncorrelated, so their variances add, + +$$ +V_1 = V_0 + V(\hat q) . +$$ (st_hausman_pythagoras) + +With asymptotic covariance as the inner product, {eq}`st_hausman_pythagoras` is a Pythagorean theorem: the efficient estimator is orthogonal to the difference between the two estimators. + +When $\hat\beta_1$ is the maximum likelihood estimator of a model that nests the null model, as in Wu's case, {eq}`st_hausman_pythagoras` is the Pythagorean theorem of {doc}`information_projections` in its local form. + +Let the larger model have parameters $(\beta, \psi)$ and the null model impose $\psi = \psi_0$. + +{doc}`exponential_families` shows that, near the true distribution, the KL divergence is one half a quadratic form in the Fisher information matrix, so the m-projection onto the null model becomes an orthogonal projection in the Fisher inner product. + +The restricted estimate $\hat\theta_0$ is then approximately the orthogonal projection of the unrestricted estimate $\hat\theta_1$ onto the null model, and the leg $\hat\theta_1 - \hat\theta_0$ of that right triangle is orthogonal to the null model; its $\beta$-coordinate is $\hat q$. + +The vector $\Delta = \sqrt{T}(\hat\theta_1 - \theta)$ has covariance matrix $\mathcal{I}^{-1}$, so $\operatorname{Cov}(a^\top \mathcal{I}\Delta, \, b^\top \mathcal{I}\Delta) = a^\top \mathcal{I} b$ for any vectors $a$ and $b$: components of $\Delta$ that are orthogonal in the Fisher inner product $\langle a, b \rangle = a^\top \mathcal{I} b$ are uncorrelated. + +The components along and orthogonal to the null model have $\beta$-coordinates $\sqrt{T}(\hat\beta_0 - \beta)$ and $\sqrt{T}\hat q$. + +For a general consistent $\hat\beta_1$, the lemma says the same thing about the leading linear terms in the expansions of the two estimators: the efficient estimator's term is uncorrelated with the difference between the two terms. + +Hausman's statistic, which he calls $m$ in his equation (2.7), is $H = T \hat q^\top \tilde V^{-1} \hat q$, where $\tilde V$ is a consistent estimate of $V(\hat q) = V_1 - V_0$. + +His Theorem 2.1 states that $H$ is asymptotically $\chi^2_K$ under the null hypothesis, where $K$ is the number of parameters in $\beta$; his footnote 12 notes that in his instrumental variables example $V(\hat q)$ is nonsingular only when enough instruments are available. + +In Wu's model, $\hat \beta_0$ is ordinary least squares and $\hat \beta_1$ is instrumental variables, and $H$ computed with the least squares estimate of the variance of $u$ equals $Q^*$ divided by that estimate. + +Hausman notes in his footnote 11 that this choice gives the Lagrange multiplier form of the test, and that the instrumental variables estimate of the variance gives the Wald form. + +These two forms are Wu's $T_4$ and $T_3$. + +The simulation below checks {eq}`st_hausman_pythagoras` under the null hypothesis and shows what the two estimators converge to when the null hypothesis is false. + +A just-identified instrumental variables estimator has no finite moments, so we read the simulated variances as approximations to the asymptotic variances; with a first-stage coefficient of $0.6$ and $n = 400$ observations, these approximations are accurate. + +```{code-cell} ipython3 +def ols_iv(σ_uv, rng, n=400, R=20_000, chunk=5_000): + b_ols, b_iv = [], [] + for _ in range(R // chunk): # chunks limit memory use + z_ = rng.normal(size=(chunk, n)) + u_ = rng.normal(size=(chunk, n)) + v_ = σ_uv * u_ + np.sqrt(1 - σ_uv**2) * rng.normal(size=(chunk, n)) # V + x_ = Π * z_ + v_ + y_ = β_true * x_ + u_ + b_ols.append((x_ * y_).sum(axis=1) / (x_ * x_).sum(axis=1)) + b_iv.append((z_ * y_).sum(axis=1) / (z_ * x_).sum(axis=1)) + return np.concatenate(b_ols), np.concatenate(b_iv) + + +rng_h = np.random.default_rng(1) +b_ols, b_iv = ols_iv(0.0, rng_h) +q = b_iv - b_ols +print(f"Var(IV) = {b_iv.var():.3e}, " + f"Var(OLS) + Var(IV - OLS) = {b_ols.var() + q.var():.3e}") +print(f"correlation of OLS with IV - OLS: {np.corrcoef(b_ols, q)[0, 1]:.4f}") + +b_ols, b_iv = ols_iv(0.3, rng_h) +print(f"\nwith Cov(u, V) = 0.3: mean OLS = {b_ols.mean():.4f} " + f"(pseudo-true value {β_true + 0.3 / (Π**2 + 1):.4f}), " + f"mean IV = {b_iv.mean():.4f}") +``` + +When $u$ and $V$ are correlated, ordinary least squares converges to the pseudo-true value $\beta + \operatorname{Cov}(u, x)/\operatorname{Var}(x)$, the coefficient of the m-projection of the true distribution onto the model that assumes independence, while instrumental variables converges to $\beta$. + +Under a sequence of local alternatives, $H$ is asymptotically noncentral $\chi^2$, and its noncentrality parameter is $T$ times the squared distance, in the metric $V(\hat q)^{-1}$, between the probability limits of the two estimators. + +Hausman's test detects whether the parameter of interest depends on which model the true distribution is projected onto, not whether the model is true; it has no power against a misspecification that leaves the two probability limits equal. + +Hausman's footnote 13 gives an example: in a regression with no lagged dependent variables, serially correlated disturbances leave both ordinary least squares and an autoregressive estimator consistent, so the probability limit of $\hat q$ is zero. + +(st_iia_section)= +## Testing independence of irrelevant alternatives + +The multinomial logit model of {doc}`exponential_families` gives the probability that a decision maker chooses alternative $i$ from a choice set $C$ as + +$$ +P(i \mid z, C, \beta) = \frac{\exp(z_i^\top \beta)}{\sum_{j \in C} \exp(z_j^\top \beta)} , +$$ + +where $z_j$ is the vector of attributes of alternative $j$. + +These probabilities form an exponential family in $\beta$ with sufficient statistic $z_i$. + +The logit model has the property of **independence of irrelevant alternatives**: + +$$ +P(i \mid z, C, \beta) = P(i \mid z, A, \beta) \cdot P(A \mid z, C, \beta) +$$ + +for a choice $i$ in a subset $A$ of $C$, where $P(i \mid z, A, \beta)$ is the logit formula applied to the alternatives in $A$ alone. + +{cite:t}`HausmanMcFadden1984` compare the maximum likelihood estimator $\hat\beta_C$ computed from all choices with the conditional maximum likelihood estimator $\hat\beta_A$ computed from the choices that fell in $A$. + +The two estimators are m-projections of two distributions: the distribution of all choices onto the logit model, and the conditional distribution of choices within $A$ onto the logit model restricted to $A$. + +When the logit model is correctly specified, both estimators converge to the true $\beta$. + +When the true model is a nested logit, in which the unobserved utilities of alternatives in the same nest are correlated, the two estimators converge to different values. + +Hausman and McFadden work out a three-choice example in which alternatives 2 and 3 have the same attributes, so that under the logit model they have the same choice probability. + +Let $n_1, n_2, n_3$ be the numbers of times each alternative is chosen, $m = n_2 + n_3$, and $s = n_2 / m$. + +Hausman and McFadden derive a likelihood ratio statistic, a Lagrange multiplier statistic, and a Hausman statistic computed by deleting alternative 3: + +$$ +LR = 2 n_2 \log \frac{2 n_2}{n_2 + n_3} + 2 n_3 \log \frac{2 n_3}{n_2 + n_3} , +\quad +LM = \frac{(n_3 - n_2)^2}{n_2 + n_3} , +\quad +H_3 = \left( \log \frac{2 n_2}{n_2 + n_3} \right)^2 (n_2 + n_3) . +$$ + +Deleting alternative 2 instead gives $H_2 = \left( \log \frac{2 n_3}{n_2 + n_3} \right)^2 (n_2 + n_3)$. + +Conditional on $m$, $n_2$ is binomial with $m$ trials and success probability $\pi_2 = p_2/(p_2 + p_3)$, and $s$ is the maximum likelihood estimate of $\pi_2$. + +The null hypothesis fixes $\pi_2 = \frac{1}{2}$. + +By {eq}`ip_lr_kl` of {doc}`information_projections`, the likelihood ratio statistic is $2m$ times the KL divergence of the Bernoulli distribution with parameter $s$ from the Bernoulli distribution with parameter $\frac{1}{2}$. + +The Lagrange multiplier statistic is $2m$ times the quadratic approximation to that divergence in the coordinate $s$, the expectation parameter. + +The Hausman statistic $H_3$ is $2m$ times the quadratic approximation in the coordinate $\log s$, which is neither the natural parameter $\log(s/(1 - s))$ nor the expectation parameter $s$, and $H_2$ is $2m$ times the quadratic approximation in the coordinate $\log(1 - s)$. + +The Fisher information for $\pi_2$ at $\pi_2 = \frac{1}{2}$ is $1/(\pi_2(1-\pi_2)) = 4$, and the Fisher information for $\log \pi_2$ is $\pi_2/(1 - \pi_2) = 1$, which give the quadratic approximations $2(s - \frac{1}{2})^2$ and $\frac{1}{2}(\log 2s)^2$. + +```{code-cell} ipython3 +def bernoulli_kl(s, p=0.5): + return s * np.log(s / p) + (1 - s) * np.log((1 - s) / (1 - p)) + + +for n2, n3 in ((230, 270), (180, 320)): + m, s = n2 + n3, n2 / (n2 + n3) + LR = 2 * n2 * np.log(2 * n2 / m) + 2 * n3 * np.log(2 * n3 / m) + LM = (n3 - n2)**2 / m + H3 = np.log(2 * n2 / m)**2 * m + print(f"n2, n3 = {n2}, {n3}: LR = {LR:.4f} = 2m KL = " + f"{2 * m * bernoulli_kl(s):.4f}; LM = {LM:.4f} = " + f"{2 * m * 2 * (s - 0.5)**2:.4f}; H3 = {H3:.4f} = " + f"{2 * m * 0.5 * np.log(2 * s)**2:.4f}") +``` + +```{code-cell} ipython3 +--- +mystnb: + figure: + caption: KL divergence per choice of alternative 2 or 3, and the quadratic approximations behind the LM and Hausman statistics + name: fig-st-iia +--- +s_vals = np.linspace(0.2, 0.8, 300) +fig, ax = plt.subplots() +ax.plot(s_vals, bernoulli_kl(s_vals), lw=3, label="KL divergence (LR)") +ax.plot(s_vals, 2 * (s_vals - 0.5)**2, "--", label=r"quadratic in $s$ (LM)") +ax.plot(s_vals, 0.5 * np.log(2 * s_vals)**2, ":", + label=r"quadratic in $\log s$ ($H_3$)") +ax.plot(s_vals, 0.5 * np.log(2 * (1 - s_vals))**2, "-.", + label=r"quadratic in $\log(1 - s)$ ($H_2$)") +ax.set_xlabel("$s = n_2 / (n_2 + n_3)$") +ax.set_ylabel("divergence per choice of alternative 2 or 3") +ax.set_ylim(0, 0.3) +ax.legend(loc="upper center", fontsize=9) +plt.show() +``` + +The four statistics have the same asymptotic distribution under the null hypothesis and under local alternatives, but they differ in finite samples. + +Hausman and McFadden tabulate exact rejection probabilities of these tests and of the Wald test of $\lambda = 1$ in a nested logit model with parameter $\lambda$. + +Their alternatives are nested logit models with $\lambda < 1$ that put alternatives 1 and 2 in one nest, so that $p_2 < p_3$. + +In their Tables III.2 and III.3, the Wald test and $H_3$ are the most powerful, followed by the likelihood ratio and Lagrange multiplier tests, and $H_2$ is the least powerful. + +Their text names $H_2$ in four places where the rows of their tables show $H_3$, and $H_3$ in one place where the tables show $H_2$; the ranking they state on p. 1233, WALD > H3 > LR > LM > H2, agrees with the tables. + +They report two "rather unexpected results": + +> (i) The three tests which comprise the so-called holy trinity of asymptotic tests differ markedly in both of their operating characteristics even when their nominal size is the same. (ii) The Wald test and Hausman type test have approximately equal power. Next comes the LR test and the LM test. Both results may well arise because we are considering a nonlocal alternative hypothesis. + +They add that "the samples may not be large enough for the reliable application of asymptotic theory." + +{doc}`exponential_families` compares quadratic approximations to KL divergence in natural and expectation coordinates for the Poisson family. + +{ref}`st_ex_iia` computes exact sizes and powers. + +(st_hs_section)= +## Hansen and Sargent's test of exogeneity + +{cite:t}`HanSar1980` derive the cross-equation restrictions that a rational expectations model of a firm's demand for labor imposes on the joint process of employment $n_t$ and a vector $x_t$ of variables that the firm takes as given. + +The firm observes a shock $a_t$ that the econometrician does not. + +Given that employment does not Granger-cause $x_t$, the vector $x_t$ is strictly exogenous in the firm's decision rule if and only if a vector $v$ of regression coefficients is zero, which is equivalent to the requirement that the innovations in $x_t$ be uncorrelated with the innovations in $a_t$. + +They write: + +> This latter test is similar in spirit to the test for exogeneity proposed by Wu (1973) in a classical simultaneous equations setting. + +and add that their setting differs from Wu's "in that we are allowing for serial correlation in disturbance terms and that we achieve parameter identification via non-linear cross-equation restrictions implied by the hypothesis of rational expectations." + +They propose to estimate the model twice by quasi-maximum likelihood, once with $v$ free and once with $v = 0$, and to compare the two likelihoods with a likelihood ratio statistic that is asymptotically $\chi^2$ under the null hypothesis. + +A second version tests $v = 0$ with the estimated covariance matrix of $\hat v$. + +They also propose testing the cross-equation restrictions themselves by nesting the model within a more loosely specified model that does not impose them. + +{doc}`hansen_singleton_1983` applies such a test to the cross-equation restrictions that a consumption Euler equation imposes on a vector autoregression. + +With the frequency-domain likelihood {eq}`ae_whittle` of {doc}`approximation_errors`, each log likelihood is, up to a term that does not depend on the model, minus the sum over frequencies of the cross-entropies of $N(0, I(\omega_j))$ relative to $N(0, G(\omega_j, \delta))$. + +Each likelihood ratio statistic is therefore a sum over frequencies. + +Neither the unrestricted model nor the restricted model is an exponential family in general, and the cross-equation restrictions make the restricted model a curved subset of the unrestricted one. + +The Pythagorean decomposition {eq}`ip_pythagoras_m` therefore holds only to second order, which is the order that the asymptotic $\chi^2$ distribution uses. + +(st_band_section)= +## Comparing frequency bands + +We construct a Hausman test that compares the frequency-domain maximum likelihood estimator that uses all frequencies with the one that deletes the seasonal bands. + +{doc}`approximation_errors` shows that deleting bands from Hansen and Sargent's criterion, as in {eq}`ae_hs_ideal`, projects the part of a process that lies outside the bands onto the part of the model that lies outside them. + +When the model is correctly specified, the two estimators converge to the same parameter, and the estimator that uses all frequencies is efficient, so Hausman's lemma applies. + +When the model is misspecified at the seasonal frequencies, the two estimators converge to different projections. + +In the seasonal example of {doc}`approximation_errors`, where the seasonal component has one quarter of the variance of the nonseasonal component, an AR(1) projection has $\rho^* = 0.62$ with all frequencies and $\rho^* = 0.87$ with bands of width $\pi/8$ deleted. + +With the 1 percent share used below, the solution to {ref}`st_ex_power` computes $0.885$ and $0.899$. + +For a Gaussian process and a correctly specified scalar model with spectral density $g(\omega; \theta)$, $\sqrt{T}$ times the error of the frequency-domain maximum likelihood estimator that uses the frequencies in a set $K$ has asymptotic covariance matrix $\mathcal{I}_K(\theta)^{-1}$, where + +$$ +\mathcal{I}_K(\theta) = \frac{1}{4\pi} \int_{K} \nabla_\theta \log g(\omega; \theta) \, \nabla_\theta \log g(\omega; \theta)^\top \, d\omega . +$$ + +$\mathcal{I}_K(\theta)$ is the curvature of a KL divergence, as in {doc}`exponential_families`: it is the Hessian at $\theta' = \theta$ of the divergence rate {eq}`ae_kl_rate`, restricted to $K$, of $g(\cdot\,; \theta)$ from $g(\cdot\,; \theta')$. + +By {eq}`st_hausman_pythagoras`, the difference between the band-deleted estimator and the full-band estimator has asymptotic covariance matrix $\mathcal{I}_K(\theta)^{-1} - \mathcal{I}(\theta)^{-1}$, where $\mathcal{I}$ uses all frequencies. + +We apply the test to a first-order autoregression with parameters $\theta = (\rho, \sigma^2)$ fitted to $T = 400$ quarterly observations, deleting bands of width $\pi/8$ around $\pi/2$ and $\pi$, and we test only $\rho$, using the $(1, 1)$ elements of these matrices. + +Each estimator uses the Fourier frequencies $\omega_j = 2\pi j / T$, $j = 1, \ldots, T - 1$, omitting $j = 0$ because the sample mean is removed, and we evaluate $\mathcal{I}_K$ at the same frequencies, so that $\frac{1}{4\pi} \int_K$ becomes $\frac{1}{2T} \sum_{j \in K}$. + +Omitting $j = 0$ removes about 10 percent of the information about $\rho$ at $T = 400$, because the spectral density of $x_t$ has a narrow peak at frequency zero; the $(1, 1)$ element of $\mathcal{I}^{-1}$ is $0.21$ rather than $1 - \rho^2 = 0.19$. + +In each sample we evaluate the two information matrices at the full-band estimate of $\rho$. + +Under the null hypothesis, the data come from $x_t = 0.9 x_{t-1} + e_t$. + +Under the alternatives, we add the seasonal component of {doc}`approximation_errors`, which we call $w_t$ here because $s$ denotes Hausman and McFadden's share: $(1 + \varphi L + \varphi^2 L^2 + \varphi^3 L^3) w_t = \eta_t$, with $\eta_t$ white noise and $\varphi = 0.98$. + +We scale $\eta_t$ so that the variance of $w_t$ is 0.5, 1, or 2 percent of the variance of $x_t$. + +```{code-cell} ipython3 +T_obs, ρ_x, φ = 400, 0.9, 0.98 +ω_T = 2 * np.pi * np.arange(1, T_obs) / T_obs +z_T = np.exp(-1j * ω_T) + + +def seasonal_keep(ω_set, Δ): + """True outside bands of width Δ centered on π/2, π, and 3π/2.""" + def dist(c): + return np.minimum(np.abs(ω_set - c), 2 * np.pi - np.abs(ω_set - c)) + inside = ((dist(np.pi / 2) < Δ / 2) | (dist(np.pi) < Δ / 2) + | (dist(3 * np.pi / 2) < Δ / 2)) + return ~inside + + +keep_all = np.ones(T_obs - 1, bool) +keep_band = seasonal_keep(ω_T, np.pi / 8) +var_x = 1 / (1 - ρ_x**2) +ω_fine = 2 * np.pi * (np.arange(2**14) + 0.5) / 2**14 +z_fine = np.exp(-1j * ω_fine) +var_w_unit = np.mean(1 / np.abs(1 + φ * z_fine + φ**2 * z_fine**2 + + φ**3 * z_fine**3)**2) + + +def whittle_ar1(I, keep): + """Frequency-domain ML estimate of ρ in an AR(1), over the frequencies in keep.""" + def criterion(ρ): + a2 = np.abs(1 - ρ * z_T[keep])**2 + return np.log(np.mean(I[keep] * a2)) - np.mean(np.log(a2)) + return minimize_scalar(criterion, bounds=(-0.999, 0.999), method="bounded", + options={"xatol": 1e-8}).x + + +def ar1_information(ρ, keep): + """(1/4π) ∫_K ∇log g ∇log g' dω at the Fourier frequencies, θ = (ρ, σ²), σ² = 1.""" + d = np.vstack([2 * (np.cos(ω_T) - ρ) / np.abs(1 - ρ * z_T)**2, + np.ones(T_obs - 1)]) + return 0.5 * (d[:, keep] @ d[:, keep].T) / T_obs + + +def band_test(share, seed, R=1000, burn=200): + rng = np.random.default_rng(seed) + stats, ρ_full, ρ_band = np.empty(R), np.empty(R), np.empty(R) + scale = np.sqrt(share * var_x / var_w_unit) + for r in range(R): + x_ = lfilter([1], [1, -ρ_x], rng.normal(size=T_obs + burn)) + w_ = lfilter([1], [1, φ, φ**2, φ**3], rng.normal(size=T_obs + burn)) + y_ = (x_ + scale * w_)[burn:] + I = np.abs(np.fft.fft(y_ - y_.mean()))[1:]**2 / T_obs + ρ_full[r] = whittle_ar1(I, keep_all) + ρ_band[r] = whittle_ar1(I, keep_band) + V_full = np.linalg.inv(ar1_information(ρ_full[r], keep_all))[0, 0] + V_band = np.linalg.inv(ar1_information(ρ_full[r], keep_band))[0, 0] + stats[r] = T_obs * (ρ_band[r] - ρ_full[r])**2 / (V_band - V_full) + return stats, ρ_full, ρ_band + + +crit_1 = chi2.ppf(0.95, 1) +stats, ρ_full, ρ_band = band_test(0.0, seed=2) +print(f"null: Var(band) = {ρ_band.var():.3e}, Var(full) + Var(band - full) = " + f"{ρ_full.var() + (ρ_band - ρ_full).var():.3e}") +print(f"null: rejection frequency at 5%: {np.mean(stats > crit_1):.3f}") +V_full_0 = np.linalg.inv(ar1_information(ρ_x, keep_all))[0, 0] +V_band_0 = np.linalg.inv(ar1_information(ρ_x, keep_band))[0, 0] +print(f"V_band - V_full = {V_band_0 - V_full_0:.4f}, V_full = {V_full_0:.4f}") + +# the same seed for every share gives common random numbers +simulated_power, band_draws = {}, {} +for share in (0.005, 0.01, 0.02): + stats, ρ_full, ρ_band = band_test(share, seed=3) + simulated_power[share] = np.mean(stats > crit_1) + band_draws[share] = (ρ_full, ρ_band) + print(f"seasonal variance {share:.3f} of Var(x): mean ρ_full = " + f"{ρ_full.mean():.3f}, mean ρ_band = {ρ_band.mean():.3f}, " + f"rejection frequency {simulated_power[share]:.3f}") +``` + +Under the null hypothesis, the simulated variances satisfy Hausman's identity {eq}`st_hausman_pythagoras`, and the test rejects at close to its nominal rate. + +A seasonal component with one or two percent of the variance of $x_t$ pulls the full-band estimate below the band-deleted estimate by enough for the test to reject in most samples; with half a percent, the test rejects in fewer than half of the samples. + +The test is powerful because, for this model, deleting the seasonal bands costs little information about $\rho$, whose information is concentrated at low frequencies: the $(1, 1)$ element of $\mathcal{I}_K(\theta)^{-1} - \mathcal{I}(\theta)^{-1}$ is about 2 percent of the $(1, 1)$ element of $\mathcal{I}(\theta)^{-1}$. + +{ref}`st_ex_power` computes the test's asymptotic power from the distance between the two projections, and {doc}`turbulence_inference` applies the same calculation to two explanations of rising earnings instability. + +## Concluding remarks + +Each specification test in this lecture compares two estimators whose probability limits coincide when the model is correctly specified, and each has no power against a misspecification that leaves the two probability limits equal. + +With the variance held fixed, Wu's statistic is the ratio of the squared lengths of the two legs of a right triangle whose Pythagorean theorem is the one for m-projections onto nested exponential families. + +Hausman's lemma is a Pythagorean theorem in the inner product defined by asymptotic covariances, and it is the local form of the Pythagorean theorem for m-projections when the inefficient estimator is the maximum likelihood estimator of a model that nests the null model. + +In Hausman and McFadden's three-choice example, the likelihood ratio, Lagrange multiplier, and Hausman statistics are $2m$ times a KL divergence and its quadratic approximations in the coordinates $s$, $\log s$, and $\log(1 - s)$. + +In our example, with $T = 400$ quarterly observations, a nonseasonal AR(1) with coefficient $0.9$, and seasonal bands of width $\pi/8$, the test that compares the estimators from all frequencies and from the frequencies outside the seasonal bands rejects in most samples when the seasonal component has at least 1 percent of the variance of the nonseasonal component. + +{doc}`turbulence_inference` compares the projections of a calibrated search model and of data onto an auxiliary statistical model, and {doc}`gallant_tauchen` describes this comparison as indirect inference. + +## Exercises + +```{exercise} +:label: st_ex_iia + +{cite:t}`HausmanMcFadden1984` compute exact rejection probabilities of their tests by enumerating all possible outcomes of a sample of choices. + +In the three-choice example, let the choice probabilities be $p_1 = 0.5$ and $p_2 = p_3 = 0.25$ under the null hypothesis, and let the sample size be $N = 100$. + +1. Conditional on $m = n_2 + n_3$, what is the distribution of $n_2$? Use it to compute the exact probabilities with which the $LR$, $LM$, $H_3$, and $H_2$ statistics exceed the 5 percent critical value of the $\chi^2_1$ distribution. Treat an infinite statistic as a rejection, and ignore the samples with $m = 0$, which have probability $0.5^{100}$. +2. Hausman and McFadden's alternatives are nested logit models in which alternatives 1 and 2 share a nest. With parameter $\lambda$ and $\beta = \log 2$, let $a = \beta/\lambda$, $\Pi_1 = e^a/(e^a + 1)$, and $p = (e^a + 1)^\lambda / (1 + (e^a + 1)^\lambda)$; then $p_1 = \Pi_1 p$, $p_2 = (1 - \Pi_1) p$, and $p_3 = 1 - p$, and $\lambda = 1$ gives the null probabilities. Repeat the calculation for $\lambda = 0.8$ and compare your answers with their Table III.3. +3. Relate the differences among the four tests to {numref}`fig-st-iia`. +``` + +```{solution-start} st_ex_iia +:class: dropdown +``` + +Here is one solution. + +Given $m$, $n_2$ is binomial with $m$ trials and success probability $p_2/(p_2 + p_3)$, and $m$ is binomial with $N$ trials and success probability $p_2 + p_3$. + +All four statistics depend only on $m$ and $n_2$. + +```{code-cell} ipython3 +def iia_statistics(n2, m): + """LR, LM, H3, and H2 for an array of values of n2, given m = n2 + n3.""" + n3 = m - n2 + with np.errstate(divide="ignore", invalid="ignore"): + LR = 2 * (np.where(n2 > 0, n2 * np.log(2 * n2 / m), 0) + + np.where(n3 > 0, n3 * np.log(2 * n3 / m), 0)) + H3 = np.where(n2 > 0, np.log(2 * n2 / m)**2 * m, np.inf) + H2 = np.where(n3 > 0, np.log(2 * n3 / m)**2 * m, np.inf) + LM = (n3 - n2)**2 / m + return np.array([LR, LM, H3, H2]) + + +def rejection_probabilities(p2, p3, N=100, level=0.05): + crit = chi2.ppf(1 - level, 1) + probs = np.zeros(4) + for m in range(1, N + 1): + n2 = np.arange(m + 1) + weights = binom.pmf(m, N, p2 + p3) * binom.pmf(n2, m, p2 / (p2 + p3)) + probs += (iia_statistics(n2, m) > crit) @ weights + return probs + + +def nested_logit(λ, β=np.log(2)): + """Choice probabilities with alternatives 1 and 2 in one nest.""" + a = β / λ + Π_1 = np.exp(a) / (np.exp(a) + 1) + p = (np.exp(a) + 1)**λ / (1 + (np.exp(a) + 1)**λ) + return Π_1 * p, (1 - Π_1) * p, 1 - p + + +for λ in (1.0, 0.8): + p1, p2, p3 = nested_logit(λ) + print(f"λ = {λ}: p = ({p1:.4f}, {p2:.4f}, {p3:.4f}); LR, LM, H3, H2 reject " + f"with probabilities {np.round(rejection_probabilities(p2, p3), 4)}") +``` + +Under the null hypothesis, the exact sizes are $0.050$ for the likelihood ratio test, $0.049$ for the Lagrange multiplier test, and $0.055$ for both Hausman tests; $H_3$ and $H_2$ have the same size because $n_2$ and $n_3$ have the same distribution under the null hypothesis. + +Hausman and McFadden's Table III.3 reports $0.054$ for both Hausman tests at $\lambda = 1$; exact enumeration gives $0.055$, while their entries for $\lambda < 1$ at the 5 percent level agree with exact enumeration to five digits. + +With $\lambda = 0.8$, the powers are $0.135$, $0.134$, $0.193$, and $0.084$, the values in Hausman and McFadden's Table III.3. + +The ranking follows from {numref}`fig-st-iia`. + +Under this alternative $p_2 < p_3$, so most samples have $s < \frac{1}{2}$. + +For $s < \frac{1}{2}$, the quadratic approximation in $\log s$ lies above the KL divergence and the quadratic approximation in $\log(1 - s)$ lies below it, so $H_3$ is larger than $LR$ and $H_2$ is smaller; the quadratic approximation in $\log(1 - s)$ also lies below the one in $s$, so $H_2$ is smaller than $LM$. + +In every sample $LR \ge LM$, by Pinsker's inequality $D(\text{Bern}(s) \| \text{Bern}(\frac{1}{2})) \ge 2(s - \frac{1}{2})^2$: the quadratic approximation in $s$ lies below the KL divergence. + +```{solution-end} +``` + +```{exercise} +:label: st_ex_power + +The power of the band comparison test depends on the distance between the two projections. + +1. For seasonal variance shares $0.005$, $0.01$, and $0.02$, compute the pseudo-true values $\rho^*_{\text{full}}$ and $\rho^*_{\text{band}}$, the AR(1) projections of the process $y_t = x_t + w_t$ with all frequencies and with the seasonal bands deleted. +2. Compute the noncentrality parameter $\nu = T (\rho^*_{\text{band}} - \rho^*_{\text{full}})^2 / (V_{\text{band}} - V_{\text{full}})$, with the variances evaluated at $\rho^*_{\text{full}}$, and the asymptotic power $P(\chi^2_1(\nu) > 3.84)$. +3. Compare the asymptotic powers with the simulated rejection frequencies, and explain the differences. +``` + +```{solution-start} st_ex_power +:class: dropdown +``` + +Here is one solution. + +We compute the projections at the Fourier frequencies of a sample of size $T$, using the spectral density of $y_t$ in place of the periodogram. + +```{code-cell} ipython3 +def spectral_density_y(share): + f_x = 1 / np.abs(1 - ρ_x * z_T)**2 + f_w = 1 / np.abs(1 + φ * z_T + φ**2 * z_T**2 + φ**3 * z_T**3)**2 + return f_x + share * var_x / var_w_unit * f_w + + +projections = {} +print("share ρ*_full ρ*_band ν asymptotic power simulated power") +for share in (0.005, 0.01, 0.02): + f_y = spectral_density_y(share) + ρ_f, ρ_b = whittle_ar1(f_y, keep_all), whittle_ar1(f_y, keep_band) + V_full = np.linalg.inv(ar1_information(ρ_f, keep_all))[0, 0] + V_band = np.linalg.inv(ar1_information(ρ_f, keep_band))[0, 0] + projections[share] = (ρ_f, ρ_b, V_full, V_band) + nc = T_obs * (ρ_b - ρ_f)**2 / (V_band - V_full) + power = ncx2.sf(crit_1, 1, nc) + print(f"{share:5.3f} {ρ_f:8.3f} {ρ_b:8.3f} {nc:7.1f} {power:12.2f} " + f"{simulated_power[share]:17.2f}") +``` + +The asymptotic power rises with the squared distance between the two projections. + +It is close to the simulated power at the smallest and largest shares and too high at the intermediate share. + +The noncentral $\chi^2$ approximation uses the variance of the difference between the two estimators under the null hypothesis. + +The code below compares the simulated mean and standard deviation of that difference with the distance between the projections and with the standard deviation that the null-hypothesis variance implies. + +```{code-cell} ipython3 +print("share mean difference distance SD null SD ratio " + "corr(ρ_full, difference)") +for share in (0.005, 0.01, 0.02): + ρ_f, ρ_b, V_full, V_band = projections[share] + ρ_full, ρ_band = band_draws[share] + difference = ρ_band - ρ_full + sd_null = np.sqrt((V_band - V_full) / T_obs) + print(f"{share:5.3f} {difference.mean():13.4f} {ρ_b - ρ_f:12.4f} " + f"{difference.std():8.4f} {sd_null:7.4f} {difference.std() / sd_null:7.2f} " + f"{np.corrcoef(ρ_full, difference)[0, 1]:12.2f}") +``` + +The mean of the simulated difference is close to the distance between the two projections at every share, but its standard deviation is about 1.5, 2, and 3 times the value that the null-hypothesis variance implies. + +Under these alternatives the AR(1) model is misspecified and Hausman's lemma no longer applies: the simulated correlation between $\hat\rho_{\text{full}}$ and the difference is $-0.34$, $-0.50$, and $-0.67$. + +The full-band estimator uses the periodogram ordinates at the seasonal peaks, whose variances are proportional to the square of the spectral density there; the band-deleted estimator does not use them. + +Those ordinates raise the variance of $\hat\rho_{\text{full}}$ and of the difference, so $V_{\text{band}} - V_{\text{full}}$ understates the variance of the difference. + +The test statistic is then approximately a multiple of a noncentral $\chi^2$ variable with a smaller noncentrality parameter than the approximation uses. + +At the largest share both powers are near one, and at the smallest share the larger spread and the smaller noncentrality roughly offset. + +At the intermediate share the smaller noncentrality dominates, and the approximation overstates the power. + +Hausman and McFadden's example shows the opposite error: "For $\lambda$ less than .9 all the tests have greater exact power than the prediction of the asymptotic approximation." + +Once alternatives are nonlocal, the approximation can err in either direction. + +```{solution-end} +``` diff --git a/lectures/turbulence_inference.md b/lectures/turbulence_inference.md new file mode 100644 index 000000000..c14e43702 --- /dev/null +++ b/lectures/turbulence_inference.md @@ -0,0 +1,1172 @@ +--- +jupytext: + text_representation: + extension: .md + format_name: myst + format_version: 0.13 + jupytext_version: 1.16.4 +kernelspec: + display_name: Python 3 (ipykernel) + language: python + name: python3 +--- + +(turbulence_inference)= +```{raw} jupyter + +``` + +# Turbulence, Earnings Instability, and Indirect Inference + +```{contents} Contents +:depth: 2 +``` + +## Overview + +{cite:t}`LjungqvistSargent1998` and {cite:t}`LjungqvistSargent2008` attribute the persistently high unemployment in Europe after 1980 to an interaction between unemployment benefits tied to past earnings and an increase in what they call **economic turbulence**, the risk of losing skills when a job ends in a layoff. + +To check whether an increase in turbulence is consistent with evidence about earnings in the United States, {cite:t}`LjungqvistSargent1998` generated artificial panels of earnings from the laissez-faire version of their model at two levels of turbulence. + +They applied to those panels the decomposition of earnings into permanent and transitory components that {cite:t}`GottschalkMoffitt1994` had applied to men in the Panel Study of Income Dynamics (PSID) for 1970–78 and 1979–87, and they compared the resulting histograms with Gottschalk and Moffitt's. + +{cite:t}`LjungqvistSargent2008` repeated the check in a richer model, with turbulence parameters $0.1$ and $0.2$ for the two windows. + +{cite:t}`LjungqvistSargent1998` concluded that "an increase in our turbulence parameter spreads the distributions of both components of the Gottschalk-Moffitt decomposition in the direction observed." They added: + +> It is also noteworthy that the increased earnings variability in the more turbulent period in our figure 14b occurs at lower standard deviations than in Gottschalk and Moffitt's findings. In this respect, the increase in economic turbulence in our parameterization of the 1980s falls short of the changes documented for the United States. + +In this lecture we describe their check as a comparison of information projections and make it quantitative for the model of {cite:t}`LjungqvistSargent1998`. + +* Gottschalk and Moffitt's decomposition is the m-projection, in the sense of {doc}`information_projections`, of the distribution of a man's nine annual log earnings in a balanced panel onto a Gaussian random-effects model. +* Ljungqvist and Sargent's check compares the data's histograms of men's averages and standard deviations with their model's at two values of the turbulence parameter; the second moments of those histograms are the parameters of the projections. Computing the model's projection at every value of that parameter gives what {cite:t}`GourierouxMonfortRenault1993` call the binding function, and choosing the parameter to make the two projections agree is the method of indirect inference that {doc}`gallant_tauchen` describes. +* With the 1970–78 turbulence parameter held at Ljungqvist and Sargent's value of $0.02$, no value of the 1979–87 parameter lets the laissez-faire model deliver more than about one fifth of the increase in the permanent variance that Gottschalk and Moffitt measured, or more than about 45 percent of the increase in the transitory variance. With both parameters free, the bounds are about one third and one half. +* These bounds depend on the range of skills and on the speed of skill transitions. Doubling the range alone lets turbulence deliver about 46 percent of the increase in the permanent variance and nearly all of the increase in the transitory variance; doubling the transition probabilities as well brings the permanent share back to about one fifth. +* An increase in the layoff rate moves Gottschalk and Moffitt's two statistics in the same direction as an increase in turbulence, and in a sample of Gottschalk and Moffitt's size the two statistics barely distinguish the two explanations. +* The covariance-structure model of {cite:t}`MoffittGottschalk2011`, a second auxiliary model, attributes the earnings instability that turbulence creates almost entirely to a transitory component, while Gottschalk and Moffitt's decomposition attributes about half of it to the permanent component. + +The lecture proceeds as follows. + +* {ref}`ti_model_section` describes the laissez-faire economy of {cite:t}`LjungqvistSargent1998` and reproduces their steady-state statistics. +* {ref}`ti_gm_section` describes Gottschalk and Moffitt's decomposition as an information projection. +* {ref}`ti_check_section` reproduces Ljungqvist and Sargent's check and computes the binding function. +* {ref}`ti_ident_section` compares turbulence with a higher layoff rate. +* {ref}`ti_mg_section` describes a second auxiliary model. + +The lecture builds on {doc}`information_projections`, {doc}`gallant_tauchen`, and {doc}`specification_tests`. + +{doc}`mccall_model` and {doc}`mccall_model_with_separation` describe simpler search models. + +We use the following imports. + +```{code-cell} ipython3 +import numpy as np +import matplotlib.pyplot as plt +from collections import namedtuple +from scipy.stats import norm, chi2, ncx2 +from scipy.optimize import minimize +``` + +(ti_model_section)= +## Laissez-faire economy + +### Workers + +{cite:t}`LjungqvistSargent1998` study a continuum of risk-neutral workers. + +A period is two weeks. + +Each worker dies with probability $\alpha$ between periods and maximizes $E_t \sum_{i=0}^\infty \beta^i (1 - \alpha)^i y_{t+i}$, where $y_t$ is income net of the disutility of searching. + +A newborn worker starts unemployed with the lowest skill level. + +A worker's skill $h$ takes one of 21 values evenly spaced on $[1, 2]$. + +An employed worker earns $w h$, where $w$ is the wage per unit of skill on the job. + +At the beginning of each period, an employed worker is laid off with probability $\lambda$. + +A worker who is not laid off gains one skill level with probability $0.1$ and keeps the wage $w$ until a layoff, a quit, or death. + +The skill of an unemployed worker falls by one level with probability $0.2$ each period, and the lowest level is absorbing. + +An unemployed worker chooses a search intensity $s \in [0, 1]$ at a disutility $c(s) = 0.5 s$, and receives one wage offer next period with probability $\pi(s) = s^{0.3}$. + +Wage offers are drawn from a normal distribution with mean $0.5$ and variance $0.1$, truncated to $[0, 1]$. + +Ljungqvist and Sargent define turbulence as follows: + +> Economic turbulence is defined in terms of the mean and variance of skill losses associated with layoffs. We now let the skills of a newly laid-off worker be distributed according to the left half of a normal distribution, with the range starting at the lowest possible skill level and ending at the worker's skill level before the layoff. + +They obtain the distribution by taking the left half of a normal distribution centered on $0.5$ and confined to $[0, 1]$, stretching it over the skill levels from the lowest to the level that the worker held before the layoff, and normalizing it. + +The variance of that normal distribution indexes turbulence; we call it the **turbulence parameter**. + +When the turbulence parameter is zero, a laid-off worker keeps the skill level held before the layoff. + +Let $\mu_e(h, h')$, $\mu_u(h, h')$, and $\mu_l(h, h')$ be the skill transition probabilities of an employed worker, an unemployed worker, and a worker who has just been laid off. + +The laissez-faire economy has no unemployment benefits and no taxes. + +The value $V(w, h)$ of a worker with skill $h$ who holds or is offered a job with wage $w$, and the value $V_u(h)$ of an unemployed worker, satisfy + +$$ +V(w, h) = \max \left\{ w h + (1 - \alpha)\beta \left[ (1 - \lambda) \sum_{h'} \mu_e(h, h') V(w, h') + \lambda \sum_{h'} \mu_l(h, h') V_u(h') \right], \; V_u(h) \right\} +$$ + +and + +$$ +V_u(h) = \max_{s \in [0, 1]} \left\{ -c(s) + (1 - \alpha)\beta \sum_{h'} \mu_u(h, h') \left[ (1 - \pi(s)) V_u(h') + \pi(s) \int V(w, h') \, dF(w) \right] \right\} . +$$ + +The second argument of the max in $V(w, h)$ is the option to reject the offer or to quit. + +Let $G(h) = (1 - \alpha)\beta \sum_{h'} \mu_u(h, h') [\int V(w, h') \, dF(w) - V_u(h')]$ be the expected gain from an offer. + +The first-order condition for search intensity gives $s(h) = \min\{1, (0.6 \, G(h))^{1/0.7}\}$. + +In the laissez-faire economy the bound binds, and $s(h) = 1$ at every skill level, as Ljungqvist and Sargent report. + +Ljungqvist and Sargent set $\beta = 0.9985$, an annual interest rate of 4 percent, $\alpha = 0.0009$, an expected working life of 42.7 years, and $\lambda = 0.009$, an expected 4.3 years of employment before a layoff. + +### Computation + +The function `create_model` stores the primitives. + +Its arguments `h_max`, `up`, and `down` set the range of skills and the probabilities of skill gains and losses, which we change in an exercise. + +```{code-cell} ipython3 +Model = namedtuple("Model", ("β", "α", "λ", "turbulence", "h_grid", "w_grid", + "f_w", "μ_e", "μ_u", "μ_l")) + + +def layoff_matrix(n_h, turbulence): + """Skill transitions at a layoff: the left half of a normal distribution + centered on 0.5, stretched over the skill levels up to the current one.""" + μ_l = np.eye(n_h) + if turbulence > 0: + for j in range(1, n_h): + x = 0.5 * np.arange(j + 1) / j + weights = np.exp(-(x - 0.5)**2 / (2 * turbulence)) + μ_l[j] = 0.0 + μ_l[j, :j + 1] = weights / weights.sum() + return μ_l + + +def create_model(turbulence=0.0, β=0.9985, α=0.0009, λ=0.009, + h_max=2.0, up=0.1, down=0.2, n_h=21, n_w=101): + h_grid = np.linspace(1, h_max, n_h) + w_grid = np.linspace(0, 1, n_w) + pdf = norm.pdf(w_grid, 0.5, np.sqrt(0.1)) + μ_e = np.eye(n_h) * (1 - up) + μ_e[np.arange(n_h - 1), np.arange(1, n_h)] = up + μ_e[-1, -1] = 1.0 + μ_u = np.eye(n_h) * (1 - down) + μ_u[np.arange(1, n_h), np.arange(n_h - 1)] = down + μ_u[0, 0] = 1.0 + return Model(β, α, λ, turbulence, h_grid, w_grid, pdf / pdf.sum(), + μ_e, μ_u, layoff_matrix(n_h, turbulence)) +``` + +The figure shows the distribution of skills after a layoff for a worker who had the highest skill level, for the two values of the turbulence parameter that Ljungqvist and Sargent use to represent 1970–78 and 1979–87. + +```{code-cell} ipython3 +--- +mystnb: + figure: + caption: Distribution of skill after a layoff for a worker with the highest skill + name: fig-ti-layoff +--- +fig, ax = plt.subplots() +for v in (0.02, 0.04): + m = create_model(turbulence=v) + ax.plot(m.h_grid, m.μ_l[-1], "o-", label=f"turbulence parameter {v}") +ax.set_xlabel("skill after the layoff") +ax.set_ylabel("probability") +ax.legend() +plt.show() +``` + +We solve the Bellman equations by value iteration and return the acceptance decisions and search intensities. + +```{code-cell} ipython3 +def solve_model(m, tol=1e-9, max_iter=100_000): + δ = (1 - m.α) * m.β + earnings = np.outer(m.w_grid, m.h_grid) + V = np.zeros_like(earnings) + V_u = np.zeros(len(m.h_grid)) + for _ in range(max_iter): + W = earnings + δ * ((1 - m.λ) * V @ m.μ_e.T + + m.λ * (m.μ_l @ V_u)[None, :]) + V_new = np.maximum(W, V_u[None, :]) + gain = δ * m.μ_u @ (m.f_w @ V - V_u) + s = np.clip((0.6 * np.maximum(gain, 0))**(1 / 0.7), 0, 1) + V_u_new = -0.5 * s + δ * m.μ_u @ V_u + s**0.3 * gain + error = max(np.abs(V_new - V).max(), np.abs(V_u_new - V_u).max()) + V, V_u = V_new, V_u_new + if error < tol: + break + accept = W >= V_u[None, :] # accept[w, h] + return accept, s +``` + +The next function computes the stationary distribution of workers across employment states, wages, and skills, with newborn workers replacing those who die. + +From it we compute the unemployment rate, the average duration of unemployment, and the average earnings of employed workers, which Ljungqvist and Sargent call average productivity. + +```{code-cell} ipython3 +def steady_state(m, accept, s, tol=1e-12, max_iter=200_000): + n_w, n_h = len(m.w_grid), len(m.h_grid) + E, U = np.zeros((n_w, n_h)), np.zeros(n_h) + U[0] = 1.0 + survive = 1 - m.α + for _ in range(max_iter): + E_kept = survive * (1 - m.λ) * E @ m.μ_e + quits = np.where(accept, 0.0, E_kept).sum(axis=0) + laid_off = survive * m.λ * E.sum(axis=0) @ m.μ_l + offers = survive * (U * s**0.3) @ m.μ_u + hires = np.outer(m.f_w, offers) * accept + E_new = np.where(accept, E_kept, 0.0) + hires + U_new = survive * U @ m.μ_u - hires.sum(axis=0) + quits + laid_off + U_new[0] += m.α + error = np.abs(E_new - E).max() + np.abs(U_new - U).max() + E, U = E_new, U_new + if error < tol: + break + inflow = quits.sum() + laid_off.sum() + m.α + earnings = np.outer(m.w_grid, m.h_grid) + return {"unemployment rate": U.sum(), + "duration (weeks)": 2 * U.sum() / inflow, + "average productivity": (E * earnings).sum() / E.sum()} +``` + +Table 5 of {cite:t}`LjungqvistSargent1998` reports these statistics for the laissez-faire economy at four values of the turbulence parameter: unemployment rates of 6.28, 5.81, 5.77, and 5.73 percent; average durations of 11.8, 10.6, 10.6, and 10.7 weeks; and average productivities of 1.659, 1.552, 1.520, and 1.496. + +```{code-cell} ipython3 +print("turbulence unemployment duration productivity search intensity") +for v in (0.0, 0.02, 0.03, 0.04): + m = create_model(turbulence=v) + accept, s = solve_model(m) + stats = steady_state(m, accept, s) + print(f"{v:9.2f} {100 * stats['unemployment rate']:12.2f}% " + f"{stats['duration (weeks)']:10.1f} {stats['average productivity']:13.3f}" + f" {s.min():.2f} to {s.max():.2f}") +``` + +Our computations agree with their table to within 0.11 percentage points of unemployment, 0.2 weeks of duration, and 0.002 units of productivity, and search intensity equals one at every skill level. + +In the laissez-faire economy, turbulence lowers productivity, because laid-off workers lose skills, and it barely changes unemployment. + +The welfare state of {cite:t}`LjungqvistSargent1998`, in which benefits are tied to past earnings, responds very differently: its unemployment rate rises from 6.95 to 14.87 percent as the turbulence parameter rises from 0 to 0.04. + +### Artificial panels + +{cite:t}`LjungqvistSargent1998` describe how they generated their panels: + +> For the laissez-faire economy, we generated artificial panels of length 9 years with 10,000 individuals for two different subperiods: relatively tranquil economic times and more turbulent times as indexed in table 5 by variances .02 and .04, respectively. The former panel is meant to represent the period 1970–78 in the Gottschalk-Moffitt study, and the latter panel would then correspond to the period 1979–87. For both panels, we use as initial conditions the equilibrium distribution of workers who have been in the labor force for 20 years. + +We draw such initial conditions by simulating newborn workers for 20 years, conditional on their survival. + +The function below records two-week earnings, employment, layoffs, and skills. + +```{code-cell} ipython3 +def draw_next(cum_rows, rows, u): + """Draw the next state for each worker from rows of cumulative probabilities.""" + return (u[:, None] > cum_rows[rows]).sum(axis=1) + + +def simulate_workers(m, accept, s, N, T, T_burn, seed=0): + rng = np.random.default_rng(seed) + cum_e, cum_u, cum_l = (np.cumsum(μ, axis=1) for μ in (m.μ_e, m.μ_u, m.μ_l)) + cum_w = np.cumsum(m.f_w) + n_w = len(m.w_grid) + emp, wi, hj = np.zeros(N, bool), np.zeros(N, int), np.zeros(N, int) + record = {"earn": np.zeros((N, T)), "emp": np.zeros((N, T), bool), + "laid": np.zeros((N, T), bool), "h": np.zeros((N, T), int)} + for t in range(T_burn + T): + u = rng.random((N, 4)) + new_emp, new_wi, new_hj = emp.copy(), wi.copy(), hj.copy() + laid = emp & (u[:, 0] < m.λ) + kept = emp & ~laid + new_hj[laid] = draw_next(cum_l, hj[laid], u[laid, 1]) + new_emp[laid] = False + new_hj[kept] = draw_next(cum_e, hj[kept], u[kept, 1]) + new_emp[kept & ~accept[wi, new_hj]] = False # quits + idle = ~emp + new_hj[idle] = draw_next(cum_u, hj[idle], u[idle, 1]) + offer = np.minimum((u[:, 2][:, None] > cum_w).sum(axis=1), n_w - 1) + hired = idle & (u[:, 3] < s[hj]**0.3) & accept[offer, new_hj] + new_emp[hired], new_wi[hired] = True, offer[hired] + emp, wi, hj = new_emp, new_wi, new_hj + if t >= T_burn: + k = t - T_burn + record["earn"][:, k] = np.where(emp, m.w_grid[wi] * m.h_grid[hj], 0.0) + record["emp"][:, k], record["laid"][:, k], record["h"][:, k] = emp, laid, hj + return record + + +def log_annual_earnings(record, years=9): + """Log annual earnings with year means removed, for workers with + positive earnings in every year.""" + annual = record["earn"].reshape(len(record["earn"]), years, 26).sum(axis=2) + positive = (annual > 0).all(axis=1) + y = np.log(annual[positive]) + return y - y.mean(axis=0), positive.mean() + + +def artificial_panel(turbulence, N=10_000, seed=0, **kwargs): + m = create_model(turbulence=turbulence, **kwargs) + record = simulate_workers(m, *solve_model(m), N=N, T=9 * 26, + T_burn=20 * 26, seed=seed) + return log_annual_earnings(record) +``` + +Gottschalk and Moffitt removed a common age profile from log earnings before decomposing them. + +All workers in an artificial panel have the same experience, so we remove only the mean of log earnings in each year. + +A worker who is unemployed for a whole year has no log earnings, and we drop such workers, about a quarter of one percent of the panel. + +(ti_gm_section)= +## Gottschalk and Moffitt's decomposition + +### Definitions + +{cite:t}`GottschalkMoffitt1994` study white men in the PSID who were aged 20 to 59, were household heads and not students, and had positive wage and salary earnings. + +They trim the top and bottom 1 percent of the earnings distribution within age-education-year cells. + +They regress log real annual earnings on a quartic in age, separately for 1970–78 and 1979–87, and decompose the residuals $y_{it}$ of man $i$ in year $t$ as $y_{it} = \mu_i + \nu_{it}$. + +They take as the permanent component of man $i$ the average $\bar y_i$ of $y_{it}$ over the $T_i$ years in which the man appears in a window, and as the transitory component the deviations $y_{it} - \bar y_i$. + +Their appendix gives the formulas + +$$ +\sigma^2_\nu = \frac{1}{N} \sum_{i=1}^N \frac{1}{T_i - 1} \sum_{t=1}^{T_i} (y_{it} - \bar y_i)^2 , +\qquad +\sigma^2_\mu = \frac{1}{N - 1} \sum_{i=1}^N (\bar y_i - \bar y)^2 - \frac{\sigma^2_\nu}{\bar T} , +$$ (ti_gm) + +where $\bar y$ is the mean of $y_{it}$ over all men and years and $\bar T$ is the average of $T_i$. + +The transitory variance $\sigma^2_\nu$ is the average of the men's own variances of earnings around their averages. + +The permanent variance $\sigma^2_\mu$ is the variance of the men's averages, less the part of that variance that the transitory components contribute. + +Their Table 1 reports that the permanent variance rose from $0.201$ in 1970–78 to $0.284$ in 1979–87, and that the transitory variance rose from $0.104$ to $0.148$. + +They write that "fully one-third of the widening of the earnings distribution has resulted from a rise in the instability of earnings." + +The function `gm_decomposition` computes formulas {eq}`ti_gm`, and the function `trim` drops the top and bottom 1 percent of each year's log earnings, which makes a panel unbalanced. + +```{code-cell} ipython3 +gm_data = {"1970-78": np.array([0.201, 0.104]), + "1979-87": np.array([0.284, 0.148])} +gm_change = gm_data["1979-87"] - gm_data["1970-78"] + + +def gm_decomposition(y, keep=None): + """Permanent and transitory variances, formulas (ti_gm); keep marks the + years in which each man appears.""" + if keep is None: + keep = np.ones(y.shape, bool) + T_i = keep.sum(axis=1) + y_bar_i = np.where(keep, y, 0).sum(axis=1) / T_i + σ2_ν = (np.where(keep, (y - y_bar_i[:, None])**2, 0).sum(axis=1) + / (T_i - 1)).mean() + σ2_μ = ((y_bar_i - y[keep].mean())**2).sum() / (len(y) - 1) - σ2_ν / T_i.mean() + return np.array([σ2_μ, σ2_ν]) + + +def trim(y, q=0.01): + """Drop the top and bottom fraction q of each year's log earnings, remove + the year means again, and keep the men who remain in at least two years.""" + lo, hi = np.quantile(y, [q, 1 - q], axis=0) + keep = (y >= lo) & (y <= hi) + y = y - np.where(keep, y, 0).sum(axis=0) / keep.sum(axis=0) + two_years = keep.sum(axis=1) >= 2 + return y[two_years], keep[two_years] +``` + +### Decomposition as information projection + +Let $y_i = (y_{i1}, \ldots, y_{iT})$ be the vector of a man's log earnings in a window of $T$ years, and suppose that every man appears in every year of the window, as in a balanced panel. + +The **random-effects model** says that $y_{it} = m + a_i + e_{it}$, where $a_i \sim N(0, \sigma^2_\mu)$ and the $e_{it} \sim N(0, \sigma^2_\nu)$ are independent of each other and over time. + +Under this model $y_i$ is normal with mean $m \mathbf{1}$ and covariance matrix $\sigma^2_\mu \mathbf{1}\mathbf{1}^\top + \sigma^2_\nu I$, where $\mathbf{1}$ is a vector of ones. + +The inverse of that covariance matrix is a linear combination of $I$ and $\mathbf{1}\mathbf{1}^\top$, so the random-effects model is an exponential family. + +Its sufficient statistics are the average $\bar y_i$, its square $\bar y_i^2$, and the within sum of squares $W_i = \sum_t (y_{it} - \bar y_i)^2$. + +In the notation of {doc}`approximation_errors`, $T \bar y_i^2$ is the periodogram of a man's earnings at frequency zero, and by Parseval's identity $W_i$ is the sum of the periodogram ordinates at the other $T - 1$ Fourier frequencies $2\pi j / T$. + +The model's distribution of earnings is discrete, so its KL divergence from every normal distribution is infinite, as {doc}`information_projections` notes. + +The proof of {prf:ref}`ip_thm_m_projection` applies instead to the cross-entropy $-E[\log q_\theta(y_i)]$, which differs from the KL divergence by the entropy of $y_i$ whenever $y_i$ has a density. + +For any distribution of $y_i$ with a nonsingular covariance matrix whose average off-diagonal element is nonnegative, the parameters that minimize the cross-entropy match the expectations of the sufficient statistics, which sets $m = E[\bar y_i]$ and + +$$ +E[W_i] = (T - 1) \sigma^2_\nu , +\qquad +T \operatorname{Var}(\bar y_i) = T \sigma^2_\mu + \sigma^2_\nu . +$$ + +Solving gives $\sigma^2_\nu = E[W_i]/(T - 1)$ and $\sigma^2_\mu = \operatorname{Var}(\bar y_i) - \sigma^2_\nu / T$. + +We call this minimizer the m-projection of the distribution of $y_i$ onto the random-effects model. + +The projection sets $\sigma^2_\nu$ equal to the average expected periodogram at the nonzero Fourier frequencies, and, for $y_i$ with mean zero, as in our year-demeaned panels, $T\sigma^2_\mu + \sigma^2_\nu$ equal to the expected periodogram at frequency zero. + +**For a balanced panel, Gottschalk and Moffitt's permanent and transitory variances are the parameters of the m-projection of the distribution of a man's earnings onto the random-effects model**: formulas {eq}`ti_gm` are the expressions above with the sample of men in place of the population, apart from the divisor $N - 1$ in the variance of the averages. + +The projection is defined whether or not the random-effects model describes the data. + +Gottschalk and Moffitt report correlations of 0.14 and 0.18 between successive transitory components and conclude that the components are "largely uncorrelated." + +Under the random-effects model, the correlation between successive deviations $y_{it} - \bar y_i$ is $-1/(T - 1)$, or $-0.125$ when $T = 9$. + +Gottschalk and Moffitt's correlations therefore lie about $0.3$ above what serially uncorrelated transitory components would produce. + +The cross-entropy of a normal distribution depends on the distribution of $y_i$ only through its mean and its covariance matrix $S$, so we can compute the projection by minimizing the KL divergence of $N(0, S)$ from the random-effects model. + +The projection's parameters are linear functions of $S$: + +$$ +\sigma^2_\nu = \frac{\operatorname{tr} S - \mathbf{1}^\top S \mathbf{1} / T}{T - 1} , +\qquad +\sigma^2_\mu = \frac{\mathbf{1}^\top S \mathbf{1}}{T^2} - \frac{\sigma^2_\nu}{T} . +$$ + +{ref}`ti_ex_projection` derives these formulas. + +So if log earnings are the sum of two independent components, the projection of the sum is the sum of the projections. + +The random-effects covariance matrices and their inverses lie in the same linear space, spanned by $I$ and $\mathbf{1}\mathbf{1}^\top$. + +The sufficient statistics are quadratic forms $y_i^\top A y_i$ with $A$ in that space, so matching their expectations makes $S - \Sigma$ orthogonal to the space in the trace inner product. + +Since $\Sigma$ lies in the space, the m-projection coincides with the least squares projection of $S$ onto it, which sets $\sigma^2_\mu$ equal to the average off-diagonal element of $S$ and $\sigma^2_\mu + \sigma^2_\nu$ equal to the average diagonal element. + +A linear space of covariance matrices does not by itself make the two projections coincide: the symmetric Toeplitz matrices, which include the covariance matrices of stationary processes, form a linear space that does not contain their inverses, and the two projections onto it differ. + +The code below checks both characterizations, and the periodogram identities, for an artificial panel. + +```{code-cell} ipython3 +def random_effects_cov(θ, T=9): + σ2_μ, σ2_ν = θ + return σ2_μ * np.ones((T, T)) + σ2_ν * np.eye(T) + + +def gaussian_kl(S, Σ): + """KL divergence of N(0, S) from N(0, Σ).""" + M = np.linalg.solve(Σ, S) + sign, logdet = np.linalg.slogdet(M) + return 0.5 * (np.trace(M) - len(S) - logdet) if sign > 0 else np.inf + + +def euclidean(S, Σ): + """Sum of squared differences of the distinct elements of S and Σ.""" + upper = np.triu_indices(len(S)) + return np.sum((S[upper] - Σ[upper])**2) + + +y02, kept = artificial_panel(0.02) +S = np.cov(y02.T) +for name, distance in (("KL", gaussian_kl), ("least squares", euclidean)): + res = minimize(lambda p: distance(S, random_effects_cov(np.exp(p))), + np.log([0.02, 0.05]), method="Nelder-Mead", + options={"xatol": 1e-10, "fatol": 1e-14}) + print(f"{name:14} projection: {np.round(np.exp(res.x), 5)}") +print(f"formulas (ti_gm): {np.round(gm_decomposition(y02), 5)}") +print(f"fraction of workers kept: {kept:.4f}") + +T = y02.shape[1] +periodogram = np.abs(np.fft.fft(y02, axis=1))**2 / T +W = ((y02 - y02.mean(axis=1, keepdims=True))**2).sum(axis=1) +print("largest Parseval discrepancies:", + np.abs(periodogram[:, 0] - T * y02.mean(axis=1)**2).max(), + np.abs(periodogram[:, 1:].sum(axis=1) - W).max()) +``` + +For a stationary process with spectral density $f$, in the convention of {doc}`approximation_errors`, the formulas in $S$ give + +$$ +\sigma^2_\mu = \frac{1}{2\pi} \int_{-\pi}^{\pi} f(\omega) \, \frac{K_T(\omega) - 1}{T - 1} \, d\omega , +\qquad +\sigma^2_\nu = \frac{1}{2\pi} \int_{-\pi}^{\pi} f(\omega) \, \frac{T - K_T(\omega)}{T - 1} \, d\omega , +$$ (ti_fejer) + +where $K_T(\omega) = \sin^2(T\omega/2) / (T \sin^2(\omega/2))$ is the Fejér kernel, the periodogram at frequency $\omega$ of a sequence of $T$ ones; the expected periodogram at frequency zero is $\frac{1}{2\pi}\int_{-\pi}^{\pi} f(\omega) K_T(\omega) \, d\omega$. + +The weight on $f$ in $\sigma^2_\mu$ equals one at frequency zero and integrates to zero, so $\sigma^2_\mu$ measures the excess of the spectral density near frequency zero over its average. + +With $T = 9$, about nine tenths of the Fejér kernel's weight lies at frequencies $|\omega| < 2\pi/T$. + +Let's check {eq}`ti_fejer` against the formulas in $S$ for two autoregressions. + +```{code-cell} ipython3 +n_grid = 2**14 +ω = 2 * np.pi * (np.arange(n_grid) + 0.5) / n_grid - np.pi +K = np.sin(T * ω / 2)**2 / (T * np.sin(ω / 2)**2) +for ρ in (0.7, -0.4): + f = 1 / np.abs(1 - ρ * np.exp(-1j * ω))**2 + lags = np.abs(np.subtract.outer(np.arange(T), np.arange(T))) + S_ar = ρ**lags / (1 - ρ**2) + σ2_ν = (np.trace(S_ar) - S_ar.sum() / T) / (T - 1) + print(f"ρ = {ρ:4}: Fejér form {np.mean(f * (K - 1)) / (T - 1):.6f}, " + f"{np.mean(f * (T - K)) / (T - 1):.6f}; " + f"formulas in S {S_ar.sum() / T**2 - σ2_ν / T:.6f}, {σ2_ν:.6f}") +print(f"share of the Fejér kernel's weight at |ω| < 2π/T: " + f"{np.mean(K * (np.abs(ω) < 2 * np.pi / T)):.3f}") +``` + +For the negatively autocorrelated process the formulas give a negative $\sigma^2_\mu$, because its spectral density lies below its average near frequency zero; its m-projection onto the random-effects model lies on the boundary $\sigma^2_\mu = 0$. + +The linearity of the projection in $S$ justifies comparing changes between windows even though the model and the data differ in levels. + +The model's workers are identical when they enter the labor force, and the model has no measurement error, so its permanent and transitory variances are far below Gottschalk and Moffitt's. + +Suppose that the data's log earnings are the sum of a component that the model describes and an independent component whose covariance matrix is the same in the two windows. + +Then the change in the data's projection from 1970–78 to 1979–87 equals the change in the projection of the component that the model describes. + +Hansen and Sargent's ideal seasonal adjustment in {doc}`approximation_errors` follows the same strategy: it compares a model that omits a feature of the data with the data only where the omitted feature drops out. + +There the comparison uses the frequencies outside the seasonal bands; here it uses the changes between windows. + +Gottschalk and Moffitt's evidence supports the maintained assumption more for the transitory variance than for the permanent variance. + +Measurement error raises their transitory variances, and they write that "the issue is whether this bias has changed over time. We know of no evidence that it has." + +They write that "an increase in the price of 'skill' may be a satisfactory explanation for changes in the dispersion of permanent wages," and Ljungqvist and Sargent's workers are ex ante identical, so their model has no education or other characteristic fixed at entry whose price could rise. + +(ti_check_section)= +## Ljungqvist and Sargent's check + +### Histograms + +{cite:t}`LjungqvistSargent1998` use Gottschalk and Moffitt's evidence "partly to inspire and partly to check our model." + +Their check compares histograms of the men's averages $\bar y_i$ and of their standard deviations around those averages. + +The figure below plots Gottschalk and Moffitt's histograms, which we read approximately from their Figures 2 and 4, above the histograms of our artificial panels for the turbulence parameters $0.02$ and $0.04$. + +```{code-cell} ipython3 +y04, _ = artificial_panel(0.04) + +gm_fig2_bins = np.arange(-1.75, 1.01, 0.25) +gm_fig2 = {"1970-78": [0.7, 0.4, 1.1, 2.9, 5.6, 11.3, 16.9, 21.5, 23.2, 10.9, 4.1, 1.3], + "1979-87": [1.1, 1.05, 1.95, 3.05, 6.2, 10.4, 15.1, 19.7, 18.7, 13.95, + 6.4, 2.0]} +gm_fig4_bins = np.arange(0.1, 1.21, 0.1) +gm_fig4 = {"1970-78": [42.4, 22.8, 12.6, 8.1, 6.05, 2.55, 1.65, 1.15, 1.0, 0.75, + 0.25, 0.45], + "1979-87": [36.4, 22.25, 12.75, 7.8, 6.3, 4.45, 3.05, 2.3, 1.4, 0.7, + 0.9, 1.15]} + + +def percent_histogram(x, centers): + width = centers[1] - centers[0] + edges = np.append(centers - width / 2, centers[-1] + width / 2) + return 100 * np.histogram(np.clip(x, edges[0], edges[-1] - 1e-9), edges)[0] / len(x) + + +model_mean_bins = np.arange(-0.5, 0.51, 0.1) +model_sd_bins = np.arange(0.1, 0.71, 0.1) +``` + +```{code-cell} ipython3 +--- +mystnb: + figure: + caption: Distributions of men's average log earnings (left) and of their standard deviations of earnings around those averages (right), in the PSID (top, read from Gottschalk and Moffitt's Figures 2 and 4) and in artificial panels from the laissez-faire economy (bottom) + name: fig-ti-histograms +--- +fig, axes = plt.subplots(2, 2, figsize=(11, 7)) +for ax, bins, data, title in ((axes[0, 0], gm_fig2_bins, gm_fig2, "PSID, average"), + (axes[0, 1], gm_fig4_bins, gm_fig4, + "PSID, standard deviation")): + width = bins[1] - bins[0] + ax.bar(bins - width / 5, data["1970-78"], width=0.4 * width, label="1970–78") + ax.bar(bins + width / 5, data["1979-87"], width=0.4 * width, label="1979–87") + ax.set_title(title) + ax.set_ylabel("percent") + ax.legend() + +for ax, bins, stat, title in ( + (axes[1, 0], model_mean_bins, lambda y: y.mean(axis=1), "model, average"), + (axes[1, 1], model_sd_bins, lambda y: y.std(axis=1, ddof=1), + "model, standard deviation")): + width = bins[1] - bins[0] + for shift, y, label in ((-1, y02, "turbulence 0.02"), (1, y04, "turbulence 0.04")): + ax.bar(bins + shift * width / 5, percent_histogram(stat(y), bins), + width=0.4 * width, label=label) + ax.set_title(title) + ax.set_ylabel("percent") + ax.legend() +plt.tight_layout() +plt.show() +``` + +Figure 14 of {cite:t}`LjungqvistSargent1998` plots the same histograms for their own panels. + +We read the heights of its bars approximately and compare them with ours. + +```{code-cell} ipython3 +ls_fig14 = {"average": {0.02: [0.5, 1.7, 3.9, 9.0, 16.2, 27.0, 29.7, 10.8, 1.2, 0, 0], + 0.04: [0.8, 2.3, 5.3, 10.9, 15.0, 22.2, 25.3, 15.0, 3.4, 0, 0]}, + "standard deviation": {0.02: [44.8, 33.2, 14.5, 4.8, 1.9, 0.4, 0.3], + 0.04: [38.4, 35.3, 17.5, 5.3, 2.1, 0.7, 0.3]}} +for v, y in ((0.02, y02), (0.04, y04)): + gaps = [np.abs(percent_histogram(y.mean(axis=1), model_mean_bins) + - ls_fig14["average"][v]).max(), + np.abs(percent_histogram(y.std(axis=1, ddof=1), model_sd_bins) + - ls_fig14["standard deviation"][v]).max()] + print(f"turbulence {v}: largest gaps from their Figure 14, in percentage points, " + f"{gaps[0]:.1f} (averages) and {gaps[1]:.1f} (standard deviations)") +``` + +Our histograms reproduce theirs to within about one percentage point in every bin. + +Raising the turbulence parameter from $0.02$ to $0.04$ spreads both distributions in the direction that Gottschalk and Moffitt found. + +Ljungqvist and Sargent pointed out that the model's distribution of averages spans a smaller range than the data's, because their workers are ex ante identical, and that the increase in the model's standard deviations occurs at lower standard deviations than in the data. + +### Binding function + +Gottschalk and Moffitt's decomposition of the model's earnings at turbulence parameter $v$ is a pair of numbers $b(v) = (\sigma^2_\mu(v), \sigma^2_\nu(v))$, the parameters of the m-projection of the model's distribution of earnings onto the random-effects model. + +{cite:t}`GourierouxMonfortRenault1993` call the map $v \mapsto b(v)$ the **binding function**; {doc}`gallant_tauchen` writes it $\theta^0(\rho)$. + +Ljungqvist and Sargent computed the distributions of $\bar y_i$ and of the men's standard deviations at $0.02$ and $0.04$, whose second moments determine $b(0.02)$ and $b(0.04)$, and compared them with the distributions in the data for 1970–78 and 1979–87. + +Indirect inference, as {doc}`gallant_tauchen` describes it, chooses parameter values that make the model's projection agree with the data's projection. + +We compare the change $b(v) - b(0.02)$ with the change that Gottschalk and Moffitt measured, because Ljungqvist and Sargent assign the turbulence parameter $0.02$ to 1970–78 and because the levels of the two projections differ for the reasons given above. + +We estimate the binding function by simulating a panel of 10,000 workers at each point of a grid of turbulence parameters, using the same random numbers at every point. + +```{code-cell} ipython3 +v_grid = np.array([0.0, 0.01, 0.02, 0.03, 0.04, 0.06, 0.1, 0.2, 1.0]) +binding = np.array([gm_decomposition(artificial_panel(v)[0]) for v in v_grid]) +b02 = binding[v_grid == 0.02][0] +b_uniform = gm_decomposition(artificial_panel(np.inf)[0]) # uniform skill losses + +print("turbulence σ²_μ σ²_ν share of the measured change in σ²_μ, σ²_ν") +for v, b in zip(list(v_grid) + [np.inf], list(binding) + [b_uniform]): + share = (b - b02) / gm_change + print(f"{v:9.2f} {b[0]:8.4f} {b[1]:8.4f} {share[0]:6.0%} {share[1]:6.0%}") +``` + +```{code-cell} ipython3 +--- +mystnb: + figure: + caption: Changes in the model's permanent and transitory variances relative to the turbulence parameter 0.02, for turbulence parameters from 0.01 to 1, compared with the changes that Gottschalk and Moffitt measured + name: fig-ti-binding +--- +fig, axes = plt.subplots(1, 2, figsize=(11, 4)) +for k, (ax, name) in enumerate(zip(axes, ("permanent variance", "transitory variance"))): + ax.semilogx(v_grid[1:], binding[1:, k] - b02[k], "o-", label="model") + ax.axhline(gm_change[k], color="k", ls="--", label="PSID, 1979–87 minus 1970–78") + ax.axhline(0, color="0.7", lw=0.8) + ax.set_xlabel("turbulence parameter") + ax.set_title(f"change in {name}") + ax.legend() +plt.tight_layout() +plt.show() +``` + +At the turbulence parameter $0.04$ that Ljungqvist and Sargent assign to 1979–87, the model delivers about 8 percent of the measured increase in the permanent variance and 13 percent of the increase in the transitory variance. + +Across random seeds the second share ranges from about 9 to 13 percent, with a mean of about 11 percent. + +The binding function rises with turbulence above $0.01$, and it flattens as the turbulence parameter grows, because the distribution of skill losses approaches the uniform distribution over the skill levels from the lowest to the worker's current level. + +At the largest value in our grid, the model delivers about 21 percent of the increase in the permanent variance and 43 percent of the increase in the transitory variance. + +In the limit of uniformly distributed skill losses, the shares are about 21 and 44 percent; across random seeds the second share ranges from about 44 to 49 percent. + +Gottschalk and Moffitt trimmed their data, and we have not trimmed the model's panels. + +Trimming each year's log earnings in the model's panels in the same way leaves the shares at $0.04$ roughly unchanged and lowers both shares at the largest turbulence parameter. + +```{code-cell} ipython3 +y_max, _ = artificial_panel(1.0) +b_trim = {v: gm_decomposition(*trim(y)) for v, y in ((0.02, y02), (0.04, y04), + (1.0, y_max))} +print(f"turbulence 0.02: σ²_ν {b02[1]:.4f} without trimming, " + f"{b_trim[0.02][1]:.4f} with trimming") +for v in (0.04, 1.0): + share = (b_trim[v] - b_trim[0.02]) / gm_change + print(f"turbulence {v}: shares of the measured changes with trimming " + f"{share[0]:.0%}, {share[1]:.0%}") +``` + +The 1 percent tails of each year's earnings carry about a third of the model's transitory variance, and trimming lowers the transitory share at the largest turbulence parameter to between 34 and 37 percent across random seeds. + +The shares also depend on the range of skills, which bounds a skill loss, and on the speed of skill transitions, which governs how long a loss persists. + +{ref}`ti_ex_robust` shows that with skills on $[1, 3]$ and the original transition probabilities, turbulence delivers about 46 percent of the measured increase in the permanent variance and nearly all of the increase in the transitory variance. + +Doubling the transition probabilities as well brings the permanent share back to about one fifth, because laid-off workers regain their skills twice as fast. + +Holding the 1970–78 parameter at $0.02$ also matters. + +If the turbulence parameters for both windows are free, the largest changes that the model can deliver are the differences between the largest and smallest points of the binding function. + +```{code-cell} ipython3 +points = np.vstack([binding, b_uniform]) +largest = (points.max(axis=0) - points.min(axis=0)) / gm_change +print(f"largest shares with both windows free: {largest[0]:.0%}, {largest[1]:.0%}") +``` + +No value of the turbulence parameter makes the change in the model's projection equal the change in the data's projection. + +Indirect inference based on these two statistics pushes the turbulence parameter toward the limit in which skill losses are uniformly distributed, and it still leaves a gap. + +Ljungqvist and Sargent observed that the increase in their model's variability occurs at lower standard deviations than in the data; the binding function measures a related shortfall in the sizes of the two variance increases. + +They concluded from their comparisons with Gottschalk and Moffitt and with Jacobson, LaLonde, and Sullivan: + +> The simulations suggest that the mechanism generating high long-term unemployment in our model operates at much lower levels of economic turbulence than those observed in the United States. + +Our estimates of the binding function support their inference that the data call for more turbulence than $0.04$. + +They also show that no amount of turbulence in this model reaches the changes in the data, so those changes must also come from components that the model omits. + +With the 1970–78 parameter fixed at $0.02$, the two statistics and the one free parameter leave one overidentifying restriction. + +{doc}`gallant_tauchen` tests a structural model in this way, by asking whether the distance that remains between the projections at the best parameter value exceeds what sampling variation allows. + +Here the test is of a joint hypothesis: that the model describes the changes in earnings and that the components of earnings that it omits did not change. + +Gottschalk and Moffitt's suggestion that a rising price of skill may explain the widening dispersion of permanent wages casts doubt on the second part for the permanent variance. + +(ti_ident_section)= +## Layoff rates and turbulence + +The binding function maps a scalar parameter into two numbers, and other structural changes can move those two numbers in the same direction. + +We compute the projection of the model with the turbulence parameter held at $0.02$ and a higher layoff rate $\lambda$. + +```{code-cell} ipython3 +b04 = binding[v_grid == 0.04][0] +b_layoff = {λ: gm_decomposition(artificial_panel(0.02, λ=λ)[0]) + for λ in (0.012, 0.015, 0.018, 0.021)} +print("layoff rate change in σ²_μ, σ²_ν from the 1970–78 calibration") +for λ, b in b_layoff.items(): + print(f"{λ:11.3f} {b[0] - b02[0]:+.4f} {b[1] - b02[1]:+.4f}") +print(f"turbulence 0.04: {b04[0] - b02[0]:+.4f} {b04[1] - b02[1]:+.4f}") +``` + +Doubling or slightly more than doubling the layoff rate raises the permanent variance by about as much as raising the turbulence parameter from $0.02$ to $0.04$, and it raises the transitory variance by about $0.003$ instead of $0.006$ in this simulation, and by about $0.002$ instead of $0.005$ on average across random seeds. + +The two explanations project onto nearby points of the random-effects model. + +The two explanations' nearby projections are the identification counterpart of the result in {doc}`specification_tests` that a comparison of projections has no power against an alternative that leaves the projections equal. + +Whether a sample can separate the two explanations depends on the sampling variability of formulas {eq}`ti_gm` in the data. + +Gottschalk and Moffitt's sample contains 2,730 men. + +The transitory variance $\sigma^2_\nu$ is the average of the men's squared standard deviations $\hat s_i^2$, so its standard deviation in a sample of 2,730 men is about the standard deviation of $\hat s_i^2$ divided by $\sqrt{2730}$. + +We compute it from our readings of Gottschalk and Moffitt's Figure 4, and we compute the power of a test that compares the change in the transitory variance with the change that each explanation predicts. + +```{code-cell} ipython3 +sd_ν = {} +for window, heights in gm_fig4.items(): + p = np.array(heights) / np.sum(heights) + s2 = gm_fig4_bins**2 + sd_ν[window] = np.sqrt((p @ s2**2 - (p @ s2)**2) / 2730) + print(f"{window}: σ²_ν implied by the figure {p @ s2:.3f}, " + f"standard deviation {sd_ν[window]:.4f}") +sd_change = np.hypot(*sd_ν.values()) +gap = (b04[1] - b02[1]) - (b_layoff[0.018][1] - b02[1]) +power = ncx2.sf(chi2.ppf(0.95, 1), 1, (gap / sd_change)**2) +print(f"standard deviation of the change {sd_change:.4f}, gap {gap:.4f}, " + f"power of a 5 percent test {power:.2f}") +``` + +Our readings of the figure imply transitory variances of $0.103$ and $0.145$, close to the $0.104$ and $0.148$ in Gottschalk and Moffitt's Table 1. + +The standard deviation of the change between windows is about $0.006$, so the difference of about $0.003$ between the two explanations' changes in the transitory variance is about half a standard deviation. + +This calculation treats the two windows as independent samples of 2,730 men; Gottschalk and Moffitt's windows contain some of the same men, which lowers the standard deviation of the change, and each window contains fewer than 2,730 men, which raises it. + +With the noncentrality calculation of {ref}`st_ex_power`, a separation of half a standard deviation gives a 5 percent test a power of about $0.08$. + +The calculation asks whether data generated by one explanation could reject the other. + +Both explanations fall more than six standard deviations short of the measured change of $0.044$, so the calculation measures what the two statistics can identify within the model, not how well either explanation fits. + +Gottschalk and Moffitt's two statistics therefore barely distinguish more frequent layoffs from larger skill losses. + +{cite:t}`LjungqvistSargent2008` also compare their model with the earnings losses of displaced workers that {cite:t}`JacobsonLaLondeSullivan1993` measured. They write: + +> We acknowledge that the substantial earnings losses experienced by displaced U.S. workers since the 1980s by themselves say nothing about increased turbulence between the 1950–1960s and the post 1980s, since that would require evidence from similar displaced worker studies from the 1950–1960s, which unfortunately do not exist. + +They add: "Instead, we have drawn support for our story about increased turbulence indirectly from time series studies like that of Gottschalk and Moffitt (1994), whose findings Katz and Autor (1999) showed to be robust across a variety of studies and data sets." + +Each additional statistic adds sufficient statistics to the auxiliary model and shrinks the set of structural parameters whose projections agree with the data's. + +An additional statistic separates two explanations only if the two explanations project onto different values of it, and only if the econometrician computes the statistic in the same way from the model and from the data. + +{ref}`ti_ex_jls` computes displaced-worker statistics for the two explanations. + +(ti_mg_section)= +## Covariance-structure model + +{cite:t}`MoffittGottschalk2011` describe a limitation of the decomposition {eq}`ti_gm`: + +> However, in addition to requiring the choice of arbitrary calendar time intervals, that method is problematic if the permanent variance does not shift abruptly at interval endpoints but instead trends smoothly upward. In that case, deviations from average earnings during the early and later parts of the interval will be incorrectly attributed to transitory earnings. + +In terms of the periodogram, a permanent component that changes within a window has power at the nonzero Fourier frequencies, which the projection counts as transitory. + +They fit instead a model of the whole covariance structure of earnings, in which a permanent component follows a random walk and a transitory component follows an ARMA(1,1) process, + +$$ +y_{it} = \mu_{it} + \nu_{it} , +\qquad +\mu_{it} = \mu_{i,t-1} + \omega_{it} , +\qquad +\nu_{it} = \rho \nu_{i,t-1} + \xi_{it} + \theta \xi_{i,t-1} , +$$ + +with loadings and variances that trend over time. + +When $\rho = \theta = 0$, the transitory component is white noise, and the model is the random walk observed with noise of {cite:t}`Muth1960` that {doc}`phillips_misspecified` and {doc}`lq_permanent_income` use. + +They estimate the model by minimum distance with an identity weighting matrix, which fits the model's autocovariances to the sample autocovariances by least squares. + +The chi-squared statistics that they report exceed the 1 percent critical values for every specification, although they judge that the random walk with an ARMA(1,1) transitory component "fits our data adequately." + +We fit a version with constant parameters to the nine-year covariance matrix of our artificial panels, both by least squares, as Moffitt and Gottschalk do, and by minimizing the Gaussian KL divergence. + +Its parameters are the variance $\sigma^2_0$ of the permanent component in the year before the window, the variance $\sigma^2_\omega$ of its increments, and $\rho$, $\theta$, and the variance $\sigma^2_\xi$ of the innovations $\xi_{it}$ to the transitory component. + +```{code-cell} ipython3 +def mg_cov(θ, T=9): + σ2_0, σ2_ω, ρ, ϑ, σ2_ξ = θ + t = np.arange(1, T + 1) + lag = np.abs(np.subtract.outer(t, t)) + γ0 = σ2_ξ * (1 + 2 * ρ * ϑ + ϑ**2) / (1 - ρ**2) + γ1 = σ2_ξ * (1 + ρ * ϑ) * (ρ + ϑ) / (1 - ρ**2) + transitory = np.where(lag == 0, γ0, γ1 * ρ**np.maximum(lag - 1, 0)) + return σ2_0 + σ2_ω * np.minimum.outer(t, t) + transitory + + +def mg_params(p): + return np.array([np.exp(p[0]), np.exp(p[1]), np.tanh(p[2]), np.tanh(p[3]), + np.exp(p[4])]) + + +def mg_projection(S, distance): + best = None + for p0 in ([np.log(0.02), np.log(0.002), 0.5, -0.3, np.log(0.02)], + [np.log(0.01), np.log(0.0005), 1.0, 0.0, np.log(0.04)]): + objective = lambda p: distance(S, mg_cov(mg_params(p))) + res = minimize(objective, p0, method="Nelder-Mead", + options={"maxiter": 40_000, "xatol": 1e-10, "fatol": 1e-15}) + res = minimize(objective, res.x, method="BFGS") + if best is None or res.fun < best.fun: + best = res + return mg_params(best.x) + + +print("turbulence distance σ²_0 σ²_ω ρ θ σ²_ξ " + "permanent transitory") +for v in (0.02, 0.04): + y_v = artificial_panel(v, N=40_000, seed=1)[0] + S = np.cov(y_v.T) + for name, distance in (("least sq.", euclidean), ("KL", gaussian_kl)): + θ = mg_projection(S, distance) + permanent = θ[0] + 5 * θ[1] # middle year of the window + transitory = mg_cov(θ)[4, 4] - permanent + print(f"{v:9.2f} {name:10} {θ[0]:8.4f} {θ[1]:8.5f} {θ[2]:7.3f} {θ[3]:7.3f} " + f"{θ[4]:8.4f} {permanent:9.4f} {transitory:10.4f}") + print(f" random effects (ti_gm): permanent {gm_decomposition(y_v)[0]:.4f}, " + f"transitory {gm_decomposition(y_v)[1]:.4f}") +``` + +The covariance-structure model assigns almost no variance to the permanent component. + +It attributes the model's earnings instability to a transitory component with an annual autoregressive coefficient between $0.63$ and $0.71$ and a moving-average coefficient of about $-0.26$. + +Moffitt and Gottschalk's PSID estimates in their Table 5 are $\rho = 0.641$ and $\theta = -0.367$. + +The covariance-structure model attributes the increase from turbulence $0.02$ to $0.04$ to the transitory component. + +The random-effects projection {eq}`ti_gm` of the same panels attributes about half of the increase to the permanent component. + +The two auxiliary models disagree because a skill loss at a layoff is large, persistent, and eventually reversed. + +A worker who loses half of the accumulated skills regains them at an average rate of one skill level, or $0.05$, every ten periods of employment, so the worker's earnings stay low for several years. + +A loss of that kind early in a nine-year window lowers the worker's average and raises the variance of averages across workers, which the random-effects projection counts as permanent. + +In terms of the periodogram, a loss that persists for several years puts much of its power at frequency zero. + +The covariances of the model's earnings decline with the lag, and the covariance-structure model fits that decline with its transitory component, so it counts the same loss as transitory. + +Moffitt and Gottschalk noted this problem as well: "if the transitory component is serially correlated, the variance of average earnings will be affected by the variance of the transitory component as well." + +The model's deviations from the workers' own averages have small serial correlations, like those that Gottschalk and Moffitt found in the PSID. + +```{code-cell} ipython3 +for v, y in ((0.02, y02), (0.04, y04)): + d = y - y.mean(axis=1, keepdims=True) + r = np.corrcoef(d[:, :-1].ravel(), d[:, 1:].ravel())[0, 1] + print(f"turbulence {v}: correlation of successive deviations {r:.2f}") +``` + +Correlations of $0.17$ and $0.22$ between successive deviations are compatible with a transitory component whose autoregressive coefficient is near $0.7$, so the small correlations in the PSID do not show that its transitory components are close to serially uncorrelated. + +The least squares and KL projections onto the covariance-structure model differ in their details. + +That model is not an exponential family: its covariance matrices form a curved set, and the argument that made the two projections coincide for the random-effects model does not apply. + +## Concluding remarks + +Ljungqvist and Sargent's comparison of histograms is an informal version of indirect inference: the second moments of their histograms are the parameters of the m-projections of the data and of the structural model onto the same auxiliary model. + +For the laissez-faire economy of {cite:t}`LjungqvistSargent1998`, the binding function of Gottschalk and Moffitt's decomposition rises with turbulence above $0.01$. + +With the 1970–78 parameter held at their value of $0.02$, the binding function cannot reach the changes that Gottschalk and Moffitt measured, and how close it comes depends on the range of skills and on how quickly laid-off workers regain them. + +The same two statistics respond in similar ways to an increase in the layoff rate, so they identify turbulence only weakly. + +The answer to the question of how much instability is permanent depends on the auxiliary model: the random-effects decomposition and the covariance-structure model of {cite:t}`MoffittGottschalk2011` split the same model-generated instability differently. + +## Exercises + +```{exercise} +:label: ti_ex_jls + +{cite:t}`JacobsonLaLondeSullivan1993` compare the quarterly earnings of workers with six years of tenure who were displaced in the first quarter of 1982 with the earnings of workers who stayed with their employers through 1986. + +{cite:t}`LjungqvistSargent1998` construct the model's counterpart by following, for 11 years, 100,000 workers who have been in the labor force for 20 years. They call the first 12 weeks of year 7 the first quarter of 1982, and they plot the separators whose skill losses exceed 40 percent. + +1. Simulate 100,000 such workers in the laissez-faire economy with turbulence parameter $0.04$. Identify the stayers, who are employed in every period and never laid off. Identify the separators, who are employed and never laid off in the first six years and are laid off in the first six periods of year 7. +2. Compute the average 12-week earnings of each group, and the ratio of separators' to stayers' earnings over the last two years. Do this for all separators and for the separators whose skill falls by more than 40 percent at the layoff. +3. Repeat part 2 for all separators in the economy with turbulence parameter $0.02$ and layoff rate $0.019$, the layoff rate at which the change in the permanent variance approximately matches the change from raising turbulence to $0.04$, and compute the fraction of workers with six years of tenure who are displaced at the start of year 7 in each economy. +4. Which of these statistics can an econometrician compute from data like Jacobson, LaLonde, and Sullivan's? Which of them distinguish the two explanations? +``` + +```{solution-start} ti_ex_jls +:class: dropdown +``` + +Here is one solution. + +```{code-cell} ipython3 +def displaced_worker_statistics(turbulence, λ=0.009, N=100_000, seed=3): + m = create_model(turbulence=turbulence, λ=λ) + rec = simulate_workers(m, *solve_model(m), N=N, T=11 * 26, T_burn=20 * 26, + seed=seed) + emp, laid, h = rec["emp"], rec["laid"], rec["h"] + k0 = 6 * 26 # first period of year 7 + tenured = emp[:, :k0].all(axis=1) & ~laid[:, :k0].any(axis=1) + stayers = emp.all(axis=1) & ~laid.any(axis=1) + separators = tenured & laid[:, k0:k0 + 6].any(axis=1) + rows = np.where(separators)[0] + k_lay = k0 + laid[rows, k0:k0 + 6].argmax(axis=1) + loss = np.round(1 - m.h_grid[h[rows, k_lay]] / m.h_grid[h[rows, k_lay - 1]], 9) + later = np.arange(laid.shape[1])[None, :] > k_lay[:, None] + big_loss = np.isin(np.arange(N), rows[loss > 0.4]) + + def quarterly(mask): + return rec["earn"][mask][:, :282].reshape(mask.sum(), 47, 6).sum(axis=2).mean(axis=0) + + stay = quarterly(stayers) + ratio = lambda mask: quarterly(mask)[-8:].mean() / stay[-8:].mean() + return {"stayers": stayers.sum(), "separators": separators.sum(), + "shares of separators with losses above 10, 20, 30, 40%": + np.round([(loss > c).mean() for c in (0.1, 0.2, 0.3, 0.4)], 3), + "displacement rate": separators.sum() / tenured.sum(), + "ratio, all separators": ratio(separators), + "separators with losses above 40%": (loss > 0.4).sum(), + "later layoffs per separator": (laid[rows] & later).sum(axis=1).mean(), + "ratio, losses above 40%": ratio(big_loss) if big_loss.any() else np.nan, + "paths": (stay, quarterly(separators), + quarterly(big_loss) if big_loss.any() else None)} + + +turbulent = displaced_worker_statistics(0.04) +more_layoffs = displaced_worker_statistics(0.02, λ=0.019) +for name, res in (("turbulence 0.04", turbulent), + ("turbulence 0.02, layoff rate 0.019", more_layoffs)): + print(name) + for key, value in res.items(): + if key != "paths": + print(f" {key}: {value:.3f}" if isinstance(value, float) + else f" {key}: {value}") +``` + +```{code-cell} ipython3 +--- +mystnb: + figure: + caption: Twelve-week earnings of stayers and separators in the laissez-faire economy with turbulence parameter 0.04 + name: fig-ti-jls +--- +fig, ax = plt.subplots() +stay, sep, big = turbulent["paths"] +quarters = np.arange(len(stay)) * 12 / 52 - 6 +ax.plot(quarters, stay, label="stayers") +ax.plot(quarters, sep, label="all separators") +ax.plot(quarters, big, label="separators with skill losses above 40%") +ax.set_xlabel("years from the start of year 7") +ax.set_ylabel("12-week earnings") +ax.legend(loc="lower left", fontsize=9) +plt.show() +``` + +Ljungqvist and Sargent report 2,889 stayers and 629 separators among their 100,000 workers. + +Our simulation has about twice as many stayers and about two thirds more separators. + +The shares of separators whose skill losses exceed 10, 20, 30, and 40 percent are 55, 27, 10, and 2.5 percent, against the 47, 25, 11, and 3 percent that they report. + +We have not found the source of the difference in the counts. + +With turbulence parameter $0.04$, all separators earn about 17 percent less than stayers three to five years after displacement, and the few separators whose skills fall by more than 40 percent earn about 37 percent less. + +Ljungqvist and Sargent describe Jacobson, LaLonde, and Sullivan's finding as a recovery "toward an eventual level of about 25 percent less than the amount earned at the predisplacement job." + +Their data identify displaced workers by the event of displacement, not by the size of a skill loss, so the earnings statistic that the data can supply is the one for all separators. + +Their records cover stayers as well as separators, so data like theirs can also supply a displacement rate. + +With the higher layoff rate, all separators earn about 21 percent less than stayers, because after displacement they are laid off again about twice as often as separators in the turbulent economy. + +The earnings-loss statistic therefore barely distinguishes the two explanations. + +The displacement rate in the economy with the higher layoff rate is about twice the rate in the turbulent economy. + +Measured in one period, the rate distinguishes the explanations only if we trust the model's level of displacement, and throughout this lecture we have compared changes rather than levels. + +The change in the displacement rate between two periods distinguishes them: it doubles when the layoff rate doubles and does not move with turbulence. + +Measuring that change requires comparable displaced-worker studies from both periods, which is what the passage from {cite:t}`LjungqvistSargent2008` quoted above says is missing. + +```{solution-end} +``` + +```{exercise} +:label: ti_ex_projection + +Let $y_i$ be a random vector in $\mathbb{R}^T$ with mean zero and covariance matrix $S$, and consider the random-effects family $N(0, \sigma^2_\mu \mathbf{1}\mathbf{1}^\top + \sigma^2_\nu I)$. + +1. Show that the inverse of $\Sigma = \sigma^2_\mu \mathbf{1}\mathbf{1}^\top + \sigma^2_\nu I$ is $\sigma_\nu^{-2} \left(I - c\,\mathbf{1}\mathbf{1}^\top\right)$ with $c = \sigma^2_\mu / (\sigma^2_\nu + T \sigma^2_\mu)$, and that $\log p(y_i)$ is a linear function of $W_i$ and $T \bar y_i^2$ plus a function of the parameters. +2. Minimize the Gaussian KL divergence of $N(0, S)$ from $N(0, \Sigma)$ over $(\sigma^2_\mu, \sigma^2_\nu)$ and show that the minimizer sets $\sigma^2_\nu = (\operatorname{tr} S - \mathbf{1}^\top S \mathbf{1}/T)/(T - 1)$ and $\sigma^2_\mu = \mathbf{1}^\top S \mathbf{1}/T^2 - \sigma^2_\nu / T$. +3. Show that the least squares projection of $S$ onto the same family gives the same answer. +``` + +```{solution-start} ti_ex_projection +:class: dropdown +``` + +Here is one solution. + +For part 1, multiply $\Sigma$ by $\sigma_\nu^{-2}(I - c\,\mathbf{1}\mathbf{1}^\top)$ and use $\mathbf{1}^\top \mathbf{1} = T$: the product is $I + \sigma_\nu^{-2}\left[\sigma^2_\mu - c(\sigma^2_\nu + T\sigma^2_\mu)\right]\mathbf{1}\mathbf{1}^\top = I$. + +Then $y_i^\top \Sigma^{-1} y_i = \sigma_\nu^{-2}\left(y_i^\top y_i - c T^2 \bar y_i^2\right)$, and $y_i^\top y_i = W_i + T \bar y_i^2$, so + +$$ +\log p(y_i) = -\frac{W_i}{2\sigma^2_\nu} - \frac{T \bar y_i^2}{2(\sigma^2_\nu + T\sigma^2_\mu)} - \frac{1}{2}\log\det(2\pi\Sigma) , +$$ + +because $1 - cT = \sigma^2_\nu / (\sigma^2_\nu + T\sigma^2_\mu)$. + +For part 2, the KL divergence of $N(0, S)$ from $N(0, \Sigma)$ is minus the expectation of $\log p(y_i)$ under $N(0, S)$ plus a constant. + +The eigenvalues of $\Sigma$ are $\sigma^2_\nu + T\sigma^2_\mu$, with eigenvector $\mathbf{1}$, and $\sigma^2_\nu$, with multiplicity $T - 1$, so $\log\det\Sigma = \log(\sigma^2_\nu + T\sigma^2_\mu) + (T - 1)\log\sigma^2_\nu$. + +With $E[W_i] = \operatorname{tr} S - \mathbf{1}^\top S \mathbf{1}/T$ and $E[T\bar y_i^2] = \mathbf{1}^\top S \mathbf{1}/T$, the objective separates into a function of $a = \sigma^2_\nu$ and a function of $d = \sigma^2_\nu + T\sigma^2_\mu$: + +$$ +\frac{E[W_i]}{2a} + \frac{T-1}{2}\log a + \frac{E[T\bar y_i^2]}{2d} + \frac{1}{2}\log d . +$$ + +Minimizing gives $a = E[W_i]/(T-1)$ and $d = E[T\bar y_i^2]$, which are the stated formulas. + +For part 3, the least squares problem $\min \sum_{t \le s} (S_{ts} - \Sigma_{ts})^2$ separates into the diagonal elements, all equal to $\sigma^2_\mu + \sigma^2_\nu$, and the off-diagonal elements, all equal to $\sigma^2_\mu$. + +The minimizer sets $\sigma^2_\mu + \sigma^2_\nu$ equal to the average diagonal element $\bar s_d$ and $\sigma^2_\mu$ equal to the average off-diagonal element $\bar s_o$. + +Since $\operatorname{tr} S = T \bar s_d$ and $\mathbf{1}^\top S \mathbf{1} = T\bar s_d + T(T - 1)\bar s_o$, the formulas of part 2 give $\sigma^2_\nu = \bar s_d - \bar s_o$ and $\sigma^2_\mu = \bar s_o$. + +```{code-cell} ipython3 +S = np.cov(y04.T) +T = len(S) +s_d, s_o = np.mean(np.diag(S)), (S.sum() - np.trace(S)) / (T * (T - 1)) +print("least squares:", np.round([s_o, s_d - s_o], 6)) +σ2_ν = (np.trace(S) - S.sum() / T) / (T - 1) +print("KL formulas: ", np.round([S.sum() / T**2 - σ2_ν / T, σ2_ν], 6)) +``` + +```{solution-end} +``` + +```{exercise} +:label: ti_ex_robust + +{cite:t}`LjungqvistSargent1998` report that "similar results were obtained in earlier simulations in which we had doubled both the range of skills and the transition probabilities of gaining a skill level when remaining employed for two periods and of losing a skill level when being unemployed for two consecutive periods." + +1. Set the skills on $[1, 3]$, keep 21 skill levels and the original transition probabilities, and recompute the binding function at the turbulence parameters $0.02$, $0.04$, $0.1$, and $1$. +2. Also double the probability of a skill gain to $0.2$ and the probability of a skill loss to $0.4$, and recompute the binding function. + +Part 2 is our reading of their sentence; part 1 separates the effect of the range from the effect of the transition probabilities. + +What fractions of the measured changes in the permanent and transitory variances can turbulence deliver in each case, and why do the two cases differ? +``` + +```{solution-start} ti_ex_robust +:class: dropdown +``` + +Here is one solution. + +```{code-cell} ipython3 +grid, ends = (0.02, 0.04, 0.1, 1.0), (0.02, 1.0) +cases = (("wider range", dict(h_max=3.0), grid), + ("wider range, faster transitions", dict(h_max=3.0, up=0.2, down=0.4), grid), + ("wider range, faster skill gains only", dict(h_max=3.0, up=0.2), ends), + ("wider range, faster skill losses only", dict(h_max=3.0, down=0.4), ends)) +for case, kwargs, v_wide in cases: + b_wide = np.array([gm_decomposition(artificial_panel(v, **kwargs)[0]) + for v in v_wide]) + print(case) + for v, b in zip(v_wide, b_wide): + share = (b - b_wide[0]) / gm_change + print(f" turbulence {v:5.2f}: σ²_μ {b[0]:.4f}, σ²_ν {b[1]:.4f}, " + f"shares of the measured changes {share[0]:.0%}, {share[1]:.0%}") +``` + +A wider range of skills allows larger skill losses. + +With skills on $[1, 3]$ and the original transition probabilities, turbulence delivers up to about 46 percent of the measured increase in the permanent variance and nearly all of the increase in the transitory variance. + +Doubling the transition probabilities as well halves the time that a laid-off worker needs to regain the lost skill levels. + +A skill loss then lasts a smaller part of a nine-year window and lowers the worker's average by less, so the random-effects projection counts less of it as permanent. + +In that case turbulence delivers at most about one fifth of the increase in the permanent variance, as in the original economy, and slightly more than all of the increase in the transitory variance. + +The faster recovery is what matters: doubling only the probability of a skill gain lowers the permanent share at turbulence $1$ to about 21 percent, while doubling only the probability of a skill loss leaves it at about 41 percent. + +Ljungqvist and Sargent's sentence concerns their qualitative findings; the binding function shows that the permanent share is not robust to changing the range of skills alone. + +```{solution-end} +``` From 41121eccea57a8b0b93025cb27216c27080d88c5 Mon Sep 17 00:00:00 2001 From: thomassargent30 Date: Sat, 21 Nov 2026 11:31:39 -0500 Subject: [PATCH 2/3] Connect filtering and seasonal adjustment to Blackwell's garbling order - approximation_errors: add the section "Garbling and the data processing inequality". It covers: - filters whose zeros are isolated, which leave the m-projection unchanged; - ideal adjustment as dropping Fourier transforms in the seasonal bands; - Hansen and Sargent's three kinds of data as a Blackwell chain whose ranking misspecification reverses; - Fisher-information contraction and the covariance of the estimator under misspecification; - low-frequency and Hodrick-Prescott filters; - sampling and aliasing. It also adds the exercise ae_ex_tradeoff on the bias-variance trade-off in choosing a band width. - blackwell_kihlstrom: add the subsection "Garbling a time series" and rows to the DPI-Blackwell summary table. - specification_tests: read the band Hausman test through the data processing inequality, and compute the variance of the estimator difference under the alternatives. - divergence_measures: add a pointer to the new section. - Add bib entries HansenSargent1983, Sargent1978Seasonal, Singleton1988, and HodrickPrescott1997. Co-Authored-By: Claude Opus 5.5 --- lectures/_static/quant-econ.bib | 40 +++ lectures/approximation_errors.md | 407 ++++++++++++++++++++++++++++++- lectures/blackwell_kihlstrom.md | 65 ++++- lectures/divergence_measures.md | 2 + lectures/specification_tests.md | 63 +++++ 5 files changed, 574 insertions(+), 3 deletions(-) diff --git a/lectures/_static/quant-econ.bib b/lectures/_static/quant-econ.bib index 57e71e5d8..5f54c1755 100644 --- a/lectures/_static/quant-econ.bib +++ b/lectures/_static/quant-econ.bib @@ -4383,6 +4383,46 @@ @article{HansenSargent1993 year = {1993} } +@article{HansenSargent1983, + author = {Hansen, Lars Peter and Sargent, Thomas J.}, + title = {The Dimensionality of the Aliasing Problem in Models with Rational Spectral Densities}, + journal = {Econometrica}, + volume = {51}, + number = {2}, + pages = {377--387}, + year = {1983} +} + +@incollection{Sargent1978Seasonal, + author = {Sargent, Thomas J.}, + title = {Comments on ``Seasonal Adjustment and Multiple Time Series Analysis'' by {K. F. Wallis}}, + booktitle = {Seasonal Analysis of Economic Time Series}, + editor = {Zellner, Arnold}, + pages = {361--363}, + publisher = {U.S. Department of Commerce, Bureau of the Census}, + address = {Washington, DC}, + year = {1978} +} + +@article{Singleton1988, + author = {Singleton, Kenneth J.}, + title = {Econometric Issues in the Analysis of Equilibrium Business Cycle Models}, + journal = {Journal of Monetary Economics}, + volume = {21}, + pages = {361--386}, + year = {1988} +} + +@article{HodrickPrescott1997, + author = {Hodrick, Robert J. and Prescott, Edward C.}, + title = {Postwar {U.S.} Business Cycles: An Empirical Investigation}, + journal = {Journal of Money, Credit and Banking}, + volume = {29}, + number = {1}, + pages = {1--16}, + year = {1997} +} + @article{Granger1966, author = {Granger, C. W. J.}, title = {The Typical Spectral Shape of an Economic Variable}, diff --git a/lectures/approximation_errors.md b/lectures/approximation_errors.md index cff9ac3be..bdb29c194 100644 --- a/lectures/approximation_errors.md +++ b/lectures/approximation_errors.md @@ -38,12 +38,13 @@ For stationary Gaussian processes, the KL divergence per observation converges t {cite:t}`Sims1971`, {cite:t}`Sims1974`, {cite:t}`Sims1993`, and {cite:t}`HansenSargent1993` study the errors that an econometrician makes when fitting a misspecified time series model, and they show how sampling, seasonal noise, and seasonal adjustment change those errors. -The lecture has four sections. +The lecture has five sections. * {ref}`ae_kl_section` describes the KL divergence between two stationary Gaussian processes as an integral over frequencies. * {ref}`ae_ar_section` describes misspecified autoregressions as projections of spectral densities, and describes how filtering the data and the model, filtering the data alone, and deleting frequency bands change the projection. * {ref}`ae_lag_section` describes least squares estimates of distributed lags as m-projections weighted by the spectral density of the regressor, and describes Sims's results on sampling and on seasonal noise. * {ref}`ae_seasonal_section` describes seasonal adjustment in dynamic rational expectations models. +* {ref}`ae_garbling_section` treats filtering, deleting frequency bands, removing seasonal means, and sampling as garblings in the sense of {doc}`blackwell_kihlstrom`, and uses the data processing inequality to organize the results of the earlier sections. {doc}`specification_tests` continues this lecture: it describes specification tests as comparisons of two projections. @@ -420,7 +421,7 @@ $$ (ae_hs_ideal) With the seasonal bands deleted, the econometrician projects the part of the process that lies outside the bands onto the part of the model that lies outside them. -The divergence rate restricted to $K$ is at most the full divergence rate, because the information inequality makes every deleted term nonnegative. +The divergence rate restricted to $K$ is at most the full divergence rate, because the information inequality makes every deleted term nonnegative; {ref}`ae_garbling_section` reads this inequality as an instance of the data processing inequality. If, for some $\delta_0$, the model matches $F$ outside the seasonal bands and matches the mean, $\mu(\delta_0) = \nu$, then $\delta_0$ is among the minimizers of {eq}`ae_hs_ideal`, whatever the model does inside the bands. @@ -472,6 +473,8 @@ Two other operations change the projection. * **Deleting frequencies**, as in {eq}`ae_hs_ideal`, removes the bands from the criterion and leaves the other frequencies unchanged. In a regression, filtering both variables with a filter that is zero in the bands and one elsewhere is equivalent to deleting the bands. That filter is not invertible, so the invariance argument does not apply. * **Filtering the data but not the model** replaces $f$ by $|c(e^{-i\omega})|^2 f$ and leaves $g$ alone, so the econometrician projects a different process onto the same model. +{ref}`ae_garbling_section` shows that the invariance and the effect of deleting frequencies are the equality and inequality cases of the data processing inequality, which says nothing about filtering the data alone. + The code below confirms the invariance and computes the effect of filtering the data alone by $c(L) = 1 - 0.5L$. ```{code-cell} ipython3 @@ -1016,6 +1019,321 @@ Sims concludes: > Use of unadjusted data and a correctly specified model of seasonal variation is always the best option. But treating seasonality casually, as a 'nuisance' component of the model, can lead to worse errors than those produced by use of adjusted data. +(ae_garbling_section)= +## Garbling and the data processing inequality + +{doc}`blackwell_kihlstrom` calls an experiment a **garbling** of another experiment when its signal can be generated from the other experiment's signal by a Markov kernel. + +The {ref}`data processing inequality ` says that applying the same Markov kernel to two distributions cannot increase any f-divergence between them, including the KL divergence, and that the divergence is unchanged when the kernel is induced by a sufficient statistic for the pair. + +Filtering, deleting frequency bands, removing seasonal means, and sampling are garblings, and the inequality organizes what this lecture has found about them. + +### Filters, frequency bands, and the data processing inequality + +When an econometrician filters the data by $c(L)$ and filters the model in the same way, the filtered series is the same function of the unfiltered series under the true process and under the model. + +Filtering therefore applies one Markov kernel, a deterministic one, to both processes, and the data processing inequality says that filtering cannot increase the divergence between them. + +When the frequency response $c(e^{-i\omega})$ is zero at most at isolated frequencies, filtering multiplies $f$ and $g$ by $|c(e^{-i\omega})|^2$ and leaves the ratio $f/g$ unchanged at every other frequency, so the divergence rate {eq}`ae_kl_rate` does not change. + +**A filter applied to both the data and the model whose frequency response is zero at most at isolated frequencies leaves the divergence rate and the m-projection unchanged, however much it shrinks the spectral densities near those frequencies.** + +If, in addition, the spectral measure of the data puts no mass at those frequencies, the filtered series determines the unfiltered series in mean square, so the filter is a sufficient statistic for the pair, and the invariance of {ref}`ae_ar_section` is the equality case of the data processing inequality. + +Sims's filter $1 - \kappa(L)\kappa(L^{-1})$ is zero at $\pm\pi/2$, at $\pi$, and at two frequencies near $\pm 0.485\pi$. + +It removes the deterministic seasonal, whose spectral measure puts all its mass at $\pm\pi/2$, and the equality applies to what remains, as {ref}`ae_ex_invariance` shows. + +A filter cannot delete a band of frequencies from the likelihood. + +A filter whose frequency response is zero on a band makes the filtered processes linearly deterministic, and formula {eq}`ae_kl_rate`, which assumes spectral densities bounded away from zero, no longer applies. + +For example, if the true process and the model are white noise with variances $1$ and $2$, the filtered model is $\sqrt{2}$ times the filtered true process, so the divergence between the distributions of $T$ filtered observations equals the divergence between the distributions of $T$ unfiltered observations at every $T$. + +Hansen and Sargent define ideal seasonal adjustment in the frequency domain instead, by omitting the seasonal frequencies from the frequency-domain likelihood. + +The finite Fourier transforms $w_j$ at the frequencies $\omega_j = 2\pi j / T$, $j = 0, \ldots, T - 1$, are an invertible linear transformation of the sample, so dropping the transforms at the frequencies in the bands is a garbling at every sample size. + +Divided by $T$, the divergence between the distributions of the remaining transforms converges to the divergence rate restricted to the set $K$ of frequencies outside the bands: + +$$ +D_K(f \| g) = \frac{1}{4\pi} \int_K \left[ \frac{f(\omega)}{g(\omega)} - 1 - \log \frac{f(\omega)}{g(\omega)} \right] d\omega \leq D(f \| g) . +$$ (ae_dpi_bands) + +Twice $D_K$ is the first term of {eq}`ae_hs_ideal` minus terms that do not depend on $\delta$, so the statement after {eq}`ae_hs_ideal` that the restricted rate is at most the full rate is the data processing inequality. + +Equality holds when $f = g$ almost everywhere in the bands: then, in large samples, the transforms in the bands have the same distribution under the two processes and are independent of the remaining transforms, so dropping them discards nothing that distinguishes the processes. + +Filtering the data but not the model, as Sims's econometrician does, applies the kernel to only one of the two distributions, and the data processing inequality says nothing about it. + +Sims's permanent income examples go in opposite directions, although each comparison also changes the order of the autoregression. + +In the first, adjusted data bring the bias factor closer to one: it is $1.17$ for a ninth-order autoregression fitted to unadjusted data, and $0.893$ by our computation and $1.0137$ by Sims's for a second-order autoregression fitted to adjusted data. + +In the second, adjusted data move the implied coefficient from $20.64$ to $17.08$ with a second-order autoregression, or to $16.82$ with a ninth-order one, farther from the true value $20$. + +### A Blackwell chain + +Hansen and Sargent's three kinds of data are ordered by garbling. + +Data from which seasonal means have been removed are the residuals from a regression of the unadjusted data on seasonal dummies, so they are a function of the unadjusted data. + +Ideally adjusted data are a function of the data with seasonal means removed. + +When $T$ is a multiple of $4$, the seasonal dummies span the same space as the finite Fourier vectors at the frequencies $0$, $\pi/2$, $\pi$, and $3\pi/2$, so removing seasonal means drops the transforms at those four frequencies, and ideal adjustment drops, in addition, the transforms in the bands around $\pi/2$, $\pi$, and $3\pi/2$. + +The three kinds of data are nested sets of Fourier transforms, and each is a garbling of the one before it at every sample size. + +For each $\delta$, subtracting from each of the three criteria the terms that do not depend on $\delta$ leaves twice the divergence rate between the true process and the model at $\delta$ after the corresponding garbling. + +So at every $\delta$, the divergence falls weakly from the first kind of data to the second and from the second to the third. + +The minimized divergence falls too: if $\delta^*$ minimizes the divergence for the finer data, the minimum for the coarser data is at most the coarser divergence at $\delta^*$, which is at most the finer divergence at $\delta^*$. + +In Hansen and Sargent's Table 1, the errors in the probability limits of the estimates also fall at every step. + +We measure the error in $\gamma$ from the average $0.1025$ of the quarterly productivity parameters. + +```{code-cell} ipython3 +table_1 = {"γ": (0.0996, 0.1030, 0.1025), "φ_1": (0.4132, 0.2854, 0.3007), + "a_1": (0.931, 0.3250, 0.3987), "a_4": (0.4383, 0.1598, -0.0003), + "a_5": (-0.4298, -0.1261, -0.0005)} +true_values = {"γ": np.mean([0.13, 0.1, 0.1, 0.08]), "φ_1": 0.3, "a_1": 0.4, + "a_4": 0.0, "a_5": 0.0} +print("absolute errors unadjusted means removed ideally adjusted") +for name, estimates in table_1.items(): + errors = np.abs(np.array(estimates) - true_values[name]) + print(f"{name:>15}" + "".join(f"{e:15.4f}" for e in errors)) +``` + +Blackwell's theorem says that a decision maker who knows the likelihoods of an experiment can do at least as well with it as with any garbling of it, in every decision problem. + +Sims's conclusion, "Use of unadjusted data and a correctly specified model of seasonal variation is always the best option," is the counterpart of that theorem for estimation: with a correctly specified model, deleting frequencies cannot lower the asymptotic variance of the maximum likelihood estimator. + +Hansen and Sargent's Table 1 reverses Blackwell's ranking. + +Their econometrician evaluates the three kinds of data with the likelihoods of a misspecified model, so Blackwell's theorem does not apply, and the probability limits of the estimates of the parameters of preferences, technology, and the endowment process are closest to the truth for the coarsest data. + +Hansen and Sargent's introduction describes the argument that their reversal answers: + +> Other writers had asserted that seasonally unadjusted data ought to be used to estimate rational expectations models, on the grounds that the agents being modelled were themselves assumed to be solving forecasting and signal extraction problems using seasonally unadjusted data, and that the cross-equation restrictions implied by their behavior applied to seasonally unadjusted series. Sims responded that that argument assumes that the model is correctly specified, and asserted that admitting the possibility of approximation error would alter the situation. + +The other writers are {cite:t}`Sargent1978Seasonal` and {cite:t}`Singleton1988`. + +The agents inside the model know the true likelihoods, so Blackwell's theorem applies to them, and they have no reason to garble their data. + +Sims's reply is that the theorem does not apply to an econometrician whose model is misspecified. + +{doc}`information_transfer` describes a different reason that a decision maker can prefer a garbled experiment. + +### Two pairs of distributions + +The data processing inequality applies to any two distributions. + +Applied to the true process and the model at $\delta$, it says that a garbling cannot increase the misspecification; Hansen and Sargent's ideal adjustment, their version of Sims's argument, uses this side. + +Applied to the model at two parameter values $\delta$ and $\delta'$, it says that a garbling cannot make them easier to tell apart. + +If a garbling maps them to the same distribution, they become observationally equivalent, which is what Hansen and Sargent mean when they write that omitting frequencies "might hinder identification by introducing additional minimizers." + +For nearby parameter values, the divergence is one half a quadratic form in the Fisher information matrix, as in {doc}`exponential_families`. + +For a scalar model with spectral density $g(\omega; \delta)$ fitted to the frequencies in a set $K$, the Fisher information matrix of the frequency-domain likelihood is + +$$ +\mathcal{I}_K(\delta) = \frac{1}{4\pi} \int_K \nabla_\delta \log g(\omega; \delta) \, \nabla_\delta \log g(\omega; \delta)^\top \, d\omega , +$$ (ae_info_K) + +so deleting frequencies lowers it in the matrix order: $\mathcal{I}_K(\delta) \preceq \mathcal{I}(\delta)$, where $\mathcal{I}$ uses all frequencies. + +This is the Fisher-information form of the data processing inequality in {doc}`blackwell_kihlstrom`. + +Inversion reverses the matrix order, so with a correctly specified model, $\sqrt{T}$ times the estimator's error has asymptotic covariance matrix $\mathcal{I}_K(\delta)^{-1} \succeq \mathcal{I}(\delta)^{-1}$, which is the efficiency cost in Hansen and Sargent's footnote 11. + +The two matrices are equal when $\nabla_\delta \log g = 0$ almost everywhere on the deleted frequencies, so that those frequencies carry no information about $\delta$. + +Hansen and Sargent's correctly specified examples remain identified when the seasonal frequencies are dropped, although the parameters "impinge most strongly on the seasonal frequencies": + +> they affect all frequencies in ways that are sufficient to preserve their identification even when the seasonal frequencies are dropped. + +There, deleting the bands lowers the information about the parameters without making any other parameter value observationally equivalent to the true one. + +Hansen and Sargent's concluding remarks set the two sides of the inequality against each other: + +> Second, when one is estimating a correctly specified model, there will occur a substantial efficiency loss from using seasonally adjusted data, a loss that grows with the importance of the seasonality in the raw data. In practice, there can be a trade-off between variance and bias of estimators, the dimensions of which we have not explored in this paper. + +Their footnote 17 adds: "On the basis of the logic leading to (4.2), something can be said about the asymptotic distributions of estimators of misspecified models. We plan to explore this in subsequent work." + +When the data come from a Gaussian process whose spectral density $f$ differs from $g(\cdot\,; \delta^*_K)$, where $\delta^*_K$ is the m-projection over the frequencies in $K$, $\sqrt{T}(\hat \delta_K - \delta^*_K)$ has asymptotic covariance matrix $\mathcal{H}_K^{-1} \mathcal{J}_K \mathcal{H}_K^{-1}$, where + +$$ +\mathcal{H}_K = \frac{1}{4\pi} \int_K \left[ \nabla \log g \, \nabla \log g^\top \, \frac{f}{g} + \nabla^2 \log g \left( 1 - \frac{f}{g} \right) \right] d\omega , +\qquad +\mathcal{J}_K = \frac{1}{4\pi} \int_K \nabla \log g \, \nabla \log g^\top \left( \frac{f}{g} \right)^2 d\omega , +$$ (ae_sandwich) + +with $g$ and its derivatives evaluated at $\delta^*_K$. + +$\mathcal{H}_K$ is the Hessian of the divergence rate restricted to $K$, and $\mathcal{J}_K$ is the asymptotic variance of the score of {eq}`ae_whittle` divided by $\sqrt{T}$. + +The factor $(f/g)^2$ comes from the variance of the periodogram, which stays near $f^2$. + +When $f = g(\cdot\,; \delta^*_K)$, both matrices equal $\mathcal{I}_K$, and the covariance matrix reduces to $\mathcal{I}_K^{-1}$. + +The code below computes, for the seasonal example, the AR(1) projection with bands of several widths deleted, the minimized divergence, and the asymptotic variance of $\hat\rho$ in two cases: when the data come from $x_t$ alone, so that the AR(1) is correct, and when they come from $y_t = x_t + s_t$. + +```{code-cell} ipython3 +def ar1_derivatives(ρ, σ2): + """∇ log g and ∇² log g on the grid for g = σ²/|1 - ρe^{-iω}|², θ = (ρ, σ²).""" + d1 = np.vstack([2 * np.real(z / (1 - ρ * z)), np.ones(n_grid) / σ2]) + d2 = np.zeros((2, 2, n_grid)) + d2[0, 0] = 2 * np.real(z**2 / (1 - ρ * z)**2) + d2[1, 1] = -1 / σ2**2 + return d1, d2 + + +def ar1_covariance(f, ρ, σ2, keep): + """Asymptotic covariance matrix of √T(θ̂ - θ*), formula (ae_sandwich).""" + d1, d2 = ar1_derivatives(ρ, σ2) + r = np.where(keep, f / ar_spectrum(ρ, σ2), 0.0) + H = 0.5 * ((d1 * r) @ d1.T + + (d2 * np.where(keep, 1 - r, 0.0)).sum(axis=2)) / n_grid + J = 0.5 * ((d1 * r**2) @ d1.T) / n_grid + H_inv = np.linalg.inv(H) + return H_inv @ J @ H_inv + + +print("band width ρ* divergence Var, x alone Var, y = x + s") +for Δ in (0, np.pi / 16, np.pi / 8, np.pi / 4, np.pi / 2): + keep = seasonal_keep(Δ) + a_K, σ2_K = ar_projection(f_y, 1, keep) + V_x = ar1_covariance(f_x, ρ_x, 1.0, keep)[0, 0] + V_y = ar1_covariance(f_y, a_K[0], σ2_K, keep)[0, 0] + print(f"{Δ / np.pi:9.4f}π {a_K[0]:7.4f} " + f"{kl_rate(f_y, ar_spectrum(a_K, σ2_K), keep):11.5f} " + f"{V_x:13.4f} {V_y:15.4f}") +``` + +With bands of width $\pi/2$, only the frequencies below $\pi/4$ remain. + +When the AR(1) is correct, deleting bands of width $\pi/8$ raises the asymptotic variance of $\hat\rho$ from $0.190$ to $0.194$, about 2 percent, because the information about $\rho$ is concentrated at low frequencies. + +Hansen and Sargent's footnote 11 describes rational expectations models differently: their cross-equation restrictions put much of the information at the high-power seasonal frequencies, where deleting bands costs more. + +In the seasonal example, the estimator that uses all frequencies has asymptotic variance $4.57$, 24 times the variance when the AR(1) is correct. + +The periodogram ordinates at the seasonal peaks, where $f/g$ is large, enter $\mathcal{J}_K$ with the weight $(f/g)^2$. + +Deleting bands of width $\pi/8$ removes those ordinates and lowers the variance to $0.31$, so here deleting bands lowers the variance as well as the bias. + +**The efficiency cost of deleting frequencies is guaranteed only for correctly specified models.** + +{ref}`ae_ex_tradeoff` finds the band width that balances bias against variance when the seasonal component is small. + +{doc}`specification_tests` builds a test that compares the band-deleted and full-band estimators and uses {eq}`ae_sandwich` to compute the variance of their difference when the model is misspecified. + +### Divergences, not estimates + +The data processing inequality bounds divergences; it does not say where the minimizer goes. + +Deleting a band of low frequencies instead of the seasonal bands is also a garbling. + +```{code-cell} ipython3 +dist_0 = np.minimum(ω, 2 * np.pi - ω) +print(f"all frequencies: ρ* = {a_full[0]:.4f}, " + f"divergence {kl_rate(f_y, g_full):.4f}") +for Δ in (np.pi / 8, np.pi / 4): + keep_low = dist_0 >= Δ / 2 # delete a band of width Δ around zero + a_low, σ2_low = ar_projection(f_y, 1, keep_low) + print(f"low band of width {Δ / np.pi:.3f}π deleted: ρ* = {a_low[0]:.4f}, " + f"divergence {kl_rate(f_y, ar_spectrum(a_low, σ2_low), keep_low):.4f}") +``` + +The minimized divergence falls from $0.429$ to $0.366$ and $0.330$, as the inequality requires, but $\rho^*$ falls from $0.62$ to $0.25$ and $0.02$, farther from the coefficient $0.9$ of the nonseasonal component. + +This garbling discards frequencies at which the seasonal component has almost no power and at which most of the information about $\rho$ lies: a band of width $\pi/8$ around zero holds 0.03 percent of the variance of $s_t$ and 91 percent of $\mathcal{I}(\rho)$ when the AR(1) is correct. + +A garbling can improve the estimates of the parameters that an econometrician cares about when it discards the frequencies at which the model is wrong and keeps the frequencies that carry information about those parameters. + +Hansen and Sargent's third qualification in their concluding remarks allows for this: "it is undoubtedly true that particular examples of estimation of misspecified models can go against Sims's recommendation." + +Their condition for ideal adjustment to work describes a garbling that discards exactly the misspecification. + +If, for some $\delta_0$, the model matches $F$ outside the seasonal bands and matches the mean, then the garbling maps the true process and the model at $\delta_0$ to the same distribution, because two Gaussian processes with the same mean and spectral density are the same process. + +The garbled divergence at $\delta_0$ is then zero, its smallest possible value. + +Hansen and Sargent's footnote 12 on measurement error fits the same reading: + +> Strictly speaking, to avail ourselves of such an argument that consistency can be retained by ignoring seasonal frequencies, it is necessary to assume that the measurement error is *purely* seasonal. Such a measurement error process would be linearly deterministic, i.e., perfectly predictable linearly from its own past. + +For deleting the bands to remove a measurement error completely, the error's spectral density must be zero outside the bands. + +The integral of the logarithm of that spectral density is then $-\infty$, and Kolmogorov's formula of {ref}`ae_ar_section` gives a one-step-ahead forecast error variance $\sigma^2_\infty = 0$. + +### Low-frequency filters + +Hansen and Sargent end their paper by extending the argument to other filters: + +> Formally, the same arguments that support the use of seasonally adjusted data also apply to using data that have been filtered to eliminate, say, low-frequency components. For example, Hodrick and Prescott (1980) compose what is essentially a high-pass filter that eliminates very-low-frequency components from time series while leaving business cycle and higher frequencies intact. Prescott and many other researchers have tried to match data that have been filtered with the Hodrick–Prescott filter to theoretical models that they have designed explicitly to capture business cycle frequencies, but whose low-frequency properties they distrust. Such an empirical strategy can probably be rationalized through an appropriate application of our approximation criterion (4.2). + +The cyclical component of the filter of {cite:t}`HodrickPrescott1997` with smoothing parameter $\lambda$ has frequency response + +$$ +h(\omega) = \frac{4 \lambda (1 - \cos \omega)^2}{1 + 4 \lambda (1 - \cos \omega)^2} , +$$ + +which is zero only at $\omega = 0$. + +Because $h(0) = 0$, the filter removes the mean, and the mean term of {eq}`ae_kl_rate_vector` drops out; because $h$ is zero at no other frequency, filtering both the data and the model leaves the rest of the divergence rate unchanged. + +For the stationary processes of this lecture, Gaussian maximum likelihood estimates of a model fitted to Hodrick–Prescott filtered data, with the model's spectral density filtered in the same way, therefore converge to the same m-projection as estimates from unfiltered data with the mean term dropped. + +In large samples, the filter can change what an econometrician estimates in three ways: + +* it can be applied to the data but not to the model, as in Sims's formulation; +* it can be replaced by the deletion of a band of low frequencies from the frequency-domain likelihood, a garbling that can improve the estimates when the model is wrong mainly at low frequencies, which is the case that Hansen and Sargent describe; or +* it can be used with a criterion that is not a likelihood, such as the distance between a few variances and covariances of the filtered data and of the filtered model, in which the frequency response of the filter weights the frequencies. + +The code below uses the smoothing parameter $\lambda = 1600$ that is customary for quarterly data. + +```{code-cell} ipython3 +λ = 1600 +h_hp = 4 * λ * (1 - np.cos(ω))**2 / (1 + 4 * λ * (1 - np.cos(ω))**2) +print(f"D(f || g) = {kl_rate(f_y, g_full):.6f}, " + f"D(h²f || h²g) = {kl_rate(h_hp**2 * f_y, h_hp**2 * g_full):.6f}") +a_hp, _ = ar_projection(h_hp**2 * f_y, 1) +print(f"AR(1) projection of filtered data, unfiltered model: ρ* = {a_hp[0]:.4f}") +``` + +In the seasonal example, fitting an unfiltered AR(1) to filtered data gives $\rho^* = 0.16$, because the filter removes the low-frequency power that pulls the projection toward $0.9$. + +### Sampling + +Sampling a continuous-time process at integer dates is also a garbling: the sampled series is a function of the continuous-time path, under the true process and under the model alike. + +So is the averaging over unit intervals that Sims uses in column (4) of his Table I. + +The denominator of {eq}`ae_folding`, the spectral density of the sampled regressor, shows the garbling in the frequency domain: sampling adds to frequency $\omega$ the contributions of the frequencies $\omega + 2\pi k$. + +Applied to two continuous-time models, the data processing inequality says that sampling cannot make them easier to tell apart. + +Two continuous-time processes whose spectral densities fold to the same discrete-time spectral density are observationally equivalent from sampled data, and in Sims's setting, distinct continuous-time lag distributions can have the same discrete-time lag distribution $B$. + +An econometrician who reads $B$ as $b$ faces this identification problem. + +{cite:t}`HansenSargent1983` describe it: + +> It is a well known result from the theory of continuous time, covariance stationary stochastic processes that the continuous time spectral density function cannot, in general, be inferred from equispaced discrete time observations. This identification problem is commonly referred to as the aliasing phenomenon. + +They show that restricting the continuous-time spectral density matrix to be rational "goes a significantly greater distance towards resolving the aliasing problem than has heretofore been recognized." + +Within the class of models with rational spectral densities, in general only a finite number of continuous-time models are observationally equivalent, in some regions of the parameter space "there may be no identification problem at all," and for a first-order vector Markov process "there generally exists a discrete sampling interval sufficiently fine that the continuous time model is identified." + +Sampling is not one-to-one on the set of all continuous-time processes, but it can be one-to-one on a restricted family. + +Hansen and Sargent add that the restrictions that economic theory imposes can also serve to identify the continuous-time model. + ## Concluding remarks The maximum likelihood estimator of a misspecified time series model converges to the m-projection of the true process onto the model. @@ -1036,6 +1354,12 @@ In the first example of {cite:t}`Sims1993`, a misspecified seasonal model of una {doc}`specification_tests` describes tests that compare two projections. +Filtering, deleting frequency bands, removing seasonal means, and sampling are garblings, and the data processing inequality orders the divergences that they leave; it does not order the estimates. + +Hansen and Sargent's three kinds of data form a chain of garblings, and their misspecified econometrician obtains the best estimates from the coarsest data, reversing the ranking that Blackwell's theorem gives a decision maker who knows the true likelihoods. + +With a correctly specified model, deleting frequencies cannot lower the asymptotic variance of the estimator; in the misspecified seasonal example, deleting the seasonal bands lowers both the bias and the variance. + ## Exercises ```{exercise} @@ -1190,3 +1514,82 @@ Filtering the model as well as the data removes the bias that filtering the data ```{solution-end} ``` + +```{exercise} +:label: ae_ex_tradeoff + +Hansen and Sargent's concluding remarks mention "a trade-off between variance and bias of estimators, the dimensions of which we have not explored in this paper." + +In the seasonal example, let the variance of the seasonal component $s_t$ be a fraction $q$ of the variance of $x_t$; the example in the lecture has $q = 1/4$. + +An econometrician fits an AR(1) by frequency-domain maximum likelihood to $T$ observations with seasonal bands of width $\Delta$ deleted, and wants to estimate the coefficient $0.9$ of the nonseasonal component. + +Measure the error of the estimator by the asymptotic root mean squared error $\sqrt{(\rho^*_K - 0.9)^2 + V_K / T}$, where $\rho^*_K$ is the AR(1) projection over the frequencies outside the bands and $V_K$ is the $(1, 1)$ element of the covariance matrix {eq}`ae_sandwich`. + +1. For $q \in \{0, 0.0005, 0.002, 0.005, 0.01, 0.25\}$ and $\Delta \in \{0, \pi/32, \pi/16, \pi/8, \pi/4, \pi/2\}$, compute $\rho^*_K - 0.9$, $V_K$, and the asymptotic root mean squared error for $T = 400$, and find the band width that minimizes the error. How much does the choice among the narrow widths matter? +2. Explain why $\Delta = 0$ is best when $q = 0$ and why the best band width grows with $q$. +3. Find the best band widths for $T = 1600$, and explain why they are at least as wide as those for $T = 400$. +``` + +```{solution-start} ae_ex_tradeoff +:class: dropdown +``` + +Here is one solution. + +```{code-cell} ipython3 +f_s_unit = f_s / np.mean(f_s) # seasonal shape, unit variance +widths = np.pi * np.array([0, 1 / 32, 1 / 16, 1 / 8, 1 / 4, 1 / 2]) +header = "".join(f"{Δ / np.pi:9.4f}π" for Δ in widths) + +bias_variance = {} +for q in (0, 0.0005, 0.002, 0.005, 0.01, 0.25): + f = f_x + q * np.mean(f_x) * f_s_unit + bias, V = [], [] + for Δ in widths: + keep = seasonal_keep(Δ) + a_K, σ2_K = ar_projection(f, 1, keep) + bias.append(a_K[0] - ρ_x) + V.append(ar1_covariance(f, a_K[0], σ2_K, keep)[0, 0]) + bias_variance[q] = np.array(bias), np.array(V) + +print(" q " + header) +for q, (bias, V) in bias_variance.items(): + print(f"{q:6.4f} ρ*-0.9" + "".join(f"{np.round(b, 4) + 0.0:10.4f}" for b in bias)) + print(f"{'':6s} V_K " + "".join(f"{v:10.4f}" for v in V)) + +for T in (400, 1600): + print(f"\nT = {T}: asymptotic root mean squared error") + print(" q" + header + " best") + for q, (bias, V) in bias_variance.items(): + rmse = np.sqrt(bias**2 + V / T) + print(f"{q:6.4f}" + "".join(f"{r:10.4f}" for r in rmse) + + f" {widths[rmse.argmin()] / np.pi:.4f}π") +``` + +With $q = 0$, the AR(1) is correct, so the projection equals $0.9$ for every band width, and $V_K = \mathcal{I}_K^{-1}$ rises with $\Delta$ by the Fisher-information form of the data processing inequality. + +Using all frequencies is best. + +With $q > 0$, the estimator that uses all frequencies is biased, and its variance includes the periodogram ordinates at the seasonal peaks with the weight $(f/g)^2$. + +Deleting a narrow band removes most of both. + +Widening the band further reduces the bias; for small $q$ it raises the variance, because the added frequencies carry information about $\rho$ and little misspecification. + +For $T = 400$, the best band width grows from $\pi/32$ at $q = 0.0005$ to $\pi/16$ at $q = 0.002$ and $0.005$, $\pi/8$ at $q = 0.01$, and the widest width in the grid at $q = 1/4$. + +For $q \leq 0.005$, the root mean squared error is nearly flat across the narrow band widths: the best width beats the next best by about 0.2 percent or less. + +Deleting some band matters more than its width: at $q = 0.01$ and $T = 400$, the error is $0.0287$ with all frequencies and $0.0223$ with the best width. + +For part 3, the squared bias falls as the band widens and does not depend on $T$, while the variance term $V_K / T$ shrinks as $T$ grows. + +A larger sample puts relatively more weight on the squared bias, so a band narrower than the best one for $T = 400$ cannot be best for $T = 1600$. + +At $q = 0.005$ the best width rises from $\pi/16$ to $\pi/8$, by a margin of about 0.1 percent; at the other values of $q$ it does not change. + +With all frequencies the error falls more slowly than with the best band, because its squared bias does not shrink: at $q = 0.01$ it is $0.0187$ for $T = 1600$, against $0.0112$ with the best width. + +```{solution-end} +``` diff --git a/lectures/blackwell_kihlstrom.md b/lectures/blackwell_kihlstrom.md index 42b907b3b..3d486743d 100644 --- a/lectures/blackwell_kihlstrom.md +++ b/lectures/blackwell_kihlstrom.md @@ -74,7 +74,7 @@ The lecture proceeds as follows. 2. We state three equivalent criteria for ranking experiments and Blackwell's theorem. 3. We develop Kihlstrom's Bayesian interpretation through standard experiments, mean-preserving spreads, and convex order. 4. We study DeGroot's uncertainty functions and two applications. -5. We connect Blackwell's order to the data processing inequality and to the likelihood-ratio learning of {doc}`likelihood_bayes`. +5. We connect Blackwell's order to the data processing inequality, to the filtering and seasonal adjustment of time series, and to the likelihood-ratio learning of {doc}`likelihood_bayes`. Python simulations illustrate each step. @@ -1305,6 +1305,62 @@ This observation was placed at the center of the study of what deep networks lea The DPI says the same thing in reverse: garbling (decreasing $\theta$) can only contract these measures. +### Garbling a time series + +{doc}`approximation_errors` applies the DPI to the filters that econometricians apply to time series. + +When an econometrician filters a time series, the filtered series is the same function of the unfiltered series whatever process generated the data, so a filter is a deterministic Markov kernel. + +For two stationary Gaussian processes with spectral densities $f$ and $g$, the KL divergence per observation converges to the divergence rate + +$$ +D(f \| g) = \frac{1}{4\pi} \int_{-\pi}^{\pi} \left[ \frac{f(\omega)}{g(\omega)} - 1 - \log \frac{f(\omega)}{g(\omega)} \right] d\omega , +$$ + +the average over frequencies of KL divergences between normal distributions whose variances are the two spectral densities. + +Filtering both processes by a filter with frequency response $c(e^{-i\omega})$ multiplies both spectral densities by $|c(e^{-i\omega})|^2$. + +* A filter whose frequency response is zero at most at isolated frequencies leaves the ratio $f/g$, and hence the divergence rate, unchanged. A filter whose frequency response is never zero is invertible, so it is a sufficient statistic. It also leaves unchanged the Fisher information matrix $\frac{1}{4\pi}\int \nabla \log g \, \nabla \log g^\top d\omega$ of the frequency-domain likelihood, because filtering adds to $\log g$ the term $\log |c(e^{-i\omega})|^2$, which does not depend on the parameters. This is the equality case of the Fisher-information contraction above. +* Ideal seasonal adjustment, as {cite:t}`HansenSargent1993` define it, drops the finite Fourier transforms of the sample at the frequencies in the seasonal bands. The transforms are an invertible linear function of the sample, so dropping some of them is a garbling at every sample size, and the divergence rate loses the integral over the bands, as {eq}`ae_dpi_bands` in {doc}`approximation_errors` shows. The inequality is strict unless $f = g$ almost everywhere on the bands. A filter that is zero on a band does not achieve this: it makes the filtered processes linearly deterministic, and the filtered sample still carries information from the band. +* Filtering the data but not the model applies the kernel to only one of the two distributions, and the DPI says nothing about it. + +{cite:t}`HansenSargent1993` compare three kinds of data for estimating a rational expectations model whose only misspecification is that it omits seasonal variation in a productivity parameter: seasonally unadjusted data, data with seasonal means removed, and ideally adjusted data. + +Each kind of data is a function of the one before it, so the three experiments are ordered by garbling. + +By Blackwell's theorem, a decision maker who knows the likelihoods weakly prefers the unadjusted data in every decision problem. + +Hansen and Sargent's econometrician gets the best estimates from the coarsest data. + +Their Table 1 reports the probability limits of the estimates, and the absolute errors of those limits are: + +| parameter | unadjusted | seasonal means removed | ideally adjusted | +|:---|---:|---:|---:| +| adjustment cost $\phi_1$ | 0.1132 | 0.0146 | 0.0007 | +| endowment coefficient $a_1$ | 0.5310 | 0.0750 | 0.0013 | +| endowment coefficient $a_4$ | 0.4383 | 0.1598 | 0.0003 | +| endowment coefficient $a_5$ | 0.4298 | 0.1261 | 0.0005 | + +Blackwell's theorem does not apply because the econometrician evaluates the three experiments with the likelihoods of a misspecified model. + +Misspecification is a second reason, beside the one studied in {doc}`information_transfer`, that a decision maker can prefer a garbled experiment. + +{cite:t}`Sims1993` states the other side: "Use of unadjusted data and a correctly specified model of seasonal variation is always the best option." + +The DPI, applied to two different pairs of distributions, describes the trade-off between these positions. + +* Applied to the true process and the model, it says that a garbling cannot increase the misspecification. A garbling that discards exactly the frequencies at which the model is wrong can remove the misspecification. +* Applied to the model at two parameter values, it says that a garbling cannot make them easier to tell apart. Locally, the Fisher information contracts, so when the model is correct the asymptotic variance of the estimator cannot fall. A garbling that maps two parameter values to the same distribution makes them observationally equivalent. + +Sampling a continuous-time process at discrete dates is a garbling of the continuous-time path, and the aliasing problem studied by {cite:t}`HansenSargent1983` is the observational equivalence of continuous-time models whose sampled versions coincide. + +The section {ref}`ae_garbling_section` of {doc}`approximation_errors` works through these results. + +It shows that the DPI orders divergences but not estimates, and that, when the model is misspecified, deleting frequencies can lower the variance of an estimator as well as its bias. + +The section {ref}`st_band_section` of {doc}`specification_tests` builds a Hausman test from the two pairs. + ### Summary of the DPI–Blackwell correspondence The table below collects the precise correspondence between Blackwell's framework and the data-processing and coarse-graining literature. @@ -1319,6 +1375,11 @@ The table below collects the precise correspondence between Blackwell's framewor | Blackwell theorem for two states | $D_f$ dominance for every $f$ $\Leftrightarrow$ a single Markov kernel witnesses dominance | | Chentsov's uniqueness theorem | Fisher information is the unique metric invariant under Markov embeddings (sufficient statistics); it also contracts under Markov kernels | | Information bottleneck $I(T;Y) \leq I(X;Y)$ | DPI for mutual information applied to Markov chain $Y{-}X{-}T$ | +| Filtering a time series, applied to the data and to the model | Deterministic Markov kernel applied to both processes; a filter whose frequency response is zero at most at isolated frequencies leaves the divergence rate unchanged | +| Invertible filter | Sufficient statistic: the divergence rate and the Fisher information are unchanged | +| Ideal seasonal adjustment (dropping the Fourier transforms in the seasonal bands) | Garbling at every sample size; it discards information unless the two spectral densities agree on the bands | +| Sampling a continuous-time process | Garbling; aliasing is the observational equivalence of continuous-time models | +| Misspecified econometrician of {cite:t}`HansenSargent1993` | Prefers a garbled experiment; Blackwell's theorem assumes that the decision maker uses the true likelihoods | (bk_lr_learning)= @@ -1398,6 +1459,8 @@ Blackwell's order implies the data processing inequality for every f-divergence, {doc}`information_transfer` shows that a decision maker can prefer a less informative experiment when the signal is observed by an agent whose interests differ from hers and who must be induced to report it. +{cite:t}`HansenSargent1993` give a second reason: an econometrician whose model is misspecified can obtain better estimates from a garbled experiment, here seasonally adjusted data. + ## Exercises ```{exercise} diff --git a/lectures/divergence_measures.md b/lectures/divergence_measures.md index d5e7b4f95..f01fb65a1 100644 --- a/lectures/divergence_measures.md +++ b/lectures/divergence_measures.md @@ -231,6 +231,8 @@ The data processing inequality says that garbling data cannot make $f$ and $g$ e The section on {ref}`the data processing inequality and coarse-graining ` in {doc}`blackwell_kihlstrom` connects it to Blackwell's ordering of experiments. +{ref}`ae_garbling_section` in {doc}`approximation_errors` applies it to filtering, seasonal adjustment, and sampling of time series. + JS divergence and Chernoff entropy, defined below, also satisfy the data processing inequality. KL divergence plays a central role in statistical inference, including model selection and hypothesis testing. diff --git a/lectures/specification_tests.md b/lectures/specification_tests.md index ddb4d34cb..46f21fc6d 100644 --- a/lectures/specification_tests.md +++ b/lectures/specification_tests.md @@ -427,6 +427,8 @@ $\mathcal{I}_K(\theta)$ is the curvature of a KL divergence, as in {doc}`exponen By {eq}`st_hausman_pythagoras`, the difference between the band-deleted estimator and the full-band estimator has asymptotic covariance matrix $\mathcal{I}_K(\theta)^{-1} - \mathcal{I}(\theta)^{-1}$, where $\mathcal{I}$ uses all frequencies. +Deleting the bands is a garbling in the sense of {doc}`blackwell_kihlstrom`, so $\mathcal{I}_K(\theta) \preceq \mathcal{I}(\theta)$ by the Fisher-information form of the data processing inequality; inversion reverses the matrix order, so this covariance matrix is positive semidefinite. + We apply the test to a first-order autoregression with parameters $\theta = (\rho, \sigma^2)$ fitted to $T = 400$ quarterly observations, deleting bands of width $\pi/8$ around $\pi/2$ and $\pi$, and we test only $\rho$, using the $(1, 1)$ elements of these matrices. Each estimator uses the Fourier frequencies $\omega_j = 2\pi j / T$, $j = 1, \ldots, T - 1$, omitting $j = 0$ because the sample mean is removed, and we evaluate $\mathcal{I}_K$ at the same frequencies, so that $\frac{1}{4\pi} \int_K$ becomes $\frac{1}{2T} \sum_{j \in K}$. @@ -524,6 +526,8 @@ A seasonal component with one or two percent of the variance of $x_t$ pulls the The test is powerful because, for this model, deleting the seasonal bands costs little information about $\rho$, whose information is concentrated at low frequencies: the $(1, 1)$ element of $\mathcal{I}_K(\theta)^{-1} - \mathcal{I}(\theta)^{-1}$ is about 2 percent of the $(1, 1)$ element of $\mathcal{I}(\theta)^{-1}$. +In the language of {ref}`ae_garbling_section` in {doc}`approximation_errors`, the numerator $T(\hat\rho_{\text{band}} - \hat\rho_{\text{full}})^2$ of the statistic is $T$ times the squared shift in the m-projection that deleting the bands causes, plus sampling noise, and the denominator measures the information that deleting them destroys, so the test has power when the shift is large relative to the lost information. + {ref}`st_ex_power` computes the test's asymptotic power from the distance between the two projections, and {doc}`turbulence_inference` applies the same calculation to two explanations of rising earnings instability. ## Concluding remarks @@ -696,5 +700,64 @@ Hausman and McFadden's example shows the opposite error: "For $\lambda$ less tha Once alternatives are nonlocal, the approximation can err in either direction. +Formula {eq}`ae_sandwich` of {doc}`approximation_errors` gives the asymptotic covariance matrix of each estimator under the alternative, which makes the explanation above quantitative. + +The two estimators share the periodogram ordinates outside the bands, so the asymptotic covariance matrix between $\sqrt{T}$ times the errors of the two estimators is $\mathcal{H}^{-1} \mathcal{J}_{\text{cross}} \mathcal{H}_K^{-1}$, where + +$$ +\mathcal{J}_{\text{cross}} = \frac{1}{4\pi} \int_K \nabla \log g_{\text{full}} \, \nabla \log g_{\text{band}}^\top \, \frac{f^2}{g_{\text{full}} \, g_{\text{band}}} \, d\omega , +$$ + +$g_{\text{full}}$ and $g_{\text{band}}$ are the spectral densities of the two projections, and $\mathcal{H}$ and $\mathcal{H}_K$ are the matrices $\mathcal{H}_K$ of {eq}`ae_sandwich` for all frequencies and for the frequencies outside the bands, each evaluated at its own projection. + +The code below computes from these matrices the ratio of the standard deviation of the difference to the null standard deviation, the correlation between $\hat\rho_{\text{full}}$ and the difference, and the power of the test when the statistic is approximated by $V_{\text{diff}} / (V_{\text{band}} - V_{\text{full}})$ times a noncentral $\chi^2_1$ variable with noncentrality $T (\rho^*_{\text{band}} - \rho^*_{\text{full}})^2 / V_{\text{diff}}$, where $V_{\text{diff}}$ is the asymptotic variance of the difference under the alternative. + +```{code-cell} ipython3 +def ar1_derivatives(ρ, σ2): + """∇ log g and ∇² log g at the Fourier frequencies, θ = (ρ, σ²).""" + d1 = np.vstack([2 * (np.cos(ω_T) - ρ) / np.abs(1 - ρ * z_T)**2, + np.ones(T_obs - 1) / σ2]) + d2 = np.zeros((2, 2, T_obs - 1)) + d2[0, 0] = 2 * np.real(z_T**2 / (1 - ρ * z_T)**2) + d2[1, 1] = -1 / σ2**2 + return d1, d2 + + +def projection_parts(f, keep): + """AR(1) projection over keep, the inverse of H, ∇ log g, and f/g on keep.""" + ρ = whittle_ar1(f, keep) + σ2 = np.mean((f * np.abs(1 - ρ * z_T)**2)[keep]) + d1, d2 = ar1_derivatives(ρ, σ2) + r = np.where(keep, f * np.abs(1 - ρ * z_T)**2 / σ2, 0.0) + H = 0.5 * ((d1 * r) @ d1.T + + (d2 * np.where(keep, 1 - r, 0.0)).sum(axis=2)) / T_obs + return ρ, np.linalg.inv(H), d1, r + + +def score_covariance(d_a, r_a, d_b, r_b): + return 0.5 * ((d_a * r_a * r_b) @ d_b.T) / T_obs + + +print("share SD ratio corr(ρ_full, difference) power simulated power") +for share in (0.005, 0.01, 0.02): + f_y = spectral_density_y(share) + ρ_f, H_f, d_f, r_f = projection_parts(f_y, keep_all) + ρ_b, H_b, d_b, r_b = projection_parts(f_y, keep_band) + V_f = (H_f @ score_covariance(d_f, r_f, d_f, r_f) @ H_f)[0, 0] + V_b = (H_b @ score_covariance(d_b, r_b, d_b, r_b) @ H_b)[0, 0] + C_fb = (H_f @ score_covariance(d_f, r_f, d_b, r_b) @ H_b)[0, 0] + V_diff = V_f + V_b - 2 * C_fb + _, _, V_full, V_band = projections[share] + V_null = V_band - V_full + power = ncx2.sf(crit_1 * V_null / V_diff, 1, T_obs * (ρ_b - ρ_f)**2 / V_diff) + print(f"{share:5.3f} {np.sqrt(V_diff / V_null):9.2f} " + f"{(C_fb - V_f) / np.sqrt(V_f * V_diff):19.2f} {power:15.2f} " + f"{simulated_power[share]:12.2f}") +``` + +The covariance matrices under the alternative give ratios of $1.42$, $1.96$, and $2.96$ and correlations of $-0.34$, $-0.51$, and $-0.68$, close to the simulated $1.48$, $2.02$, and $3.01$ and $-0.34$, $-0.50$, and $-0.67$. + +The power approximation that uses them gives $0.47$, $0.77$, and $0.92$, against simulated powers of $0.43$, $0.78$, and $0.98$: it corrects the error at the intermediate share, is slightly farther from the simulation than the null approximation at the smallest share, and understates the power at the largest share. + ```{solution-end} ``` From 7595f05808996e325d6398199894fdbe2359332d Mon Sep 17 00:00:00 2001 From: Matt McKay Date: Sun, 22 Nov 2026 09:11:33 +1100 Subject: [PATCH 3/3] [approximation_errors, specification_tests, turbulence_inference] Review fixes and style pass Address the four Copilot review comments: - approximation_errors: an AR(1) can produce a narrow peak at pi with a coefficient near -1; qualify the sentence. - turbulence_inference: the moment-matching characterization of the random-effects projection needs the same mean in every year. - turbulence_inference: state the assumptions (positive definite S with a nonnegative average off-diagonal element) in ti_ex_projection, and note in the solution why sigma^2_mu >= 0 needs them. - specification_tests: ols_iv now generates the final partial chunk, so R need not be a multiple of chunk. Output is unchanged for R = 20,000. Style pass: - Shorten the eight figure captions so each says what the figure shows. - Change six bolded emphasis sentences to italic; definitions stay bold. No other code changes; all printed output is unchanged. Co-Authored-By: Claude Opus 5.5 --- lectures/approximation_errors.md | 20 +++++++++++--------- lectures/specification_tests.md | 11 ++++++----- lectures/turbulence_inference.md | 16 +++++++++------- 3 files changed, 26 insertions(+), 21 deletions(-) diff --git a/lectures/approximation_errors.md b/lectures/approximation_errors.md index bdb29c194..7de1da178 100644 --- a/lectures/approximation_errors.md +++ b/lectures/approximation_errors.md @@ -140,7 +140,7 @@ We call $D(f \| g)$ the **KL divergence rate** of the process with spectral dens {doc}`likelihood_ratio_process` and {doc}`likelihood_var` write this rate $h_{KL}(f, g)$ and compute it in the time domain, for Markov chains and for Gaussian vector autoregressions; for two first-order vector autoregressions with mean zero, the vector formula {eq}`ae_kl_rate_vector` below equals {eq}`eq:var_kl_rate`. -**The KL divergence rate is the average over frequencies of the KL divergences between normal distributions whose variances are the two spectral densities at each frequency.** +*The KL divergence rate is the average over frequencies of the KL divergences between normal distributions whose variances are the two spectral densities at each frequency.* The transforms $w_j = T^{-1/2} \sum_{t=1}^T y_t e^{-i \omega_j t}$ at the frequencies $\omega_j = 2\pi j / T$ with $0 < \omega_j < \pi$ are, for large $T$, approximately independent complex normal random variables with variances $f(\omega_j)$. @@ -202,7 +202,7 @@ $$ (ae_hs_criterion) Subtracting from $A(\delta)$ the quantity $\frac{1}{2\pi}\int \log \det F(\omega) \, d\omega + n$, which does not depend on $\delta$, leaves twice the divergence rate {eq}`ae_kl_rate_vector`. -Hence **the probability limit of the misspecified maximum likelihood estimator is the m-projection of the true process onto the model, with divergence measured by the KL divergence rate.** +Hence *the probability limit of the misspecified maximum likelihood estimator is the m-projection of the true process onto the model, with divergence measured by the KL divergence rate.* {cite:t}`HansenSargent1993` apply at each frequency $\omega$ what they call "the familiar information inequality for normally distributed random variable": @@ -262,7 +262,7 @@ By Kolmogorov's formula, $\frac{1}{2\pi}\int_{-\pi}^{\pi} \log f(\omega) \, d\om For a vector process, the spectral factorization identity {eq}`eq:sf_identity` of {doc}`kalman_filter_var` gives the counterpart: the average over frequencies of the log determinant of the spectral density matrix of a state-space model's observables equals the log determinant of its innovation covariance matrix, $G\Sigma G^\top + R$ in that lecture's notation. -The second term does not depend on $a$, so **the m-projection of a stationary process onto the autoregressions of order $p$ chooses the coefficients that minimize the mean squared one-step-ahead forecast error.** +The second term does not depend on $a$, so *the m-projection of a stationary process onto the autoregressions of order $p$ chooses the coefficients that minimize the mean squared one-step-ahead forecast error.* Those coefficients solve the Yule–Walker equations $\sum_{k=1}^p a_k \gamma_{j-k} = \gamma_j$ for $j = 1, \ldots, p$; for $p = 1$, $a_1 = \gamma_1 / \gamma_0$. @@ -364,7 +364,7 @@ In the right panel, vertical lines mark the seasonal frequencies $\pi/2$ and $\p --- mystnb: figure: - caption: Spectral densities (left) and the contribution of each frequency to the divergence rate (right) for an AR(1) fitted to a series with a seasonal component + caption: AR(1) projection of a seasonal series name: fig-ae-seasonal-ar1 --- half = ω <= np.pi @@ -396,7 +396,9 @@ plt.tight_layout() plt.show() ``` -A first-order autoregression cannot produce a peak at $\pi/2$ or a narrow peak at $\pi$, so the divergence is largest at those frequencies. +A first-order autoregression cannot produce a peak at $\pi/2$, and it can produce a narrow peak at $\pi$ only with a coefficient near $-1$, which would give up the power near frequency zero. + +So the divergence is largest at those two frequencies. For a given $\sigma^2$, lowering $\rho$ raises the model's spectral density at high frequencies and lowers it near frequency zero. @@ -599,7 +601,7 @@ print_lag_table(t_vals, b_exp(t_vals), col2, col3, col5) --- mystnb: figure: - caption: A continuous-time lag distribution and two discrete-time lag distributions that least squares estimates from sampled data + caption: Continuous-time lag and its sampled projections name: fig-ae-sampled-lag --- t_fine = np.linspace(-4, 8, 600) @@ -696,7 +698,7 @@ print(f"unconstrained coefficient at lag zero, identity lag: " --- mystnb: figure: - caption: Spectral densities of the regressor with and without seasonal noise (left), and the lag distributions that unconstrained least squares estimates (right) + caption: Seasonal noise and estimated lag distributions name: fig-ae-sims-1974 --- fig, axes = plt.subplots(1, 2, figsize=(11, 4)) @@ -1036,7 +1038,7 @@ Filtering therefore applies one Markov kernel, a deterministic one, to both proc When the frequency response $c(e^{-i\omega})$ is zero at most at isolated frequencies, filtering multiplies $f$ and $g$ by $|c(e^{-i\omega})|^2$ and leaves the ratio $f/g$ unchanged at every other frequency, so the divergence rate {eq}`ae_kl_rate` does not change. -**A filter applied to both the data and the model whose frequency response is zero at most at isolated frequencies leaves the divergence rate and the m-projection unchanged, however much it shrinks the spectral densities near those frequencies.** +*A filter applied to both the data and the model whose frequency response is zero at most at isolated frequencies leaves the divergence rate and the m-projection unchanged, however much it shrinks the spectral densities near those frequencies.* If, in addition, the spectral measure of the data puts no mass at those frequencies, the filtered series determines the unfiltered series in mean square, so the filter is a sufficient statistic for the pair, and the invariance of {ref}`ae_ar_section` is the equality case of the data processing inequality. @@ -1226,7 +1228,7 @@ The periodogram ordinates at the seasonal peaks, where $f/g$ is large, enter $\m Deleting bands of width $\pi/8$ removes those ordinates and lowers the variance to $0.31$, so here deleting bands lowers the variance as well as the bias. -**The efficiency cost of deleting frequencies is guaranteed only for correctly specified models.** +*The efficiency cost of deleting frequencies is guaranteed only for correctly specified models.* {ref}`ae_ex_tradeoff` finds the band width that balances bias against variance when the seasonal component is small. diff --git a/lectures/specification_tests.md b/lectures/specification_tests.md index 46f21fc6d..a90759237 100644 --- a/lectures/specification_tests.md +++ b/lectures/specification_tests.md @@ -224,10 +224,11 @@ A just-identified instrumental variables estimator has no finite moments, so we ```{code-cell} ipython3 def ols_iv(σ_uv, rng, n=400, R=20_000, chunk=5_000): b_ols, b_iv = [], [] - for _ in range(R // chunk): # chunks limit memory use - z_ = rng.normal(size=(chunk, n)) - u_ = rng.normal(size=(chunk, n)) - v_ = σ_uv * u_ + np.sqrt(1 - σ_uv**2) * rng.normal(size=(chunk, n)) # V + for start in range(0, R, chunk): # chunks limit memory use + size = min(chunk, R - start) + z_ = rng.normal(size=(size, n)) + u_ = rng.normal(size=(size, n)) + v_ = σ_uv * u_ + np.sqrt(1 - σ_uv**2) * rng.normal(size=(size, n)) # V x_ = Π * z_ + v_ y_ = β_true * x_ + u_ b_ols.append((x_ * y_).sum(axis=1) / (x_ * x_).sum(axis=1)) @@ -333,7 +334,7 @@ for n2, n3 in ((230, 270), (180, 320)): --- mystnb: figure: - caption: KL divergence per choice of alternative 2 or 3, and the quadratic approximations behind the LM and Hausman statistics + caption: KL divergence and its quadratic approximations name: fig-st-iia --- s_vals = np.linspace(0.2, 0.8, 300) diff --git a/lectures/turbulence_inference.md b/lectures/turbulence_inference.md index c14e43702..6850c50bc 100644 --- a/lectures/turbulence_inference.md +++ b/lectures/turbulence_inference.md @@ -179,7 +179,7 @@ The figure shows the distribution of skills after a layoff for a worker who had --- mystnb: figure: - caption: Distribution of skill after a layoff for a worker with the highest skill + caption: Skill after a layoff from the top level name: fig-ti-layoff --- fig, ax = plt.subplots() @@ -412,7 +412,7 @@ The model's distribution of earnings is discrete, so its KL divergence from ever The proof of {prf:ref}`ip_thm_m_projection` applies instead to the cross-entropy $-E[\log q_\theta(y_i)]$, which differs from the KL divergence by the entropy of $y_i$ whenever $y_i$ has a density. -For any distribution of $y_i$ with a nonsingular covariance matrix whose average off-diagonal element is nonnegative, the parameters that minimize the cross-entropy match the expectations of the sufficient statistics, which sets $m = E[\bar y_i]$ and +For any distribution of $y_i$ with the same mean in every year and a nonsingular covariance matrix whose average off-diagonal element is nonnegative, the parameters that minimize the cross-entropy match the expectations of the sufficient statistics, which sets $m = E[\bar y_i]$ and $$ E[W_i] = (T - 1) \sigma^2_\nu , @@ -426,7 +426,7 @@ We call this minimizer the m-projection of the distribution of $y_i$ onto the ra The projection sets $\sigma^2_\nu$ equal to the average expected periodogram at the nonzero Fourier frequencies, and, for $y_i$ with mean zero, as in our year-demeaned panels, $T\sigma^2_\mu + \sigma^2_\nu$ equal to the expected periodogram at frequency zero. -**For a balanced panel, Gottschalk and Moffitt's permanent and transitory variances are the parameters of the m-projection of the distribution of a man's earnings onto the random-effects model**: formulas {eq}`ti_gm` are the expressions above with the sample of men in place of the population, apart from the divisor $N - 1$ in the variance of the averages. +*For a balanced panel, Gottschalk and Moffitt's permanent and transitory variances are the parameters of the m-projection of the distribution of a man's earnings onto the random-effects model*: formulas {eq}`ti_gm` are the expressions above with the sample of men in place of the population, apart from the divisor $N - 1$ in the variance of the averages. The projection is defined whether or not the random-effects model describes the data. @@ -588,7 +588,7 @@ model_sd_bins = np.arange(0.1, 0.71, 0.1) --- mystnb: figure: - caption: Distributions of men's average log earnings (left) and of their standard deviations of earnings around those averages (right), in the PSID (top, read from Gottschalk and Moffitt's Figures 2 and 4) and in artificial panels from the laissez-faire economy (bottom) + caption: Earnings histograms in the PSID and the model name: fig-ti-histograms --- fig, axes = plt.subplots(2, 2, figsize=(11, 7)) @@ -671,7 +671,7 @@ for v, b in zip(list(v_grid) + [np.inf], list(binding) + [b_uniform]): --- mystnb: figure: - caption: Changes in the model's permanent and transitory variances relative to the turbulence parameter 0.02, for turbulence parameters from 0.01 to 1, compared with the changes that Gottschalk and Moffitt measured + caption: Binding function against the measured changes name: fig-ti-binding --- fig, axes = plt.subplots(1, 2, figsize=(11, 4)) @@ -1017,7 +1017,7 @@ for name, res in (("turbulence 0.04", turbulent), --- mystnb: figure: - caption: Twelve-week earnings of stayers and separators in the laissez-faire economy with turbulence parameter 0.04 + caption: Earnings of stayers and separators name: fig-ti-jls --- fig, ax = plt.subplots() @@ -1066,7 +1066,7 @@ Measuring that change requires comparable displaced-worker studies from both per ```{exercise} :label: ti_ex_projection -Let $y_i$ be a random vector in $\mathbb{R}^T$ with mean zero and covariance matrix $S$, and consider the random-effects family $N(0, \sigma^2_\mu \mathbf{1}\mathbf{1}^\top + \sigma^2_\nu I)$. +Let $y_i$ be a random vector in $\mathbb{R}^T$ with mean zero and a positive definite covariance matrix $S$ whose average off-diagonal element is nonnegative, and consider the random-effects family $N(0, \sigma^2_\mu \mathbf{1}\mathbf{1}^\top + \sigma^2_\nu I)$. 1. Show that the inverse of $\Sigma = \sigma^2_\mu \mathbf{1}\mathbf{1}^\top + \sigma^2_\nu I$ is $\sigma_\nu^{-2} \left(I - c\,\mathbf{1}\mathbf{1}^\top\right)$ with $c = \sigma^2_\mu / (\sigma^2_\nu + T \sigma^2_\mu)$, and that $\log p(y_i)$ is a linear function of $W_i$ and $T \bar y_i^2$ plus a function of the parameters. 2. Minimize the Gaussian KL divergence of $N(0, S)$ from $N(0, \Sigma)$ over $(\sigma^2_\mu, \sigma^2_\nu)$ and show that the minimizer sets $\sigma^2_\nu = (\operatorname{tr} S - \mathbf{1}^\top S \mathbf{1}/T)/(T - 1)$ and $\sigma^2_\mu = \mathbf{1}^\top S \mathbf{1}/T^2 - \sigma^2_\nu / T$. @@ -1107,6 +1107,8 @@ The minimizer sets $\sigma^2_\mu + \sigma^2_\nu$ equal to the average diagonal e Since $\operatorname{tr} S = T \bar s_d$ and $\mathbf{1}^\top S \mathbf{1} = T\bar s_d + T(T - 1)\bar s_o$, the formulas of part 2 give $\sigma^2_\nu = \bar s_d - \bar s_o$ and $\sigma^2_\mu = \bar s_o$. +So $\sigma^2_\mu \geq 0$ exactly when the average off-diagonal element of $S$ is nonnegative, which is why the exercise assumes it. + ```{code-cell} ipython3 S = np.cov(y04.T) T = len(S)