Comparing groups of rows
Put two sets of rows side by side, column by column. Compare a group with the rest, two versions or missing with present, read effect sizes rather than p-values, and match rows by a key.
What runs in CodeSplash
- Table 1 (characteristics by group) Verified in Python and R
You will be able to
- Compare a group with the rest, two groups, two versions or missing with present
- Read standardized differences, PSI and total variation without p-values
- Match the rows of two versions by a key to see what changed
- Hand a comparison to Table 1 when you need tests
Read first
Two sets of rows
ReadMany questions compare rows of one table: customers who left against those who stayed, this month's rows against last month's, rows where income is missing against rows where it isn't.
Compare in Insights puts two sets of rows side by side, column by column. What to compare offers A group and the rest, Two groups, Two versions, Two datasets and Missing vs present.
You can also start from where you are. Breakdown's level menu has Compare with the rest. A row of the Column summary has Compare missing vs present. The Versions panel has Columns beside each version.
Missing, or different?
PredictPredict first
In a customer table, income is blank for some rows. You compare Missing vs present on income. If the blanks happened at random, what should the other columns show?
Reveal
They should look alike, apart from noise. When the missing side is younger, newer or on another plan, the blanks aren't random. Dropping those rows then changes who your analysis is about, and filling them with the average hides the difference.
Read the Columns tab
In the appThe Columns tab lists every column, largest difference first, with a verdict: Large, Moderate, Small or None. The number beside it is an effect size:
- SMD, the standardized mean differenceStandardized mean differenceA covariate's group difference in standard deviation units; below about 0.1 usually counts as balanced. as Table 1 computes it, for numbers and for categories. Compare calls 0.1 small, 0.2 moderate and 0.5 large.
- TV for categories, the total variation distanceTotal variation distanceHow different two category mixes are: the share of rows you would have to move to make them equal. 0 = the same, 1 = no overlap.: the share of rows you'd have to move to make the two mixes equal.
- PSIPopulation stability indexA summary of how much a variable's distribution has shifted between two periods. and KS D for the whole shape, and Δ missing in percentage points.
New and lost levels are listed too.
No p-values here
ReflectThe page ends with a note: "No p-values here; test in Analyze to report a difference." Comparing every column is a screen, and with many rows even a trivial gap gets a tiny p-value. Effect sizes tell you which gaps are big enough to matter.
When you need a citable comparison, press Test these differences in Analyze. It opens Table 1 on a working copy with a column for each side, and Table 1 adds the tests.
Which gap on your last comparison would you have reported? Was it the largest effect, or the smallest p-value?
Can anything tell them apart?
ExploreColumn by column, every gap can look small while the rows still differ in how columns combine. Check with a classifier trains a nearest-neighbor model on a sample of rows from each side and reports its AUC.
An AUC of 0.5 means it can't tell the sides apart. Near 1, the two sets differ in some combination of columns, even if no single column stands out. Try it on two versions of a dataset before and after a recipe changed it.
Rows by key
In the appTwo versions of one table often hold the same customers. Rows by key matches them on a Key column and counts Matched, Only in A, Only in B, Changed and Unchanged rows. Each count opens its rows.
Values must match exactly unless you set a Number tolerance. A key that repeats stops the match, because rows can't be paired one to one. Add a Second key column, or press Compare the first row per key, and the result says which you chose.
Every group against the rest
In the appThe Groups tab takes a column with a few levels, such as a site, an arm or a segment. Each level is compared with the rest of the rows, and each cell holds the SMD of one column for one level, shaded by size. Press a cell to open that level against the rest on the Columns tab.
A gap is a description, not a reason.
Check your understanding
CheckpointCheck yourself
Churned customers have a mean tenure of 14 months and the rest 16 months, with a pooled SD of 8 months. What is the absolute SMD?
Show the answer
Answer: 0.25
|14 − 16| / 8 = 0.25. Compare would call that a moderate gap: above 0.2 and below 0.5.
Check yourself
Why does Compare show effect sizes and no p-values?
Show the answer
Answer: b
It's a screen. Use it to see where the sets differ, then test the gaps you care about in Table 1, where the tests are planned and counted.
Check yourself
Every column shows Small or None, but Check with a classifier reports an AUC near 0.9. What does that mean?
Show the answer
Answer: b
A classifier looks at all the columns together. Single-column effect sizes can miss a difference that only shows in combination.
Recap
Recap- Compare puts two sets of rows side by side: a group and the rest, two groups, two versions, two datasets, or missing and present.
- Read effect sizes: SMD as in Table 1, TV for category mixes, PSI and KS D for shapes.
- No p-values here. Hand the gaps you care about to Table 1.
- Match rows by a key to see exactly what changed between versions.
Concepts in this lesson