Preventing Overfitting in Regression With 10+ Variables
Forty adjustment variables can be fine or badly overfit, depending on your rows, your outcome's rarest class, and whether you penalise the coefficients.

A biostatistics student asked a question that comes up in most applied work: an intro class taught that you should never adjust for more than 10 variables in a regression model because it will overfit. Their dataset has 50 variables, and about 40 of them are things they would normally adjust for. Does the rule forbid that model, and if so, what do you do instead? The question and its answers are on Cross Validated.
The short answer is that the rule is a compressed version of a sample-size ratio, and the ratio is the part that matters. Forty adjustment variables can be fine in one dataset and badly overfit in another. What decides it is how many observations you have, what kind of outcome you are modelling, and whether you constrain the coefficients.
This article walks through what the answers on that thread support: the observations-per-regressor rule, how it changes for categorical outcomes, penalised regression as a way out, and the costs of a large multiple-regression model that have nothing to do with overfitting.
The ten-variable rule is really a ratio
The top-voted answer calls the fixed cap 'much too simple a rule.' Its proposed replacement is one regressor for every ten observations. The limit scales with your data, so a large dataset can support more variables without overfitting.
Apply that to the 40-variable case. By this rule of thumb you would want roughly 400 observations to adjust for 40 regressors. The classroom cap of 10 variables corresponds to about 100 observations. If your dataset has 150 rows, 40 adjustment variables is well past what the ratio supports. If it has 50,000 rows, the same model is nowhere near the limit.
This is a rule of thumb, not a guarantee. It tells you when to be worried, not when a model is safe. Note also that it counts regressors, not original variables. How a categorical predictor with several levels counts toward that total is something the thread does not spell out, so check it for your own design matrix rather than assuming one column per variable.
Categorical outcomes make the count stricter
The asker said the outcome is either categorical or continuous and suggested it would not matter. The answer says it does. For a categorical outcome, the common rule of thumb is 10 observations in the least common category for each regressor.
The restriction depends on the outcome's balance rather than the total row count. A dataset of 10,000 rows sounds generous, but if only 80 of them fall in the rare category, the effective sample size for this rule is 80. Under it, that supports about 8 regressors, not 40.
- Continuous outcome: count all observations, then divide by ten.
- Categorical outcome: count the observations in the rarest category, then divide by ten.
This is the most common way a 'big' dataset turns out to be small. Before deciding how many variables to adjust for, tabulate the outcome and look at the smallest cell.
Regularization turns the question into model selection
If the ratio says you have too many candidates, the second answer suggests penalised regression: ridge (an L2 penalty on the coefficients), lasso (an L1 penalty), or a mix of both. Rather than choosing a subset of variables by hand, you fit with a penalty and let it shrink the coefficients.
As that answer puts it, playing with the penalties 'essentially converts your question to a model selection problem.' Fit as many candidate variables as you like, and the lasso will zero out the coefficients of the less relevant ones. Ridge shrinks coefficients but does not zero them, so it will not reduce the variable count on its own.
The answer also ties penalty strength to sample size. The more data you have, the more coefficients it makes sense to keep, or the smaller the penalties you can use and still get meaningful results. This is the same ratio logic as the first section, expressed through a tuning parameter rather than a hard cap.
A stability check on the penalty
The answer gives one concrete heuristic for judging the penalty: if reducing it a little changes your coefficients a lot, you should go the other way. In practice, that means unstable coefficients under a light penalty are a sign you are asking too much of the data, and a stronger penalty is the direction to move.
The thread does not say how to choose the penalty formally, so this is the only guidance it supports. Treat it as a sanity check rather than a tuning procedure.
Overfitting is not the only cost
The top answer adds two problems that persist even if you solve the sample-size question. The first is interpretation. Mathematically, a multiple-regression coefficient is straightforward: it is the association with the outcome while controlling for all the other variables. But what that means substantively, with 40 variables held fixed, can be tricky to state in words.
The second is collinearity, which the answer says is often a problem with many regressors if you want to interpret the model. It does not affect prediction. That distinction should shape your goal. If you only need predictions from a high-dimensional set of inputs, collinearity is largely a non-issue. If you are reporting an adjusted coefficient for a particular exposure, correlated adjustment variables can make that single number hard to trust.
Where this does not fit
None of these rules replaces thinking about why each variable is in the model. The ratio and the penalties address overfitting only. They say nothing about whether a variable should be adjusted for, and the thread does not address that question.
Watch for the following:
- Treating one regressor per ten observations as a safe threshold. It is a rule of thumb, and the answers present it as such.
- Counting total rows when the outcome is categorical and one class is rare.
- Expecting the lasso to give you an interpretable, causal adjustment set. It selects for the fit, which is a different goal from the one your research question may have.
- Ignoring collinearity because the penalised model predicts well. Prediction is unaffected, but the coefficients you report may not be.
The thread's closing pointer is honest: choosing a good model is a huge subject. The model-selection tag on Cross Validated is the place to continue.
This article draws on How do you prevent overfitting regression models when you adjust for more than 10 variables? and answers to it (1, 2), on the Stack Exchange network, licensed under CC BY-SA 4.0.
- #high-dimensional
- #lasso
- #multiple-regression
- #overfitting
- #regression
- #ridge regression



Comments