Saltar al contenido

Lección 18 · Time and Groups

Group Comparisons and Cohorts

Compare groups over time with cohort tables and retention rates, separate mix changes from rate changes, and avoid unfair comparisons of young cohorts.

An overall number can stay flat while the groups inside it change a lot. New customers may behave worse while loyal ones hide the decline. To see this, you compare groups over time. A very useful kind of group is the cohort.

What is a cohort?

A cohort is a group that shares a starting event in the same period, such as everyone who signed up in January. You then follow each cohort by its age: month 0, month 1, month 2 and so on.

Cohorts involve three kinds of time:

Three clocks

Cohort When did they start?
Age How long since the start?
Calendar When did it happen?

A pattern can follow any of the three

1 / 2

If every cohort drops at age 1, look at the customer journey, such as the end of a free month. If every cohort drops in the same calendar month, look for an outside event.

Build a retention table

Retention is the share of a cohort that is active at a given age. Decide what "active" means (logged in? bought something?) before you compute anything.

Python A retention table from activity rows

Press Run (or Ctrl + Enter) to see the result here.

Program input · what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The dashes are important. The March cohort has no month-2 value yet, because that month has not happened. A dash means unknown, not 0%. Filling it with zero would make new cohorts look terrible.

Month 0 is 100% here by construction, since a user's first activity defines the cohort. If you define cohorts by signup instead, month 0 activity can be below 100%.

The same idea in pandas

The usual steps are: find each user's first month with groupby(...).transform("min"), compute the age, count unique users by cohort and age, and pivot.

Python Cohort counts with pandas

Press Run (or Ctrl + Enter) to see the result here.

Program input · what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

A missing cell in this output (NaN) can mean "not yet observable" or "nobody active". Use the last observed month to tell the two apart, and replace only the observable gaps with zero.

Cohorts in SQL

SQL First month and age with a CTE

Press Run (or Ctrl + Enter) to see the result here.

Be sure that your data reaches back far enough. If the export starts in January, long-time customers will appear in a "January cohort" even though they joined years ago.

Mix change or rate change?

An overall rate is a weighted average of group rates. It can change because the rates changed or because the mix of groups changed.

Python Overall rate falls, every group improves

Press Run (or Ctrl + Enter) to see the result here.

Program input · what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Both groups improved, but the share of new users grew, and new users convert less. Reporting only the overall drop could send the team looking for the wrong problem. This is the same effect as in Simpson's paradox.

Funnels

A funnel tracks how many users pass through ordered steps, such as view, add to cart and pay. Compare each step with the one before it and with the start. Define the time limit between steps, count users rather than events, and check funnels by device or source. A step that records more users than the step before can signal a tracking problem or a different path into the funnel.

Fair comparisons between groups

  • Compare cohorts at the same age.
  • Show cohort sizes; small cohorts swing widely.
  • Keep definitions fixed across periods, and note any change.
  • Averages for later months that include only users who stayed do not describe the original group. Say which base you use.

Do not compare the total revenue of a two-year-old cohort with that of a two-month-old one. The older group has had far more time. Compare revenue within the first two months for both.

Size matters in cohort tables

A retention table looks authoritative even when its rows are tiny. In the example above, the April cohort has a single user, and the March cohort has two. A change of one person moves a percentage by 50 or 100 points. Show the size column, consider graying out very small cohorts and avoid reading trends into them.

When you present the table, point out the direction of reading. Reading across a row follows one cohort as it ages. Reading down a column compares different cohorts at the same age. Reading along a diagonal compares what happened in the same calendar month.

Try it yourself

Add three users to the March cohort who are active in months 3 and 4. See how the percentages change. Then change last_month to 3 and confirm that the table hides the cells that can no longer be observed.

Define the start carefully

The starting event shapes everything that follows. A cohort based on signup includes people who never bought anything. A cohort based on first purchase includes only buyers, so its later purchase rates will naturally look different. Neither is better in every case. Choose the one that matches the decision, name it in the table title and do not switch between them within one comparison. Also decide how to treat a person who has two accounts, since it can create a false "new" user.

State what the table cannot show

A retention table shows how many people remained active at each age. It does not show why they stopped. To learn that, combine it with other sources, such as support records or interviews, and treat their answers with the same care about who responded.

A common mistake

Do not average retention percentages across cohorts without thinking about their sizes. A cohort of one user would count as much as a cohort of thousands. Pool the active users and the cohort sizes for the same age, using only cohorts that have reached that age.

Check your understanding

Quick check · 4 questions

of 4 answered You scored / 4 · perfect!

  1. 1. What defines a cohort?

    Cohorts group people by a common start so you can follow them over time.
  2. 2. A new cohort has no month-3 value because month 3 has not happened. How should you show it?

    Zero would claim that nobody was active, which you cannot know yet.
  3. 3. Every group's rate rises, but the overall rate falls. What is a likely cause?

    An overall rate depends on both group rates and group shares.
  4. 4. Which comparison of two cohorts is fair?

    Both groups get the same amount of observed time.

Summary

  • Cohorts group by start period and follow members by age.
  • Define activity clearly and keep unobserved cells separate from zeros.
  • Check whether data goes back far enough to identify true first events.
  • Split overall changes into rate effects and mix effects.
  • Compare groups at equal ages and show their sizes.

Next: Outliers and Anomalies

Tu progreso se guarda en este navegador. No necesitas una cuenta.