# Forecasting active users in shared groups (declared before any run)

The shared-groups part asks how to test a change when one member's treatment reaches the rest of their group. This
part asks a planning question on the same simulated groups: when a user's chance of staying active depends on how
much of their group was active, how well do monthly active-user forecasts hold up, and does a plan built on groups do
better than one built on users? Every choice below is fixed before any run of the forecasting code on the declared
seed, and the machine-readable copy is [data/group-forecast-protocol.json](data/group-forecast-protocol.json). Every
earlier run and its files are unchanged; their hashes are listed in the protocol and checked before and after the run.

## Why this home

The question sits between two published parts of the portfolio: a lifecycle account of active buyers (new, retained,
returning and lapsed, from real orders of individual buyers) and the shared-groups part here (the same simulated
groups, used to compare test designs). The new part is the group structure, so it lives here, as a second groups page
that reuses the groups simulator, and it takes the lifecycle account's flows and its written-before-scoring statements
as method.

## The simulated app

Every number here is an assumption I chose, not an estimate from any company's data.

- **Groups.** The shared-groups simulator, called unchanged, with 14,000 possible users: groups of 2 to 8 people
  (weights 22%, 20%, 18%, 15%, 11%, 8% and 6%) on a ring that stands in for social nearness, and 15% of users also in
  one second group among the 20 nearest their own.
- **Arrivals.** Groups are created in ring order. New groups per month are Poisson with a mean of 24 in month 1,
  growing 2% a month. The group's first member joins when it is created; each other member joins after 0, 1, 2 or more
  months, with a 40% chance each month. A user is active in the month they join. The history runs 60 months; groups
  that would arrive later never appear.
- **Activity.** From the month after joining, a user is active with a chance set on the log-odds scale by: a base of
  -2.2; plus 3.6 if they were active last month; a user effect (SD 1.0); a first-group effect shared by its members
  (SD 0.5); a month shock shared by every user, which keeps 70% of last month's value and adds noise with SD 0.08; and
  the coupling.
- **Coupling.** Coupling times (the share of the user's joined group-mates, across all their groups, who were active
  last month, minus one half). Three settings: 0, 1 and 2, so a user whose group-mates were all active has 1, 2.7 or
  7.4 times the odds of one whose group-mates were all inactive. The base setting is 1 (moderate). A user with no
  joined group-mate gets no coupling term.
- **Control.** A fourth setting with no coupling and no month shock, 50 histories, used only for a check.
- **Runs.** 200 histories per setting, seed 23. Every setting reuses the same draws for the same history (groups,
  arrivals, joining, user and group effects, month shocks, activity draws), so settings differ only by the coupling.

A pilot on a reserved seed (90017, three histories per coupling) read only activity levels and time: over months 37
to 60 about 85% of a month's active users were active the next month and about 8% of joined, inactive users came
back. It ran no plan and computed no forecast error.

## The account

Per month, at user level: new (joined this month), retained (active this month and last), returning (active this
month, not last month, joined before) and lapsed (active last month, not this month). At group level the same with
groups, where a group is active when at least one of its first-group members is active and new in the month it is
created; and users per active group. Every user counts once, in their first group, so actives equal active groups
times users per active group.

What the user-level split hides: for each month 13 to 58 and each group with at least 3 members who joined at least 6
months earlier, the most active member is the one with the most active months over the previous 6 (ties: lowest user
number), and was active last month. Followers are the group's other members who were active last month and this month.
A follower lapses if inactive in either of the next two months. The measure is the share of followers who lapse when
the most active member lapsed this month, minus the share when the most active member stayed active, per history. With
no coupling this gap is not zero (groups share an effect, so a weak group loses members together); the coupling's part
is the base setting's gap minus the no-coupling gap, paired by history. One worked example: the first group from
month 37 in history 0 of the base setting with at least 4 such members whose most active member lapsed and at least
two followers lapsed within two months. It is chosen to show the pattern, not as a typical group.

