Test whether samples follow a binomial distribution
J.P. MorganData Scientist · OnsiteLast updated
This problem tests the application of goodness-of-fit testing to verify if a set of discrete observations conforms to a binomial distribution.
Problem Statement
You are working on a risk modeling team and receive a dataset containing the number of successful outcomes across N independent trials for M different experiment groups. Each experiment group consists of n trials with a success probability p.
Your task is to determine whether the observed success counts in these M groups follow a binomial distribution B(n, p).
Requirements
- Given the array
observationsof lengthM(where each element is the number of successes in a group ofntrials), estimate the parameterpusing the Method of Moments. - Construct the expected frequency for each possible outcome
k(where0 <= k <= n) under the null hypothesis that the data followsB(n, p). - Propose and implement a statistical test to quantify the goodness-of-fit. Provide the test statistic and explain how to determine the p-value.
Example
- Input:
observations = [1, 2, 2, 3, 1],n = 4,M = 5 - Step 1: Mean successes = (1+2+2+3+1)/5 = 1.8. Estimate
p= 1.8 / 4 = 0.45. - Step 2: Calculate expected frequencies for
k = 0, 1, 2, 3, 4usingP(X=k) = C(n, k) * p^k * (1-p)^(n-k)multiplied byM. - Step 3: Compare expected vs. actual frequencies using the Chi-Squared test.
Constraints
n(trials per group) is between 5 and 50.M(number of groups) is at least 100.- Ensure all expected bin frequencies are greater than 5 to maintain the validity of the Chi-Squared approximation.
Hints
Hint 1
Use the sample mean to estimate the probability p, knowing that for a binomial distribution, the mean is E[X] = n * p.
Hint 2
The Chi-Squared goodness-of-fit test is appropriate here, where the test statistic is the sum of (Observed - Expected)^2 / Expected.
Hint 3
Remember to subtract degrees of freedom for the parameter estimated from the data when calculating the p-value from the Chi-Squared distribution.
Follow-up questions
- How would your approach change if you were testing for a Poisson distribution instead of a Binomial distribution?
- What are the limitations of the Chi-Squared test if your expected frequencies in certain bins are very small?
- If the test rejects the null hypothesis, how would you investigate whether the data is 'overdispersed' (i.e., variance is higher than the binomial model predicts)?
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.