With the logistic link, every estimate stays between 0 and 1.
Computational Approaches to the Non-Observed EconomyMeasuring
Module 4Estimating the size
Fifty invented countries, thirty with a careful benchmark and twenty without: fill in the twenty and say how sure you are. We write the estimation task down, place each method in its history, fit linear models with the right shape and read their coefficients as what-if answers, then try trees, nearest neighbours, support vectors, boosting and a neural network. Random rows flatter the flexible models; whole held-out countries put the simple, well-shaped model first. Finally ranges: an ensemble's spread and quantile models are overconfident, while a Gaussian process and conformal prediction calibrated on whole countries keep their 90% promise.
Key ideas, one per video
- Video 7A logistic link removed the negative estimates and cut the error on new countries from 4.9 to 4.2 points. Tax alone goes with almost 15 fewer points per 5 points of tax; with controls the sign flips to about +2, near the true +1.
- Video 8Trees, neighbours, support vectors and boosting look best on random rows. On the twenty new countries the linear model with a link won (4.2 points), ahead of support vectors (5.5) and boosting (6.0).
- Video 9A small neural network was unstable with thirty countries. Ranges from an ensemble's spread covered 37% and quantile boosting 52%; a Gaussian process and conformal prediction calibrated on whole countries covered 90%.
Book: Chapter 4 of Computational Approaches to the Non-Observed Economy: From Theory to Practice (coming soon). The videos and slides follow the chapter’s topics in our own words, figures and simulations; the towns and countries are invented, and nothing is copied from the book.
Watch
3 videos for this module, each about 8 to 11 minutes. Pick one from the list, and open the transcript to read along: each timestamp plays the video from there. The narration is generated with a voice clone of Teddy, used with his permission.
Video 7 · 8:19
The estimation task and linear models
Fill in twenty countries nobody has studied. A straight line predicts a hidden economy below zero for five country-years.
A logistic link removed the negative estimates and cut the error on new countries from 4.9 to 4.2 points. Tax alone goes with almost 15 fewer points per 5 points of tax; with controls the sign flips to about +2, near the true +1.
TranscriptVideo 7
Fill in twenty countries. Here are fifty invented countries. For thirty of them, the statistics office has done a careful study of its hidden economy. For the other twenty, nobody has. Your job is to fill in the twenty. And because we invented this world, we can check every answer against the truth. We start with the simplest tool there is: a straight line through the data. It does surprisingly well. But for five country-years, it predicts a hidden economy smaller than zero. Change one thing, the shape of the link between the line and the share, and the negative shares disappear. The error drops too, from about 5 points to about 4. That's the spirit of this module. Every estimator carries assumptions. Good estimation is choosing them on purpose.
Three videos, one world. Welcome to Module 4: estimating the size of the non-observed economy. I'm Teddy. This module has three videos. This one sets up the task and the linear models. The next one covers trees, neighbours, margins and boosting. The last one covers neural networks, honest uncertainty, and a fair comparison. All three use the same invented world, which we call the Archipelago. Fifty countries, twelve years each.
The estimation task. Let's write the task down carefully. A unit can be a country in a year, a region, a sector or a firm. For each unit, there's a hidden share we never see directly. Multiply that share by an observed scale, like official GDP, and you get the hidden economy in money. Say what the share is a share of. In the Archipelago, it's a share of everything produced, hidden or not. As we saw in Module 1, dividing by official GDP gives a bigger number for the same activity. What we do see comes in three kinds. Causes: things that push activity into hiding, like tax burden, weak enforcement or low trust. Indicators: traces that hidden activity leaves, like extra cash, a gap between spending and declared income, or electricity that recorded output can't explain. And benchmarks: careful estimates for a few units, from audits, special surveys or the statistics office's own completeness checks. A general estimator balances three wishes at once. Explain the indicators. Agree with the benchmarks where they exist. And stay plausible, for example by changing smoothly from year to year, and staying between zero and one. In the Archipelago, the benchmark exists for thirty countries, and it's close to the truth. Our models learn from those thirty, and estimate the other twenty. That's a realistic setting. Careful benchmarks are expensive, so they exist for some countries and not others. The rest need a model that carries the measured level across.
A short history. This task has a long history, and it helps to know it, because modern models inherit its assumptions. The earliest estimates read money. If hidden trade needs cash, then cash beyond what normal habits explain points to hidden activity. Everything depends on what counts as normal. Later came models with a hidden variable, which link several causes and several indicators to one unobserved size. Others compared what households spend with what they declare, or electricity with recorded output. Direct surveys and audits got better too, with careful wording for sensitive questions. And statistics offices developed their own methods, built into the national accounts. The main lesson of that history: no single method is a reliable benchmark. They measure different parts of the hidden economy, under different assumptions. So the best evidence triangulates.
Linear models and shape. Now, the linear model. Predict the hidden share as a weighted sum of the inputs. The computer picks the weights that make the errors on the thirty countries as small as possible. Its strength is that you can read it. Each weight says how the prediction moves when one input moves, and the others stay fixed. How does it pick the weights? It squares each error and adds them up. Squaring punishes big misses more than small ones, and it makes the best weights easy to compute. To report how good a model is, we'll use the average size of the miss, in points of hidden share. Four points means that a typical estimate of, say, twenty percent could really be sixteen or twenty-four. Its first weakness is shape. A share lives between zero and one. A straight line doesn't know that. In the Archipelago, the straight line predicts negative hidden shares for five country-years. The lowest is minus three percent. The fix is a link function. Fit the line to the log-odds of the share, then squeeze the result back between zero and one. Small shares stay small, but never negative. With the link, the lowest prediction is about three percent, and the error on the twenty new countries falls from 4.9 points to 4.2.
A sign that flips. The second weakness is interpretation. Let's look at the tax burden. Before the numbers, a quick guess. Across countries, do higher taxes go with more hidden activity, or less? Fit the share on tax alone, across countries. Five more points of tax go with almost fifteen fewer points of hidden activity. Add enforcement, trust and the other causes, and the sign flips. Now five more points of tax go with about two points more. We built this world, so we know the truth: about one point more. The controlled model has the right sign, and the right order of size. A coefficient answers the question: what if this input changed and the others didn't? Leave out the others, and you answer a different question. And inputs that move together, like enforcement and trust, make individual weights unstable, even when the predictions are fine. Report predictions with confidence. Read single weights with care.
Regularisation and two checks. With many inputs and few countries, a model can chase noise. Regularisation pushes weights towards zero, unless the data insist. The lasso goes further: it sets some weights exactly to zero, so it also chooses inputs. In our world, it kept ten of the eleven inputs, and dropped bank access. Its cousin, ridge regression, shrinks all the weights a little instead of zeroing some. It helps most when inputs move together. Here, it didn't help. The lasso's error on new countries was about 5 points, a little worse than the plain model with a link. Regularisation earns its keep when inputs are many and data are scarce, and in this world they aren't scarce enough. One more check. We estimated the linear model's error two ways: holding out random rows, and holding out whole countries. Both said about 5 points. A simple model can't memorise a country's quirks, so the two checks agree. Keep that in mind for the next video, where they won't.
Look at the data first. Before you trust any of this, look at the data itself. Where does each variable come from? Which countries are missing which years? Is the benchmark a measurement, or someone else's model? Plot each input against the benchmark. Look for breaks in series, for countries that sit far from the rest, and for inputs that are almost copies of each other. Check the benchmark too. Is it the same kind of estimate in every country? A benchmark built from a survey in one country and from tax audits in another isn't one target, it's two. And look at time. A series that jumps in one year, in one country, is more often a change in how it was measured than a change in the economy. In the Archipelago, the currency ratio depends on cash habits as much as on hiding. A model that leans on it will be wrong wherever habits differ. That kind of knowledge doesn't come from the fit. It comes from knowing how the data were made.
Recap. Let's recap. The estimation task has a hidden share, an observed scale, causes, indicators, and benchmarks for some units. A good estimator explains the indicators, respects the benchmarks, and stays plausible. History says no single method is a reliable benchmark, so triangulate. Linear models are readable. Give them the right shape with a link function, read coefficients as what-if answers with everything else fixed, and expect unstable weights when inputs move together. In the Archipelago, a linear model with a logistic link estimates the twenty new countries within about four points. In the lab, you'll build the Archipelago's linear model, switch the link on and off, and watch a coefficient flip as you add controls. Next: trees, neighbours, margins and boosting. They're more flexible. Are they better?
The tree's first question. We asked a decision tree to estimate the hidden economy of our fifty invented countries. Its very first question was about enforcement. Is enforcement below zero point three five? If yes, the hidden share is much higher. That's exactly the threshold we built into this world. Nobody told the tree. It found it in the data. Flexible models can discover shapes we didn't write down. The question for this video is what that flexibility costs.
Four families. Welcome back to Module 4. This is video two: trees, margins, neighbours and boosting. Same task as before. Thirty countries with a careful benchmark, twenty without, and we score on the twenty against the truth. We'll meet four families of models, then put them side by side, with two different ways of checking them. A reminder of what makes this world hard. The hidden share jumps when enforcement is weak. Cash matters more where banks are scarce. And each country has quirks no input explains.
Decision trees and depth. A decision tree asks a sequence of yes or no questions. Each question splits the data on one input, at the value that makes the two groups as different as possible. At the end of each path, it predicts the average of the countries that landed there. To choose each question, the tree tries every input and every cut point, and keeps the one that reduces the error the most. Then it repeats inside each group. After the enforcement question, our tree asks about the spending gap on one side, and the currency ratio on the other. You can read it like a flowchart. The danger is depth. Let the tree grow, and it ends up with one country-year per leaf. Its error on the training data drops to zero. But on new countries, deep trees are no better than a tree four questions deep. The extra questions only memorise noise. So the depth is chosen by checking on held-out data. In our world, four questions was best. Trees have a big advantage for this field: they need no scaling, they handle odd distributions, and a shallow one can be shown to a minister on one slide.
Nearest neighbours. The second family is the nearest neighbours. To estimate a country, find the countries that look most like it, and average their benchmarks. It's intuitive. It's how many experts actually reason. This country looks like those countries, so its hidden economy is probably similar. Two choices matter. How many neighbours: in our world, ten worked best. And what similar means: inputs measured in different units have to be put on the same scale first. If you measure tax burden in percent and population in people, population will decide every neighbour. Scaling makes each input count on a comparable footing. Its weakness is that every input counts as much as every other, unless you weight them. Irrelevant inputs make countries look alike for the wrong reasons. It also can't extrapolate. A country more extreme than any in the training data gets the average of the most extreme ones it knows, which is too moderate.
Support vector regression. The third family is support vector regression. It fits a tube around the data, and ignores errors smaller than the tube's width. Only the points outside the tube shape the model, so it's quite robust to small noise. With a kernel, the tube can bend, so it isn't limited to straight lines. It's sensitive to scaling, and to two or three settings that control the tube's width and how much it can bend. Those settings need careful checking too. In our world, its random-row score was about five points, close to the best. On whole held-out countries, it rose to about six. Keep those two numbers in mind.
Boosting. The fourth family is boosting, and in practice it's often the strongest. Gradient boosting libraries like XGBoost are everywhere in applied work. The idea is to build many small trees in a row. Each new tree looks at the errors left by the trees before it, and tries to fix a little of them. Add trees, and the training error keeps falling, towards zero. The error on new countries falls quickly, and then stops improving after about a hundred trees. That's why boosting needs early stopping, a small learning rate, and shallow trees. Each one limits how much noise it can learn. The learning rate is how much of each new tree's correction we keep. Small steps, many trees, and a stop when held-out error stops falling: that's the standard recipe. Boosted models are hard to read directly, but you can ask them questions. Hold everything fixed, slide enforcement from low to high, and watch the average prediction. Below about zero point three five, the boosted model predicts about thirty-seven percent hidden. Above it, about twenty-four. It found the threshold too. Shuffle one input at a time, and see how much worse the predictions get. The currency ratio matters most, then enforcement, then the spending gap.
The check decides the winner. Now the comparison. First, the way many studies do it: hold out random rows, train on the rest, and measure the error. On that check, the flexible models look best. Boosting scores about 4.7 points, the support vector model 5.0, and the linear model 5.0. Before the next result, pause. Which model do you expect to do best on the twenty countries it has never seen? On the new countries, against the truth, the order changes. The linear model with a logistic link is best, at about 4.2 points. The support vector model comes next, at 5.5. Boosting gets 6.0. The tree and the neighbours both about 6.9. The random-row check flattered the flexible models. A country's years look alike, so random rows let a model recognise a country it has already seen. Holding out whole countries tells a much more honest story. On that check, boosting's score rises to about 5.3, the neighbours' to 6.0, and the tree's to 6.4. With only thirty countries to learn from, a model with the right shape beat models that could learn any shape. That's not a law. With more countries, or stronger non-linear effects, the ranking could flip. Why does memorising a country help on random rows? Because a country's twelve years share its institutions and its quirks. Seeing eleven of them makes the twelfth easy. Seeing none is the real task.
How to choose. So which should you use? Here's a practical way to choose. Start with a linear model, with the right link and sensible inputs. It's your baseline, and it's readable. Then try a flexible model. If it beats the baseline on whole held-out countries, not just random rows, use what it learned. Look at its partial dependence for shapes like thresholds. Use the same held-out countries for every model, the same inputs, and a similar effort tuning each one. Otherwise you're comparing effort, not models. And sometimes you can put what the flexible model found back into the simple one. We tried it: a weak-enforcement flag in the linear model. In our world, it didn't help. The error went from 4.2 to 4.4 points. The threshold is real, but with thirty countries, other errors dominate. Testing an idea is cheaper than believing it.
Recap. Let's recap. Trees ask yes-or-no questions and can find thresholds. Their depth must be chosen on held-out data. Neighbours average similar countries, so scaling and the choice of inputs decide what similar means. Support vector models fit a tube, and need careful settings. Boosting builds many small trees that fix each other's errors. It's strong, but it needs early stopping, and questions like partial dependence to be read. And the way you check decides the winner. Random rows flattered the flexible models. Whole held-out countries put the simple, well-shaped model first. And testing an idea, like putting the threshold into the simple model, is cheaper than believing it. In the lab, you'll grow a tree question by question, change the number of neighbours, and run both checks yourself. Next: neural networks, error bars you can trust, and an honest comparison of everything.
Ranges that keep their promise. Five models give an estimate for the same invented country, each with a ninety percent range. In theory, each range should contain the truth nine times out of ten. We checked them on twenty countries none of them had seen. One range contained the truth only thirty-seven percent of the time. Another, fifty-two percent. Two of them got it right: ninety percent, as promised. A number without an honest range can mislead. A range that isn't honest misleads more. This video is about telling them apart.
Three parts. Welcome to the last video of Module 4. I'm Teddy. We'll start with neural networks, then move from single numbers to ranges, and end with a fair comparison of everything we've built in this module. Same setting as before: thirty countries with a careful benchmark, twenty without, and the truth hidden in our pocket to check every answer.
Neural networks need data. A neural network stacks simple units in layers. Each unit takes a weighted sum of its inputs and bends it. Stack enough of them, and the network can represent almost any shape. That power has a price: data. A network has many weights, and with few examples it fits noise easily. Training adjusts all the weights a little at a time, to reduce the error. Tricks like weight penalties, and stopping before the training error hits zero, keep it from memorising. We trained the same small network on six, twelve, eighteen, twenty-four and thirty of the Archipelago's benchmark countries. Its error on the new countries jumped around: about 29 points with six countries, 8 with twelve, 19 with eighteen, and about 6 with thirty. The linear model stayed between about four and five and a half points the whole way. With thirty countries, deep learning has little to learn from. It shines with many units, like regions, firms or satellite images, and with careful regularisation. Even then, keep the target in mind. A network trained on a published estimate learns the estimate, just like any other model. Networks can also predict a range directly. Instead of one number, the network outputs a centre and a spread, and is trained to make the truth likely under that spread.
Why ranges. Now, ranges. A single number hides how unsure you are. Twenty percent, give or take two, and twenty percent, give or take twelve, lead to different decisions. Uncertainty has several sources. The benchmark itself is noisy. The model's form might be wrong. And a new country can be unlike any country in the training data. The first source, noise in the benchmark, never goes away with more data. The last one, a country unlike the others, is the most dangerous, because a model can't know what it hasn't seen. A probabilistic estimator gives a whole distribution, or at least a range. There are several ways to get one, and they don't capture the same sources. We tried five on the Archipelago, each asked for a ninety percent range, and counted how often the truth fell inside, on the twenty new countries.
Ensembles, quantiles, a Gaussian process. First, an ensemble. Train many boosted models on resampled data, and take the spread of their predictions. That spread only measures how much the model wobbles. It contained the truth only thirty-seven percent of the time. The ranges were narrow, and they ignored the noise and the differences between countries. Second, quantile boosting. Train one model for the low end and one for the high end. Better, but still only fifty-two percent. A quantile model is trained with a lopsided error. For the high end, missing below costs nineteen times more than missing above, so the model learns a line that only one country in twenty should cross. Both were tuned on countries they had seen, and they were overconfident about countries they hadn't. Third, a Gaussian process. It's a model that comes with its own uncertainty, which grows as a new country gets further from the ones it knows. It covered the truth ninety percent of the time, with ranges about nineteen points wide. That honesty isn't guaranteed. A Gaussian process trusts its own assumptions about smoothness. Here they happened to fit. In another world, they might not, so its coverage must be checked too.
Conformal prediction. Fourth and fifth, conformal prediction. It's a simple recipe that works with any model. Fit the model on part of the data. On the rest, measure how big its errors are. Then make every range wide enough to cover ninety percent of those errors. That's all. No assumptions about the shape of the errors. The only assumption is that the held-out data look like the new data, and that assumption is exactly where it can go wrong. The crucial choice is what you hold out. Hold out random rows, and the errors come from countries the model already knows. Those ranges contained the truth eighty-two percent of the time on new countries. Too narrow. Hold out whole countries instead, and the recipe measures the errors that matter for new countries. Those ranges covered ninety percent, as promised. They're wide, about twenty-four points. That's honest. With thirty countries, that's how much we really know about a new one. So an honest range has to be calibrated on the same kind of question you'll ask it. Here, that means whole countries. When you report a range, report three things: its width, how often it covered the truth on a held-out check, and what was held out. A range without its check is just a decoration.
Every model side by side. Let's put everything side by side. For each model: its error on new countries, whether it gives an honest range, how readable it is, and how much data it needs. The linear model with a link: the best point estimate here, about four points, and fully readable. Add a conformal range calibrated on countries. The Gaussian process: about four and a half points, with its own honest range in this world. Less readable, and slow on very large data. Boosting: about six points here, but strong when data are many and effects are tangled. Readable through partial dependence. Needs a calibrated range. The tree and the neighbours: easy to explain, weaker here. The neural network: needs far more data than we have. And for policy, remember Module 2. A good estimate of the size is not a model of what would change it. Predictive accuracy is one goal among five. No model wins everywhere. What holds up is a process: look at the data, design the check to match the use, compare honestly, and report ranges you've tested. And if two models are close, prefer the one you can explain, check and maintain. In this field, someone will ask why the estimate moved, and you'll need an answer.
A checklist. Here's that process as a checklist you can use on real data. First, explore the data and its origin. Where did each variable and each benchmark come from, and which ones are themselves estimates? Second, design the estimation. Which units, which target, which split matches the use, and which baseline must every model beat? Third, compare a small set of models on that split, with the same inputs and the same budget for tuning. Fourth, interpret. Read coefficients and partial dependence, check whether the shapes make economic sense, and report the range with its tested coverage. And remember the label. If your benchmark is a model, everything you build inherits its assumptions. Write all of this down before you look at the results on the held-out countries. Choosing the check after seeing the scores is one of the easiest ways to fool yourself.
Recap. Let's recap. Neural networks need many more units than thirty countries. With little data, they're unstable. Ranges matter as much as point estimates. An ensemble's spread and quantile models were overconfident here. A Gaussian process, and conformal prediction calibrated on whole countries, were honest. The best point estimate came from the simplest model with the right shape. The best practice came from a process, not a model. In the lab, you'll ask each model for a ninety percent range, and watch how often the truth lands inside. Next module: predicting the size and its trend over time. Forecasting something you can't see.
8:19Video 7 · 4.1The estimation task and linear modelsA logistic link removed the negative estimates and cut the error on new countries from 4.9 to 4.2 points. Tax alone goes with almost 15 fewer points per 5 points of tax; with controls the sign flips to about +2, near the true +1.
8:08Video 8 · 4.2Trees, margins, neighbours and boostingTrees, neighbours, support vectors and boosting look best on random rows. On the twenty new countries the linear model with a link won (4.2 points), ahead of support vectors (5.5) and boosting (6.0).
8:07Video 9 · 4.3Deep and probabilistic estimators, and an honest comparisonA small neural network was unstable with thirty countries. Ranges from an ensemble's spread covered 37% and quantile boosting 52%; a Gaussian process and conformal prediction calibrated on whole countries covered 90%.
Interactive lab
Estimate the Archipelago
Fit a linear model with and without a logistic link, grow a decision tree question by question, choose the number of neighbours, and ask for 90% ranges. Every estimate is scored on countries the models never saw, against the truth.
The Archipelago is simulated in your browser (thirty countries with a careful benchmark, twenty to estimate). Four challenges are checked as you go.
The Archipelago: thirty countries teach, twenty to estimate
Fifty invented countries × 12 years. The hidden share jumps where enforcement is below 0.35, cash matters more where banks are scarce, and every country has quirks. A careful benchmark exists for thirty countries; the models estimate the other twenty, and we score them against the truth.
Each question splits on the input and cut point that reduce the error most.
Conformal prediction: what you hold out decides whether the range is honest for new countries.
Running…
Estimates for the twenty new countries
Challenges
Each one is checked on your current settings.
- See the straight line predict a negative hidden share, then switch on the logistic link and make every estimate positive.
- Grow a tree whose first question is about enforcement, near the threshold of 0.35 we built in. (Hint: which inputs does it see?)
- Grow a tree with a training error below 1.5 points and an error on new countries above 6 points.
- Get 90% ranges that cover at least 85% of the new countries. What did you hold out?
