Quant500 Academy

5. Goodness of fit and the traps of R squared

Level 7: Rigorous Statistical Diagnostics

To predict Y well we want the independent variable X to explain as much of the variation in Y as possible (hence the name explanatory variable). Ideally, the variance of X helps explain the variance of Y. So we need a way to measure how good our model is, a goodness-of-fit measure that quantifies how well the estimated model fits the data.

The best known is the coefficient of determination, R squared: the ratio of explained variation to total variation; equivalently, one minus the ratio of the sum of squared residuals to total variation.

# R squared = ESS / TSS = 1 - RSS / TSS
#   TSS: total variation of Y around its mean
#   ESS: variation explained by the model
#   RSS: sum of squared residuals
model.rsquared
model.rsquared_adj

The closer it is to 1, the closer the observed values of Y are to the fitted values. If it equals exactly 1, every point lies on the estimated line and the fit is perfect. If Y and X have no linear relationship at all, in a simple regression it would be 0. Between 0 and 1 it is read as the proportion of the variation of Y around its mean explained by the model: an R squared of 0.17 means that 17% of the variation of Y is explained by X.

So far, what everyone knows. Now the warnings, which are what really matters:

The professor's conclusion is blunt: under no circumstances should a model be chosen on the basis of R squared alone.

In finance this matters a lot. A CAPM regression on an individual stock usually gives a modest R squared, of the order of 0.2, and that is perfectly normal: almost all the movement of a single stock is idiosyncratic. Conversely, an R squared of 0.99 in a regression on prices (not returns) is not good news but the usual signature of a spurious regression between trending series. Adjusted R squared penalizes the number of regressors and is preferable when comparing models with different numbers of factors, because plain R squared never falls when you add variables, useful or not.

The rest of Quant500

What you are learning, applied to the index every day:

The model portfolio, weekly in your inbox

Every Saturday, its week in one minute: how it went, the best and the worst, and which insiders bought with their own money. Plus, the day the model is rebuilt, which stocks come in and which go out. A simulation, not advice. At most one email a week, no ads, no account; one-click unsubscribe. Made by one person: Pol Gracia.

A model portfolio with simulated results, not a personalized recommendation. Your email is used for this only: privacy.

Behind the Academy and the rest of Quant500 there is one person: Pol Gracia Serrahima.