Why Compare Associations Within Groups?
A data set may contain distinct groups, such as clinics, schools, or age categories. A single regression line through all observations summarizes the pooled association between a predictor and an outcome. Separate lines, one for each group, summarize the group-specific associations. Those summaries need not agree. An overall trend can be weaker than each within-group trend, stronger than either one, or even point in the opposite direction.
The point of comparing them is not to decide that one summary is always right. Each answers a different descriptive question. The pooled slope describes the linear pattern among all observations considered together. A group-specific slope describes the linear pattern among observations in that group. If group membership matters to the question, reporting only the pooled slope can hide important differences.
These are descriptive summaries of linear association. A positive slope means that larger predictor values tend to occur with larger outcome values in the data summarized; a negative slope indicates a downward linear pattern. The slope is measured in outcome units per predictor unit. It does not, by itself, establish that changing the predictor causes a change in the outcome.
Before comparing slopes, identify what is being pooled and what defines each group. Also check that the predictor varies within each group: if every observation in a group has exactly the same predictor value, that group’s least-squares slope cannot be calculated. The calculations below describe hypothetical data and make no claims about real patients or institutions.
A Worked Comparison
The following hypothetical example uses six observations split between two groups. The outcome might represent a score and the predictor might represent hours of practice, but the numbers are illustrative only.
Worked Example: Positive Trends Within Groups, a Negative Pooled Trend
Group A has \((x,y)\) values \((1,3),(2,4),(3,5)\). Group B has values \((7,1),(8,2),(9,3)\). Calculate the slope in each group and the slope using all six observations.
Group A. Its means are \(\bar{x}_A=2\) and \(\bar{y}_A=4\). Thus $$ S_{xx,A}=(-1)^2+0^2+1^2=2,\qquad S_{xy,A}=(-1)(-1)+0(0)+1(1)=2, $$ so \(b_{1,A}=2/2=1\) outcome unit per predictor unit.
Group B. Its means are \(\bar{x}_B=8\) and \(\bar{y}_B=2\). The centered values follow the same increasing pattern: $$ S_{xx,B}=(-1)^2+0^2+1^2=2,\qquad S_{xy,B}=(-1)(-1)+0(0)+1(1)=2. $$ Therefore \(b_{1,B}=2/2=1\), also positive.
All observations together. The pooled means are \(\bar{x}=5\) and \(\bar{y}=3\). The predictor deviations are \(-4,-3,-2,2,3,4\); the outcome deviations are \(0,1,2,-2,-1,0\). Therefore $$ S_{xx}=16+9+4+4+9+16=58, $$ $$ S_{xy}=(-4)(0)+(-3)(1)+(-2)(2)+(2)(-2)+(3)(-1)+(4)(0)=-14, $$ and $$ b_1=\frac{-14}{58}\approx -0.2414. $$ The pooled slope is negative, even though the slope is positive in each group. In this data set, the observations in Group A have relatively smaller \(x\) values and larger \(y\) values than those in Group B. That separation between groups contributes a negative overall pattern that outweighs the positive patterns within them.
This example shows why the pooled slope cannot be treated as a substitute for every group-specific slope. It is not an average of the two group slopes in this example: both group slopes equal \(1\), whereas the pooled slope is approximately \(-0.2414\). The pooled calculation uses the positions of all observations relative to the overall means, including how the group means differ.
Why Pooled and Group Slopes Differ
The relationship can be made precise using centered sums. Let \(g\) index groups, let \(i\) index observations within group \(g\), and let \(n_g\) be the number of observations in that group. Write \(\bar{x}_g\) and \(\bar{y}_g\) for group means, and \(\bar{x}\) and \(\bar{y}\) for pooled means. The pooled cross-product sum decomposes as
The first term adds the within-group cross-product sums. The second term describes how group means vary together: groups with above-average predictor means and above-average outcome means contribute positively, while groups whose predictor and outcome means are on opposite sides of their pooled means contribute negatively.
To see why the decomposition holds, write each deviation as the sum of a within-group deviation and a group-mean deviation:
Multiply these expressions and sum over observations. The product of the two within-group deviations gives the first term in the decomposition. The product of the two group-mean deviations is repeated \(n_g\) times in group \(g\), giving the second term. Each cross-product term is zero: for example, within any group, \(\sum_i(x_{ig}-\bar{x}_g)=0\), so multiplying that sum by the fixed group-mean deviation \((\bar{y}_g-\bar{y})\) still gives zero. This proves the decomposition. A parallel expansion gives
Since the pooled slope is \(S_{xy}/S_{xx}\), both within-group patterns and differences between group means enter the pooled result. The group-specific slopes, by contrast, use only variation around their own group’s means. This is the arithmetic reason the summaries can differ.
When Group Slopes Differ From One Another
Groups can also have genuinely different descriptive slopes. The pooled slope then summarizes a combined pattern, but it need not match any group’s slope. A pooled result by itself does not tell us whether within-group associations are alike.
Worked Example: A Pooled Slope Between Two Group Slopes
Consider hypothetical observations with the same predictor values in two groups. Group A has \((1,2),(2,4),(3,6)\), and Group B has \((1,10),(2,10),(3,10)\). Find the group-specific slopes and the pooled slope.
In Group A, \(\bar{x}_A=2\) and \(\bar{y}_A=4\). Hence \(S_{xx,A}=2\), while $$ S_{xy,A}=(-1)(-2)+0(0)+1(2)=4. $$ Its slope is \(4/2=2\). In Group B, \(\bar{x}_B=2\) and \(\bar{y}_B=10\). Here \(S_{xx,B}=2\), but all outcome deviations are zero, so \(S_{xy,B}=0\). Its slope is \(0/2=0\).
For all six observations, \(\bar{x}=2\) and \(\bar{y}=7\). The pooled \(S_{xx}\) is \(2+2=4\), since both groups have the same predictor mean. In Group A, the pooled outcome deviations are \(-5,-3,-1\), giving a pooled cross-product contribution of $$ (-1)(-5)+0(-3)+1(-1)=4. $$ In Group B, the outcome deviations are \(3,3,3\), giving $$ (-1)(3)+0(3)+1(3)=0. $$ Thus \(S_{xy}=4\) and \(b_1=4/4=1\). The pooled slope of \(1\) lies between the group-specific slopes of \(2\) and \(0\); it does not describe either group’s slope exactly.
Here the groups have the same predictor values, so the difference in their mean outcomes does not add a between-group contribution to \(S_{xy}\). The pooled slope combines the within-group cross-products and predictor variation. The result is a useful overall summary if the question concerns the combined data, but it conceals the different patterns in the two groups.
When Group Trends Cancel
A pooled slope can also be near zero even when there are clear linear patterns within groups. That does not mean there is no association in every subgroup. It may mean that opposing group-specific patterns cancel in the combined calculation.
Worked Example: Opposing Group Trends Produce a Zero Pooled Slope
Group A has \((1,3),(2,2),(3,1)\), while Group B has \((1,1),(2,2),(3,3)\). Calculate the three slopes.
Both groups have \(\bar{x}_g=2\). Group A has \(\bar{y}_A=2\), so \(S_{xx,A}=2\) and $$ S_{xy,A}=(-1)(1)+0(0)+1(-1)=-2. $$ Its slope is \(-2/2=-1\). Group B also has \(S_{xx,B}=2\), and $$ S_{xy,B}=(-1)(-1)+0(0)+1(1)=2, $$ so its slope is \(2/2=1\).
For all six observations, \(\bar{x}=2\) and \(\bar{y}=2\). The pooled \(S_{xx}\) is \(2+2=4\), and the pooled \(S_{xy}\) is \(-2+2=0\). Therefore the pooled slope is \(0/4=0\). The pooled data have no linear slope, although each group has a nonzero slope and the two group-specific slopes point in opposite directions.
How to Report the Comparison
A clear comparison names the pooled association and the group-specific associations separately, includes units, and states what the calculations do and do not establish. For example: “In these hypothetical data, the pooled least-squares slope is \(-0.2414\) outcome units per predictor unit; the slopes are \(1\) outcome unit per predictor unit in both groups. Thus the overall linear pattern is downward, while each within-group pattern is upward.” This sentence reports the numerical contrast without suggesting that the predictor causes the outcome.
When describing a comparison, also keep in mind that least-squares slopes summarize linear patterns. If a group’s scatterplot is strongly curved or dominated by an unusual observation, a single slope may give an incomplete description. Calculations are easiest to interpret alongside the plotted data and a clear description of which observations belong to each group.
Common Mistake
- Wrong reasoning: “The pooled slope is negative, so the predictor and outcome must be negatively associated within every group.”
- Correction: The pooled slope summarizes all observations together. As the first example shows, its sign can differ from the signs of all the group-specific slopes because group means also contribute to the pooled calculation. Calculate or examine the within-group patterns before making claims about them.
Check Your Understanding
Use the definitions and examples above to answer these questions.
- What observations are used to calculate a pooled slope, and what observations are used to calculate a group-specific slope?
- In the first worked example, why is the pooled slope negative even though both group-specific slopes are positive?
- If two groups have identical predictor means, what happens to the between-group contribution to pooled \(S_{xy}\)?
- Can a pooled slope of zero occur when both groups have nonzero slopes? Explain using the third worked example.
- Write one sentence that reports a slope comparison with units while avoiding a causal claim.