KatInterview

Why Scaling Sample Singletons by 10 Overcounts Rare Queries

Statistics & ExperimentsModel answer
MediumModel answerStatistics & Experimentssamplinggood-turingfrequency-of-frequencies

Last updated

Explain the bias of scaling sample singleton counts from a 10% log sample, then build, stress-test and simulate better estimators of the true number of once-only queries.

A search engine stores one row per query submission each day. You are given a 10% simple random sample of rows, drawn without replacement, from one day's log, and you want to know how many distinct query strings occurred exactly once in the full day's log. Call these population singletons.

A colleague proposes the shortcut: count the query strings that occur exactly once in the sample and multiply by 10.

Answer the following.

a) Show that the shortcut is biased. State which direction the bias goes and give an intuitive explanation.

b) Describe a better estimator. Relate the sample frequency-of-frequencies counts (the number of distinct queries seen exactly k times in the sample) to the corresponding population counts under binomial thinning. Then propose at least one concrete estimator, such as a Good-Turing/Good-Toulmin style correction, a Chao-type estimator, or a Poisson/negative-binomial mixture fit.

c) Explain how you would compute standard errors or confidence intervals (for example the delta method and the bootstrap), and how you would detect that your model is misspecified when query frequencies are heavy-tailed.

d) Outline a simulation study to compare candidate estimators across realistic traffic distributions.

Aim for a structured answer with formulas where helpful, and be explicit about the trade-offs.

Hints

Hint 1

Let F_j be the number of distinct queries occurring exactly j times in the full log. A query with j occurrences shows up exactly once in the sample with probability j·p·(1−p)^(j−1). What does the expectation of 10·f_1 look like when you sum this over all j?

Hint 2

Under binomial thinning, E[f_k] is a triangular linear function of the F_j. Inverting it exactly gives an alternating series with coefficients growing like 9^k. Think about why that is unbiased yet useless, and what regularization (damping the tail, or a parametric mixture) buys you.

Hint 3

For uncertainty, a naive row-level bootstrap of the sample creates fake duplicates. Think about resampling distinct queries or using a parametric bootstrap from the fitted model. For simulation, vary the tail heaviness (Zipf exponent), the number of distinct queries and the sampling rate, and report bias, RMSE and CI coverage.