Probability Distributions, Sampling Bias, and Correlation

Medium · Machine Learning · Data Scientist · Online Assessment

Prompt

Answer each of the following three foundational probability and statistics scenarios clearly, stating any modeling assumptions you rely on:

  1. Count Process Shift: An automated payment-monitoring pipeline historically averages 2 flagged alerts per hour across one-hour observation windows. After a platform change, you inspect the empirical probability mass function (PMF) of hourly alert counts and find that the fraction of zero-alert hours has dropped sharply below the theoretical Poisson(2) baseline. What does this tell you about the underlying arrival mechanism, and which model parameter may have shifted?
  2. Training Cohort Selection Bias: A B2B subscription software company wants to predict account cancellation. To assemble a labeled dataset, the team samples currently active customer accounts that have maintained at least 12 months of continuous tenure, then deploys the resulting classifier to score newly onboarded sign-ups. Name the statistical bias created by this cohort filter and explain how it distorts model behavior on brand-new accounts.
  3. Zero Covariance and Affine Transformations: Let X and Y be real-valued random variables:
    • Does Cov(X, Y) = 0 guarantee that X and Y are statistically independent? Justify your conclusion or construct a concrete counterexample.
    • Suppose X is transformed into X_new = aX + b, where a < 0 is a strictly negative constant and b is any real number. How does the Pearson correlation coefficient rho(X_new, Y) relate to rho(X, Y)?

Scope & Expectations

  • Connect the theoretical Poisson zero-count probability and mean-equals-variance property to concrete reasons zero-count windows vanish (distinguishing true arrival-rate growth from underdispersion, positive floors, or dropped zero records).
  • Diagnose how tenure-based sample truncation alters training labels, feature distributions, calibration, and offline validation metrics relative to a Day-1 cohort.
  • Contrast linear co-movement (Cov(X, Y)) with full distributional independence, and show algebraically how location shifts (b) and negative scaling (a < 0) act on the numerator and denominator of Pearson correlation.

