# How to test whether linear models fit separately to two groups are better than a single model applied to both groups?

My question is how to tell if two regressions explain the data better than one.

Let me be more concrete with an example (which I'm making up as I go, it's not meant to be plausible). Say I'm interested in the relationship between income and happiness. Then I ask a lot of people about their income and happiness. But say some of the people I ask are men and some are women. Now, I perform a linear regression for income and happiness and see that income does predict happiness according to some coefficients, it's significant, the model explains a lot of the variance, etc.

My question is, how do I test whether there's a unique relationship between happiness and income, that applies across men and women, or the data are better explained by two models, each obtained by regressing separately on men and women?

I'm thinking of calculating residuals for the data with respect to each model, then comparing the sum of the residuals, or something along those lines. Is that a reasonable thing to do? How would I go about comparing the residuals?

So, in summary, how do I know if the better hypothesis is that of one unique linear model for all the data, or the one where each subset (subsets defined a priori) of the data has its own linear model?

$$\text{Happiness}=\beta_0 + \beta_1\text{Income} + \beta_2\text{Sex} + \beta_3\text{Income}\times\text{Sex} + \varepsilon$$ Note that sex would be represented by a dummy code, that is, a vector of $1$s and $0$s, where the $1$s indicated, e.g., that the person was a man. The reduced model would look like this:
$$\text{Happiness}=\beta_0 + \beta_1\text{Income} + \varepsilon$$ Thus, the models differ in two parameters, and the larger model 'reduces' to the smaller one if $\beta_2=\beta_3=0$. To simultaneously test whether both parameters are 0, you perform a nested model test. (I have discussed such tests here: Testing for moderation with continuous vs categorical moderators, albeit in a different context.)
$$\text{Happiness}=\beta_0 + \beta_1\text{Income} + \varepsilon$$ And the relationship for men is:
$$\text{Happiness}=\underbrace{(\beta_0 + \beta_2)}_{\text{intercept}} + \underbrace{(\beta_1+\beta_3)}_{\text{slope}}\text{Income} + \varepsilon$$ (Again, this assumes that men are $1$, and women are $0$.)