Tutorials › Exam PA - Predictive Analytics › Comparing Outcomes Across Predictor Groups

Exam PA · Data Structures and Exploratory Summaries · Tutorial 121 of 966

Comparing Outcomes Across Predictor Groups

Learn to build and interpret grouped outcome summaries, compare the relevant statistics across predictor categories, and state what the data do—and do not—show.

Beginner 10 min read

What You'll Learn

  • Distinguish a grouped descriptive comparison from a causal conclusion.
  • Select group summaries that match a numeric or categorical outcome.
  • Calculate and interpret differences in group means, medians, and proportions.
  • Use dplyr to produce a compact outcome summary by predictor category.
  • Recognize how an extreme value can make mean and median comparisons tell different stories.
  • Report a group difference with its direction, scale, and context.

Why Compare Outcomes Across Predictor Groups?

A predictive analytics data set often contains an outcome of interest and a categorical predictor that divides observations into groups. For example, an insurer might want to describe claim amounts by payment channel, or a service team might compare resolution times across contact methods. A grouped summary makes the observed differences visible in a compact, interpretable form.

The purpose here is descriptive: summarize the observed outcome within each category, then state how the summaries differ. A difference between groups does not, by itself, show that the predictor caused the outcome to change. People or records in different categories may also differ in other ways, and the groups may not have been formed by random assignment.

Definition: A grouped outcome summary reports one or more descriptive statistics of an outcome separately for each observed category of a categorical predictor. For a numeric outcome, common summaries include the count, mean, median, minimum, and maximum. For a categorical outcome, common summaries include category counts and within-group proportions.

The predictor defines the groups; the outcome is what is summarized within each group. State both explicitly before interpreting a result. If the predictor is “payment channel” and the outcome is “days to resolve,” a mean resolution time by channel answers a different descriptive question from the proportion of records marked “resolved” by channel.

Choose a Summary That Matches the Outcome

For a numeric outcome \(Y\), let \(G\) denote a categorical predictor. Within category \(g\), the group mean is the sum of the observed outcome values in that category divided by the number of observations in that category. The group median is the middle observed value after the category’s values have been ordered, or the average of the two middle values when there is an even number of observations.

$$ \bar{y}_g = \frac{\sum_{i:G_i=g} y_i}{n_g} $$

Here, \(n_g\) is the number of observed records in category \(g\). The mean is sensitive to extreme values; the median is less sensitive to them. Reporting both can be useful when an unusual value makes the mean alone an incomplete description. The choice should serve the question and the shape of the observed data, rather than simply defaulting to one statistic.

If the outcome is categorical, summarize its distribution separately within each predictor group. For a binary outcome, such as “complete” versus “incomplete,” the within-group proportion marked “complete” is the number marked complete divided by the total number in that predictor category. The denominator is the group total, not the overall total.

$$ \hat{p}_g = \frac{\text{number of observations in group } g \text{ with the outcome}}{n_g} $$

A difference in group means or proportions is a descriptive contrast. For numeric outcomes, one useful convention is to define the contrast as the second named group’s summary minus the first named group’s summary. The direction then has a clear meaning: a positive value means the second group has the larger summary. For proportions, report the difference in percentage points when expressing the difference on a percentage scale.

Build and Read a Grouped Summary in R

With a data frame named records, a categorical predictor named channel, and a numeric outcome named days, dplyr can produce a summary for each channel. The command groups by the predictor, calculates statistics within each group, and then removes the grouping from the output.

R: records |> dplyr::group_by(channel) |> dplyr::summarise(n = dplyr::n(), mean_days = mean(days), median_days = median(days), .groups = "drop")

For a binary outcome stored as values such as “Complete” and “Incomplete,” first define exactly which outcome category is being counted. One direct approach is to summarize the number of records in each predictor-outcome combination and calculate the within-predictor proportion. The denominator for each proportion must be the total count across outcome categories for that predictor group. A percentage of all records in the data set answers a different question.

A grouped summary is only as meaningful as its inputs. The predictor categories should represent the intended groups, and the outcome should be recorded in a consistent unit and definition across categories. For example, comparing resolution times recorded in hours in one group with times recorded in days in another would not be a fair numerical comparison without first resolving the unit inconsistency.

Worked Example: Comparing Mean and Median Resolution Time

In a hypothetical service operation, four records are observed for each of two payment channels. The outcome is resolution time in days. The times for the self-service channel are 8, 10, 12, and 14 days; the times for the assisted channel are 11, 13, 15, and 21 days. Calculate each group’s mean and median, then compare assisted minus self-service.

Method. Summarize the numeric outcome separately within each channel, then subtract the self-service statistic from the assisted statistic. The mistake this avoids is comparing totals when the question concerns typical time per record.

For self-service, the total is \(8+10+12+14=44\) days and the count is 4. Thus the mean is \(44/4=11\) days. The ordered middle values are 10 and 12, so the median is \((10+12)/2=11\) days.

For assisted service, the total is \(11+13+15+21=60\) days and the count is 4. Thus the mean is \(60/4=15\) days. The ordered middle values are 13 and 15, so the median is \((13+15)/2=14\) days.

The mean difference, assisted minus self-service, is \(15-11=4\) days. The median difference in the same order is \(14-11=3\) days. Both observed group summaries are higher for assisted service in these data, but the values alone do not show that assisted service caused longer resolution times. The checked totals, 44 and 60, reproduce the reported means when divided by four.

Worked Comparisons for Different Outcomes

Worked Example: Comparing a Completion Proportion

A hypothetical intake team records whether each application is complete at first review. Among 30 applications submitted through a web form, 18 are complete. Among 20 applications submitted by telephone, 12 are complete. Calculate each within-channel completion proportion and the difference, web form minus telephone.