## Three forecasts, fitted on the first 36 months only

Each plan is fitted once per history on months 1 to 36. From every origin month 36 to 57 it forecasts actives 1, 2 and
3 months ahead from the data observed up to the origin and the rates fitted on months 1 to 36: 22 origins per horizon.

1. **User plan** (the active-drivers method at user level). The chance a user is active next month, by tenure (months
   since joining: 0, 1, 2, 3 to 5, 6 to 11, 12 or more) and by whether they are active this month. Every joined user is
   carried forward from their observed state; planned new users are active in their first month and carried forward
   the same way.
2. **Group plan.** The chance a group is active next month, by group tenure and state; users per active group, by
   tenure and by whether the group was active the month before; users per active group in a group's first month.
   Expected active groups times users per active group, plus planned new groups times users per new group.
3. **Last year times recent growth** (the naive baseline): actives in the target month a year earlier, times actives at
   the origin over actives twelve months before it.

Planned new users and new groups for origin plus m months: the mean of the origin month and the two before it, grown
at the monthly rate of a least-squares line through the log of monthly arrivals over months 13 to 36.

## Scoring

Percentage error per forecast, (plan minus actual) over actual. Per history, method and horizon: mean absolute error
over the 22 origins, and mean signed error. Per setting: the mean over histories with a bootstrap 95% Monte Carlo
interval (2,000 resamples of histories, seed 2323), and the middle 90% of histories, which is closer to what one app
with one history would see. The group plan and the naive baseline are each compared with the user plan per history,
with the same interval and the share of histories where they did better.

## A bridge for each miss

The group plan one month ahead. Actual minus plan splits into three pieces: new groups (actual minus planned new
groups, valued at the plan's users per new group), groups kept or lost (actual minus planned active groups among those
created by the origin, valued at the plan's users per such group), and users per active group (actual users minus
actual groups times the plan's users per group). New users who join an existing group show up in the third piece. The
pieces add up exactly by construction; what the split shows is which one to own. Per setting: how often each piece is
the largest, and its typical size as a share of actual actives. Another order of the split would move part of each miss
between pieces.

## Predictions, written before the run

Each prediction is scored true or false on its point value after the run; a prediction holds only if every part holds.

1. One month ahead, in each of the three coupling settings, the user plan's mean error is below last year times
   growth's.
2. With no coupling, one month ahead, the group plan's mean error is at least the user plan's.
3. At the base (moderate) coupling, three months ahead, the group plan's mean error is below the user plan's.
4. The user plan's three-month mean error at strong coupling is at least 1.2 times its error with no coupling.
5. At the base coupling, users per active group is the largest piece of the group plan's month-ahead miss in more than
   half of the months.
6. At the base coupling, followers lapse after the most active member lapses at least 5 points more often than when the
   most active member stays, beyond the same gap with no coupling (paired by history).

## Checks

- Census: 650 histories, 14,300 plan rows and 39,000 month rows; every plan value finite.
- Control: with no coupling and no month shock, one month ahead, the user plan's mean absolute error is at most 2.0%
  and the group plan's at most 3.0%, and each plan's mean signed error is within 1.0 point. A wrongly built plan fails
  this; the tests show a plan that ignores tenure and state failing it.
- Bookkeeping, which confirms the code but cannot fail on a wrong model: the flow identities for users and groups in
  every month, and the bridge pieces adding up to the miss.
- A failed check is reported and kept; nothing is rerun with other random draws.

## What this leaves out

The simulation builds the coupling in, and I wrote both the simulation and the plans, so this is a self-test of
methods against a process I chose, not evidence about any real app. There is no seasonality, no change in the app that
moves activity, and no churn from the app itself; the month shock is the only common movement. Groups are fixed once
created, and nobody leaves a group. Overlap is fixed at 15%. Neither plan uses a user's share of active group-mates,
which is the quantity the coupling runs on; a plan that did would be the natural next step.