Step-by-step walkthrough

  1. Part 1a: What a theoretical Poisson(2) process predicts

    A Poisson process models discrete events (such as monitoring alerts) arriving one at a time, independently of one another, at a steady average rate λ per unit time. Its probability mass function (PMF)—the formula giving the exact probability of observing k alerts in a one-hour window—is:

    P(K = k) = e^(-λ) * λ^k / k!        for k = 0, 1, 2, ...
    Key Poisson identity:   Mean(K) = Variance(K) = λ
    

    Plugging in the historical rate λ = 2 alerts per hour (e^(-2) ≈ 0.1353):

    Alerts in 1 hour (k):      0       1       2       3       4       5      6+
    Theoretical P(K = k):   0.1353  0.2707  0.2707  0.1804  0.0902  0.0361  0.0166
    

    Under a genuine Poisson(2) process, roughly 13.5% of hours (0.1353) record zero alerts—about 13 to 14 quiet hours in every 100 hours monitored (the chance of seeing zero quiet hours across 50 independent hours is (1 - 0.1353)^50 ≈ 0.0007, well under 0.1%). Because a Poisson model has only a single parameter (λ), seeing far fewer zeros than 13.5% means either λ itself rose, or hourly counts no longer follow a pure Poisson process.

  2. Part 1b: Why zero-alert hours vanished—and which parameter shifted

    Compare the new empirical distribution against Poisson(2) by inspecting both the sample mean and the dispersion index (Variance / Mean, which equals 1.0 for any true Poisson process):

    Poisson(2) baseline:       k=0 [#######] k=1 [##############] k=2..3 [#######################]  (mean=2, var=2)
    Case A (higher λ = 4):     k=0 [#]       k=1 [####]           k=3..5 [########################] (mean=4, var=4)
    Case B (underdispersed):   k=0 [ ]       k=1 [########]       k=2..3 [########################] (mean=2, var=0.4)
    
    1. Case A — The arrival rate parameter λ increased (process remains Poisson): Because P(K = 0) = e^(-λ) decays exponentially, higher traffic shrinks zero-count hours rapidly (λ = 4 gives P(0) = 1.83%; λ = 5 gives P(0) = 0.67%). You confirm this if the sample mean also rose (say from 2.0 to ~4.0) while Variance ≈ Mean.
    2. Case B — Underdispersion or zero-truncation (mean stays near 2, regularity/floor parameter changed): Underdispersion means Variance < Mean—hourly counts cluster much more tightly around 2 than independent random arrivals allow:
      • Positive floor or zero-truncation: A new synthetic hourly health-check injects 1 guaranteed alert every hour (K = 1 + Poisson(1) has Mean = 2, Variance = 1, and P(0) = 0), or an ingestion pipeline drops rows whenever the hourly count is 0 (zero-truncated Poisson).
      • Rate-smoothed intake or logging ceiling: If upstream batching paces alerts out evenly instead of letting them arrive independently, generalized count models such as Conway–Maxwell–Poisson CMP(λ, ν) show an increased dispersion parameter ν > 1. Likewise, if a throttling rule caps logged alerts at 3 per hour (a ceiling), an observed mean of 2.0 masks a higher underlying rate (λ ≈ 2.35), pulling P(0) down to e^(-2.35) ≈ 9.6% and variance down to 1.02.

    Crucial trap to rule out: Day-versus-night traffic swings averaging 2 alerts/hour cannot shrink P(0). Mixing half λ = 0.5 overnight hours and half λ = 3.5 peak hours keeps the overall mean at (0.5 + 3.5) / 2 = 2.0, yet P(0) = 0.5 * e^(-0.5) + 0.5 * e^(-3.5) ≈ 0.318 (31.8% > 13.5%)! Rate variation creates overdispersion (Variance > Mean) and extra zeros, the exact opposite of what appeared here.

    # Quick diagnostic on 20 observed hourly counts: check BOTH mean and variance / mean
    counts = [2, 2, 3, 1, 2, 2, 3, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 1, 2, 2]
    n = len(counts)
    sample_mean = sum(counts) / n
    sample_var = sum((c - sample_mean) ** 2 for c in counts) / (n - 1)
    dispersion_index = sample_var / sample_mean
    
    print(f"mean={sample_mean:.2f}, var={sample_var:.2f}, var/mean={dispersion_index:.2f}")
    # mean=2.00, var=0.42, var/mean=0.21 -> mean stayed 2.00, strong underdispersion (Case B)!
    
  3. Part 2a: Why restricting to 12-month subscribers creates survivorship bias

    Training exclusively on accounts that remained active for at least 12 months introduces survivorship bias—a form of selection bias in which examples enter the dataset only after surviving a threshold directly tied to the target outcome (known in survival analysis as left truncation).

    8,000 New Customer Sign-Ups (Target Population at Day 0)
      |
      +---> 2,400 cancel during Months 0..12 ---> [EXCLUDED! Never reach 12-month tenure]
      |
      +---> 5,600 survive past Month 12      ---> [TRAINING SET: seasoned accounts only!]
    

    Excluding everyone who canceled prior to Month 12 distorts the learning problem in three ways:

    • Erased early-cancellation labels: Every account that abandoned the platform during initial setup or within its first 11 months is completely absent from training.
    • Truncated feature support: tenure_months is strictly >= 12 in training, and early-adoption signals (such as "completed_sso_setup" or "invited_team_members") are nearly 100% True among 12-month veterans, masking how strongly those signals separate sticky new customers from early dropouts.
    • Mismatched cancellation drivers: First-quarter cancellations typically stem from integration friction, missing features, or trial expiration, whereas second-year cancellations reflect budget cuts or vendor consolidation. The classifier learns only late-stage behavior.
  4. Part 2b: Quantifying how the biased classifier fails on newly onboarded accounts

    Trace the cohort numbers above: suppose out of 8,000 new sign-ups, 1,600 cancel in Quarter 1 (20% quarterly cancellation rate), another 800 cancel across Quarters 2–4, and among the 5,600 accounts reaching Month 12, only 4% cancel in any subsequent quarter.

    Population                       True Quarterly Cancel Rate   What the Model Predicts
    ------------------------------   --------------------------   ---------------------------------------
    12-month survivors (training)                4%               ~4% on average (calibrated on veterans)
    Brand-new sign-ups (production)             20%               ~4% (5x under-prediction!)
    

    Deploying this model on new sign-ups produces four concrete failures:

    1. Severe probability miscalibration (systematic under-prediction): Because the classifier learned a 4% baseline risk instead of 20%, expected revenue-at-risk forecasts and customer-success staffing plans are underestimated by roughly 5×.
    2. Missed high-risk newcomers (low recall): If customer-success outreach fires only when predicted_cancel_prob > 12%, almost no newly onboarded accounts clear that bar, letting the majority of the 1,600 first-quarter cancellations slip away unassisted.
    3. Out-of-domain extrapolation: Feeding tenure_months = 1 into a model trained solely on tenure_months >= 12 forces linear or neural models to extrapolate far below their training range and pushes tree ensembles to route Day-1 accounts into the tenure == 12 split.
    4. Illusory offline validation scores: A standard random 80/20 train/test split taken from the same 12-month survivor snapshot repeats the exact same truncation in the test fold, making offline AUC and calibration curves look deceptively healthy before launch. (Whenever raw historical logs exist, rebuild the dataset from point-in-time cohort snapshots starting at Day 1.)
  5. Part 3a: Why zero covariance does not guarantee independence

    Covariance (Cov(X, Y) = E[(X - E[X])(Y - E[Y])] = E[XY] - E[X]E[Y]) captures only linear association—whether Y tilts systematically upward or downward along a straight line as X grows. Statistical independence is a far stricter requirement: observing X provides zero information of any kind about Y (P(X = x, Y = y) = P(X = x) * P(Y = y) for every (x, y)).

    A transparent counterexample lets X take values {-2, 0, +2} with equal probability 1/3 each, and sets Y = X^2:

      Y
      4 |   *(-2, 4)            *(+2, 4)      Best-fit straight line is horizontal (slope = 0),
        |                                     so negative and positive X tilts cancel in Cov(X, Y)!
      0 |             *(0, 0)                 Yet knowing X pins down Y with 100% certainty.
        +-------------------------------- X
           -2         0        +2
    

    Check both facts directly:

    1. Compute Cov(X, Y):
       E[X]  = (-2)*(1/3) + 0*(1/3) + 2*(1/3) = 0
       E[XY] = E[X^3] = (-8)*(1/3) + 0*(1/3) + 8*(1/3) = 0
       Cov(X, Y) = E[XY] - E[X]*E[Y] = 0 - 0 * (8/3) = 0
    
    2. Disprove independence (check X = 0, Y = 0):
       Actual joint probability:      P(X = 0 and Y = 0) = P(X = 0) = 1/3
       Product of marginal probs:     P(X = 0) * P(Y = 0) = (1/3) * (1/3) = 1/9
       Since 1/3 != 1/9, X and Y are NOT independent!
    
    import numpy as np
    
    # Equally likely outcomes (-2, 4), (0, 0), (+2, 4)
    x = np.array([-2.0, 0.0, 2.0])
    y = x ** 2
    population_cov = float(np.mean(x * y) - np.mean(x) * np.mean(y))
    print(population_cov)  # 0.0, even though y = x^2 is 100% deterministic!
    

    Remember which implication does hold (whenever variances are finite): independence always implies Cov(X, Y) = 0, and the reverse holds when (X, Y) follow a jointly normal (bivariate Gaussian) distribution.

  6. Part 3b: How `X_new = aX + b` (with `a < 0`) changes Pearson correlation

    The Pearson correlation coefficient rho(X, Y) divides covariance by the product of both standard deviations (sd), producing a scale-free measure in [-1, +1]:

    rho(X, Y) = Cov(X, Y) / (sd(X) * sd(Y))
    

    Propagate X_new = aX + b through the numerator and denominator step by step:

    1. Additive shift `b` cancels out in mean-centered deviations:
       E[aX + b] = a * E[X] + b
       (aX + b) - E[aX + b] = (aX + b) - (a * E[X] + b) = a * (X - E[X])
    
    2. Numerator (covariance scales by `a`, keeping `a`'s negative sign):
       Cov(aX + b, Y) = E[ a * (X - E[X]) * (Y - E[Y]) ] = a * Cov(X, Y)
    
    3. Denominator (standard deviation is non-negative, so it scales by |a|, NOT `a`!):
       Var(aX + b) = E[ (a * (X - E[X]))^2 ] = a^2 * Var(X)
       sd(aX + b)  = sqrt(a^2 * Var(X))      = |a| * sd(X)
    
    4. Combine numerator and denominator:
       rho(aX + b, Y) = (a * Cov(X, Y)) / (|a| * sd(X) * sd(Y))
                      = (a / |a|) * rho(X, Y)
    

    Since a < 0, |a| = -a and a / |a| = -1. Consequently rho(X_new, Y) = -rho(X, Y): the absolute strength is unchanged, the sign reverses, and b has zero impact.

    Verify numerically on X = [1, 2, 4, 5], Y = [2, 3, 7, 8], and X_new = -3X + 12 = [9, 6, 0, -3]:

    import numpy as np
    
    x = np.array([1.0, 2.0, 4.0, 5.0])
    y = np.array([2.0, 3.0, 7.0, 8.0])
    x_new = -3.0 * x + 12.0
    
    rho_orig = float(np.corrcoef(x, y)[0, 1])
    rho_transformed = float(np.corrcoef(x_new, y)[0, 1])
    print(round(rho_orig, 4), round(rho_transformed, 4))  # 0.9923  -0.9923
    

Intuition & how it works

All three scenarios test one core data-science discipline: recognizing what structural detail a single summary statistic or query filter silently discards. A single Poisson rate λ locks the average and the spread together (Mean = Variance = λ), a veteran-only account query erases everyone who canceled early, and covariance projects a two-dimensional relationship onto a single straight-line tilt.

Surface-level intuition misfires whenever you read the headline number without inspecting the distribution or cohort behind it: assuming fewer quiet hours must reflect heavier traffic rather than artificially regular arrivals, trusting high holdout scores on a 12-month-tenure dataset that omitted every first-year cancellation, or treating Cov(X, Y) = 0 as proof that X tells you nothing about Y when Y follows a symmetric U-curve.

Trace each idea on a compact concrete example: 1. Missing Poisson zeros (Part 1): Poisson(2) predicts e^(-2) ≈ 13.5% zero-alert hours. If an hourly synthetic probe adds 1 guaranteed alert onto Poisson(1) (K = 1 + Poisson(1)), the mean stays 2.0, yet P(K = 0) drops to 0% and variance falls from 2.0 to 1.0 (underdispersion). 2. Survivorship bias (Part 2): Out of 100 new accounts, if 30 cancel before Month 12 and only 3 of the 70 veterans cancel in the next quarter, training solely on Month-12 survivors teaches a 3 / 70 ≈ 4.3% baseline rate instead of the steep early-cohort risk. 3. Covariance & affine scaling (Part 3): Across (-2, 4), (0, 0), (+2, 4), negative and positive slopes cancel (Cov = 0) even though Y = X^2; meanwhile mapping X to X_new = -3X + 12 reflects the point cloud horizontally and shifts its center, preserving linear tightness while flipping +rho to -rho.

Key points

  • Poisson(2) baseline and diagnosing missing zeros: Under Poisson(λ), P(K = 0) = e^(-λ) (13.53% at λ = 2) and Mean = Variance = λ. A sharp drop in zero-count windows means either the arrival rate λ grew (sample mean rose above 2 with Variance / Mean ≈ 1) or counts became underdispersed / zero-truncated (sample mean stayed near 2 with Variance / Mean < 1, driven by a positive floor like synthetic checks, dropped zero-count records, rate-smoothed batching, or a logging ceiling).
  • Rate swings across hours produce more zeros, never fewer: By Jensen's inequality (averaging a convex curve such as e^(-λ) across varying rates lands above e^(-mean(λ))), mixing quiet (λ = 0.5) and busy (λ = 3.5) hours with mean 2.0 lifts P(0) from 13.5% to 31.8%.
  • Part 2 introduces survivorship bias (left truncation): Requiring tenure >= 12 months conditions inclusion on surviving the entire first year, stripping out early-cancellation labels, hiding tenure < 12 feature behavior, and severely under-predicting risk on new cohorts even when survivor-only test splits look strong.
  • Cov(X, Y) = 0 rules out linear tilt, not nonlinear dependence: Symmetric pairings such as X uniform on {-2, 0, +2} with Y = X^2 give Cov(X, Y) = 0 while Y is 100% determined by X. Zero correlation implies independence reliably when (X, Y) are jointly normal (bivariate Gaussian).
  • rho(aX + b, Y) = sign(a) * rho(X, Y) for any a != 0: Adding b shifts observations and mean equally (canceling in X - E[X]), whereas multiplying by a < 0 multiplies Cov by a and sd(X) by |a| = -a, leaving a / |a| = -1 so rho flips sign with identical magnitude.

Common mistakes

  • Concluding λ rose in Part 1 without checking whether the sample mean actually increased. If the hourly average remained 2.0 while zeros disappeared, λ did not jump to 4—the independent, unbounded Poisson assumptions broke down.
  • Attributing missing zeros to peak-vs.-off-peak traffic variation. Changing arrival rates induce overdispersion (Variance > Mean) and increase P(K = 0).
  • Calling Part 2 "class imbalance" and reaching for SMOTE / oversampling. Duplicating Month-13 cancellations only clones veteran cancellation patterns; it cannot reconstruct first-month onboarding drop-offs absent from the table.
  • Claiming separate normal marginals plus Cov(X, Y) = 0 guarantee independence. (X, Y) must be jointly normal—if X ~ N(0, 1) and S is a fair ±1 coin flip, Y = S * X is marginally N(0, 1) with Cov(X, Y) = 0, yet |Y| = |X|.
  • Dropping the absolute value in sd(aX + b) = |a| * sd(X). Writing sd(aX + b) = a * sd(X) cancels a / a = +1 and misses the sign reversal for a < 0; writing rho_new = a * rho violates -1 <= rho <= 1.

Follow-up questions

  • When count data exhibits variance far exceeding its mean, why does standard Poisson regression break down and which alternative regression models address it? Variance exceeding the mean is overdispersion, and fitting ordinary Poisson regression underestimates parameter standard errors and inflates false-positive significance because the Poisson likelihood forces Var(Y | X) = μ. Replace it with Negative Binomial regression, which models each unit's Poisson rate with a Gamma prior around mean μ, introducing a quadratic variance term Var(Y | X) = μ + α * μ^2 (α > 0) that absorbs burstiness or unobserved customer heterogeneity. Depending on the mechanism, Quasi-Poisson preserves the Poisson mean equation while scaling variance by φ * μ to correct confidence intervals, whereas Zero-Inflated Poisson or Negative Binomial (ZIP / ZINB) fits best when excess variance stems from a structural spike at k = 0.
  • Suppose historical records for accounts that canceled early were purged—what practical steps can reduce the resulting survivorship bias for new-cohort scoring? First, immediately begin recording point-in-time daily or weekly snapshots for every new sign-up alongside fast early proxy labels (such as 14-day or 30-day inactivity) so an unbiased early-tenure training set builds up rapidly. Second, in the interim, score tenure < 12 months accounts with a separate rule set or anomaly-detection baseline derived from the preserved early-month activity logs of current veterans (flagging newcomers whose Week-1 usage trails far behind healthy veterans' Week-1 trajectories) instead of passing tenure = 1 into the veteran model. Third, if finance reports still retain the aggregate early-cancellation base rate (say π_new = 20% vs. π_train = 4%), apply a prior-odds recalibration—multiplying predicted odds p / (1 - p) by (0.20 / 0.80) / (0.04 / 0.96) = 6.0—as a temporary calibration adjustment while noting its assumption that conditional feature patterns match across tenures.
  • How is the ordinary least squares slope when regressing Y on X algebraically linked to the Pearson correlation coefficient? In ordinary least squares (OLS) simple linear regression (choosing intercept β_0 and slope β_1 in Ŷ = β_0 + β_1 * X to minimize squared vertical residuals Σ(y_i - β_0 - β_1 * x_i)^2), setting the partial derivatives with respect to β_0 and β_1 to zero gives β_0 = mean(Y) - β_1 * mean(X) and β_1 = Cov(X, Y) / Var(X). Because Var(X) = sd(X)^2 and rho(X, Y) = Cov(X, Y) / (sd(X) * sd(Y)), substituting Cov(X, Y) = rho(X, Y) * sd(X) * sd(Y) cancels one sd(X) factor and yields β_1 = rho(X, Y) * (sd(Y) / sd(X)). In plain words, each 1-standard-deviation increase in X predicts a rho-standard-deviation shift in Y (on X = [1, 2, 4, 5], Y = [2, 3, 7, 8], rho = 0.9923 and sd(Y) / sd(X) = 1.6125, giving β_1 = 0.9923 * 1.6125 = 1.6), and rho^2 equals the regression's R^2.

Follow-up questions

Similar questions

More Morgan Stanley interview questions

All 11 Morgan Stanley questions →