# R-squared value when using offset — how is it calculated?

I have a linear model with a test score variable as a dependent variable and a vector of covariates. I have an offset variable in the model.

So the formula is=

$$\text{score}_i = B_0 + B_xX_x + offset_i + e_i$$

or equivalently:

$$\text{score}_i - \text{offset}_i = B_0 + B_xX_x + e_i$$

I estimate this in R using

lm(score ~ covariates, offset=offset, data=data)


When running this, I get an $R^2$ of $0.55$.

Then, I create a different dependent variable, subtracting the offset manually, so the formula is:

$$\text{score-offset}_i = B_0 + B_xX_x + e_i$$

I get a different $R^2$ -- substantially less: $0.10$.

I'd like to know why these calculations are different. Obviously, this is a large difference. Prof. Ripley here http://r.789695.n4.nabble.com/Calculation-of-r-squared-for-linear-model-with-offset-td797608.html notes that $R^2$ is calculated differently in the presence of an offset, but I'm not sure how.

$R^2$ is computed in terms of the sum of squares of fitted values $\text{MSS}=\sum (\hat{y}_i - \bar y_i)^2$ (assuming an intercept term is present) and sum of squares of residuals $\text{RSS} = \sum \left(y_i - \hat{y}_i\right)^2$ as
$$R^2 = \frac{\text{MSS}}{\text{MSS} + \text{RSS}}:$$
it is the fraction of the total sum of squares "explained" by the fit. Whether you subtract an offset $z_i$ or declare it as variable in the offset parameter, the model will be equivalent--it produces the same residuals--but in the former case the values to be predicted are those of $y_i-z_i$; that is, $z_i$ has been subtracted from $\hat y_i$. The sum of squares to be "explained" is thereby changed when the offset is manually subtracted (and the software has no way of knowing that). $\text{MSS}$ could increase or decrease, resulting either in an increase or decrease in $R^2$, respectively.