Method. Divide the number complete by the total number in each channel, then subtract proportions using the stated order. The common mistake is to divide each count by the overall total of 50, which would not give a within-channel completion rate.

For the web form, the completion proportion is \(18/30=0.60\), or 60%. The incomplete count is \(30-18=12\), which checks that the two outcome counts sum to the group total.

For telephone, the completion proportion is \(12/20=0.60\), or 60%. The incomplete count is \(20-12=8\), again giving the stated group total.

The difference is \(0.60-0.60=0.00\), or 0 percentage points. These observed records have equal completion proportions by channel. This does not establish that the channels would have equal outcomes in a different set of records, nor that channel has no effect; it reports only the comparison calculated from the supplied data.

Worked Example: An Extreme Value Changes the Mean Comparison

A hypothetical analyst compares claim amounts, in hundreds of dollars, for two categories of submitted documents. The observed amounts for Category A are 100, 110, 120, 130, and 600. For Category B they are 140, 150, 160, 170, and 180. Calculate each mean and median, then compare Category A minus Category B.

Method. Calculate both mean and median within each category, because a large value may influence the mean much more than the median. The mistake this avoids is treating a larger mean as a complete description of every typical outcome in the group.

For Category A, the sum is \(100+110+120+130+600=1060\) hundreds of dollars. With five observations, its mean is \(1060/5=212\) hundreds of dollars, or $21,200. The ordered middle value is 120, so the median is 120 hundreds of dollars, or $12,000.

For Category B, the sum is \(140+150+160+170+180=800\) hundreds of dollars. Its mean is \(800/5=160\) hundreds of dollars, or $16,000. The middle value is 160, so its median is 160 hundreds of dollars, or $16,000.

The mean difference, Category A minus Category B, is \(212-160=52\) hundreds of dollars, or $5,200. The median difference in the same order is \(120-160=-40\) hundreds of dollars, or −$4,000. The mean is higher for A, while the median is lower for A. The 600-hundred-dollar observation contributes to the difference in means; it does not change Category A’s middle value. The figures check against the totals: \(1060/5=212\) and \(800/5=160\).

Why the Overall Mean Is a Weighted Average

A useful check on grouped means is that the overall mean can be recovered by weighting each group mean by that group’s share of the observations. This identity follows directly from how the means are calculated; it does not require a probability model.

$$ \bar{y} = \frac{\sum_g n_g \bar{y}_g}{\sum_g n_g} $$

To justify the identity, within group \(g\), the sum of the observed outcomes equals \(n_g\bar{y}_g\), by the definition of the group mean. Adding those sums across all groups gives the total of all observed outcomes. Dividing by the total number of observations, \(\sum_g n_g\), gives the overall mean:

$$ \bar{y} = \frac{\sum_g \sum_{i:G_i=g} y_i}{\sum_g n_g} = \frac{\sum_g n_g\bar{y}_g}{\sum_g n_g} $$

For the first worked example, each group has four observations, so the overall mean is \((4\times11+4\times15)/(4+4)=104/8=13\) days. Simply averaging the two group means also gives 13 here because the group sizes are equal. If group sizes differ, an unweighted average of group means generally will not equal the overall mean.

Describe Differences Without Overstating Them

A careful comparison names the groups, the outcome, the statistic, the direction, and the units. For example: “In these records, the mean resolution time was 15 days for assisted service and 11 days for self-service, a difference of 4 days.” This is more informative than “assisted is worse,” which introduces a value judgment and can imply a causal conclusion not supported by a descriptive summary.

The predictor category may be associated with other characteristics of the records or people being compared. The observed group summaries alone do not separate those characteristics from the predictor. Therefore, describe what was observed and avoid language such as “caused,” “led to,” or “reduced” unless the study design and analysis justify a causal interpretation. A grouped summary is an exploratory description, not a substitute for an appropriate causal analysis.

When you report a proportion, make the denominator and outcome category clear. “60% were complete within the web-form group” identifies the group-specific percentage; “18 were complete” gives a count; “18 out of 50 were complete” uses the overall denominator. Those statements are not interchangeable.

Key takeaway: Define the predictor groups and outcome, calculate a suitable summary within each group, and state the contrast in a fixed order and meaningful units. The resulting difference describes the observed data; it does not, on its own, establish why the groups differ.

Check Your Understanding

For each problem, calculate the requested grouped comparison and describe it as an observed difference, not a causal effect.

  1. A hypothetical office records completion times in minutes. North has values 6, 8, and 10; South has values 9, 12, and 15. Find each mean and the mean difference South minus North. (Answer: North mean 8 minutes; South mean 12 minutes; difference 4 minutes.)
  2. A fictional review team marks 16 of 25 email submissions complete and 21 of 30 portal submissions complete. Find both completion proportions and the difference, portal minus email, in percentage points. (Answer: Email 64%; portal 70%; difference 6 percentage points.)
  3. For a hypothetical numeric outcome, Group A has 4, 6, 8, and 10; Group B has 5, 7, 9, and 11. Find each group’s mean and median. (Answer: A mean 7 and median 7; B mean 8 and median 8.)
  4. A fictional analyst observes values 20, 22, 24, and 54 in Group X, and 25, 27, 29, and 31 in Group Y. Find the mean and median in each group, then give the mean difference X minus Y. (Answer: X mean 30 and median 23; Y mean 28 and median 28; mean difference 2.)
  5. Two groups have means 10 and 16. Group 1 has 3 records and Group 2 has 5 records. Calculate the overall mean using the group sizes, and explain why the simple average of the two group means is not the correct overall mean. (Answer: Overall mean \((3\times10+5\times16)/8=13.75\); the simple average is 13 and ignores the unequal group sizes.)
Clinical Biostats