Covers fundamental probability theory and statistical inference from first principles to practical applications. Core probability concepts include sample spaces and events, independence, conditional probability, Bayes theorem, expected value, variance, and standard deviation. Reviews common probability distributions such as normal, binomial, Poisson, uniform, and exponential, their parameters, typical use cases, computation of probabilities, and approximation methods. Explains sampling distributions and the Central Limit Theorem and their implications for estimation and confidence intervals. Presents descriptive statistics and data summary measures including mean, median, variance, and standard deviation. Details the hypothesis testing workflow including null and alternative hypotheses, p values, statistical significance, type one and type two errors, power, effect size, and interpretation of results. Reviews commonly used tests and methods and guidance for selection and assumptions checking, including z tests, t tests, chi square tests, analysis of variance, and basic nonparametric alternatives. Emphasizes practical issues such as correlation versus causation, impact of sample size and data quality, assumptions validation, reasoning about rare events and tail risks, and communicating uncertainty. At more advanced levels expect experimental design and interpretation at scale including A B tests, sample size and power calculations, multiple testing and false discovery rate adjustment, and design choices for robust inference in real world systems.
HardTechnical
67 practiced
Implement a permutation test (in Python or detailed pseudocode) to assess whether the observed average clustering coefficient differs between two groups of networks. Networks vary in size and degree distribution. Explain how you would construct the null permutations to preserve exchangeability, and describe options to preserve within-network structural properties (e.g., degree-preserving swaps) when appropriate.
Sample Answer
**Approach (brief)**- Compute observed difference in mean clustering coefficient between Group A and Group B, where each "sample" is a network's average clustering (taking care to compute transitivity or node-wise clustering as needed).- Build null by permuting group labels across networks only when exchangeability holds. If networks differ in size/degree distribution, restrict permutations within strata (matching by size/degree quantiles) or use network-level constrained resampling: for each network, generate null networks preserving chosen properties (e.g., degree sequence) and keep group labels fixed.**Python implementation (sketch)**
python
import random
import numpy as np
import networkx as nx
from copy import deepcopy
def avg_clustering(G):
return nx.average_clustering(G) # node-wise average
def permutation_test(networks, labels, n_perms=5000, stratify=None):
# networks: list of networkx graphs
# labels: list/array of 0/1 group labels
# stratify: list of strata indices same length as networks (optional)
obs_diff = np.mean([avg_clustering(G) for G, l in zip(networks, labels) if l==1]) - \
np.mean([avg_clustering(G) for G, l in zip(networks, labels) if l==0])
perm_diffs = []
indices = list(range(len(networks)))
for _ in range(n_perms):
if stratify is None:
perm_labels = np.array(labels)[np.random.permutation(indices)]
else:
perm_labels = np.empty_like(labels)
for s in set(stratify):
idx = [i for i,ss in enumerate(stratify) if ss==s]
perm_labels[idx] = np.array(labels)[np.random.permutation(idx)]
diff = np.mean([avg_clustering(networks[i]) for i in indices if perm_labels[i]==1]) - \
np.mean([avg_clustering(networks[i]) for i in indices if perm_labels[i]==0])
perm_diffs.append(diff)
p_value = (1 + sum(abs(d) >= abs(obs_diff) for d in perm_diffs)) / (1 + n_perms)
return obs_diff, np.array(perm_diffs), p_value
# Option: degree-preserving null generation per-network
def degree_preserving_nulls(G, n_swaps=1000):
Gs = deepcopy(G)
nx.double_edge_swap(Gs, n_swaps, max_tries=n_swaps*10)
return Gs
**Exchangeability & Null construction**- Exchangeability requires that under null the label assignment doesn't affect distribution of the test statistic. If networks have differing size/degree, raw label permutation across all networks violates exchangeability.- Use stratified permutations: group networks into strata by size and mean degree (or degree-distribution quantiles) and permute labels only within strata.- Alternative: keep labels fixed and generate null networks for each original by resampling edges under constraints (Erdos-Renyi matched density, configuration model to preserve degree sequence, or degree-preserving double-edge swaps). Then compute statistic difference across many simulated datasets to form null.**Options to preserve within-network structure**- Configuration model: preserves exact degree sequence but introduces self-loops/multi-edges; post-process or use simple graph configuration variants.- Double-edge swap (nx.double_edge_swap): preserves degree sequence and simple graph property; use many swaps to approach uniform sample from degree-preserving ensemble.- Preserve degree distribution coarsely: match degree histogram rather than exact sequence (use stub-matching within bins).- Preserve clustering or motifs: use exponential random graph models (ERGMs) or constrained MCMC — more complex and computationally heavier.**Practical considerations**- Compute clustering consistently (transitivity vs. average clustering).- Use enough permutations (or simulate null graphs) and seed RNG for reproducibility.- If sample size is small, use exact permutations within strata.- Report effect size, permutation distribution plots, and whether null preserves degrees. Complexity dominated by graph resampling cost: O(n_perms * cost_per_graph).
MediumTechnical
55 practiced
In Python (pseudocode acceptable), implement a nonparametric bootstrap to estimate a 95% confidence interval for the difference in means between two independent samples A and B. Your function should accept arrays A, B, number of resamples B_resamples, and a choice between 'percentile' and 'bootstrap-t' CI methods. Briefly comment on parallelization and performance concerns for large B_resamples.
Sample Answer
**Approach (brief)** Use nonparametric resampling with replacement to compute bootstrap distribution of mean(A*) - mean(B*). Support two CI styles: percentile (quantiles of bootstrap differences) and bootstrap-t (studentized: use bootstrap estimate of standard error per resample). Return 95% CI by default.**Code (Python/pseudocode)**
python
import numpy as np
def bootstrap_diff_means(A, B, B_resamples=10000, method='percentile', alpha=0.05, rng=None):
rng = np.random.default_rng(rng)
nA, nB = len(A), len(B)
A = np.asarray(A); B = np.asarray(B)
# observed statistic
obs = A.mean() - B.mean()
diffs = np.empty(B_resamples)
if method == 'bootstrap-t':
t_stats = np.empty(B_resamples)
for i in range(B_resamples):
a_star = rng.choice(A, size=nA, replace=True)
b_star = rng.choice(B, size=nB, replace=True)
diffs[i] = a_star.mean() - b_star.mean()
if method == 'bootstrap-t':
# estimate standard error using simple bootstrap within resample (or analytic if assumed)
se = np.sqrt(a_star.var(ddof=1)/nA + b_star.var(ddof=1)/nB)
t_stats[i] = (diffs[i] - obs) / se if se > 0 else 0.0
if method == 'percentile':
lo, hi = np.quantile(diffs, [alpha/2, 1-alpha/2])
return lo, hi
elif method == 'bootstrap-t':
t_lo, t_hi = np.quantile(t_stats, [1-alpha/2, alpha/2]) # note inversion
se_obs = np.sqrt(A.var(ddof=1)/nA + B.var(ddof=1)/nB)
return obs - t_lo * se_obs, obs - t_hi * se_obs
else:
raise ValueError("method must be 'percentile' or 'bootstrap-t'")
**Key points & complexity** - Time: O(B_resamples * (nA + nB)). Memory: O(B_resamples) to store diffs. - Edge cases: small sample sizes, zero variance, ties — handle se==0. For bootstrap-t, inner SE can be improved with analytical SE or nested bootstraps (more costly).**Parallelization & performance** - Independent resamples -> trivially parallelizable across CPU cores or GPUs. Use joblib, multiprocessing, or vectorized batching. - For very large B_resamples, stream statistics (avoid storing all diffs) or accumulate quantile summaries (t-digest). Use 32-bit floats to reduce memory; ensure RNG streams per worker for reproducibility.
MediumTechnical
98 practiced
Explain how the Central Limit Theorem's rate of convergence depends on skewness and tail behavior. Provide concrete rule-of-thumb guidelines for minimum sample sizes when underlying distributions are light-tailed, moderately skewed, and heavy-tailed. Outline a short simulation (pseudocode) that empirically compares convergence rates across these cases.
Sample Answer
**Brief answer / intuition**The CLT says sample means converge to normal at rate ~1/sqrt(n), but the finite-sample approximation error depends on third moment (skewness) and tail behavior. The Berry–Esseen theorem quantifies this: the Kolmogorov distance is bounded by C * (E|X - μ|^3) / (σ^3 * sqrt(n)). Heavy tails (infinite third moment) break this bound and slow/obstruct convergence.**Rule-of-thumb minimum n (practical guidelines)**- Light-tailed, near-symmetric (e.g., Gaussian, uniform): n ≈ 30 is usually sufficient.- Moderately skewed, finite third moment (e.g., exponential, log-normal with mild skew): n ≈ 100–500.- Heavy-tailed (Pareto with α in (2,3) or α ≤ 2): if third moment diverges, CLT may hold slowly or require n ≫ 1000; for α close to 2, aim n > 10,000; if α ≤ 2, consider stable laws and robust estimators instead.Reasoning: Berry–Esseen implies error ∝ skewness / sqrt(n); larger skew/tails increase constant and require larger n. If third moment infinite, asymptotics change.**Short simulation pseudocode**
python
# Pseudocode
distributions = {
"normal": lambda n: np.random.normal(size=n),
"exponential": lambda n: np.random.exponential(size=n),
"lognormal": lambda n: np.random.lognormal(mean=0, sigma=1, size=n),
"pareto_alpha2.5": lambda n: (np.random.pareto(2.5, size=n)+1) # finite 3rd
"pareto_alpha1.8": lambda n: (np.random.pareto(1.8, size=n)+1) # heavy-tail
}
ns = [10,30,100,300,1000,5000,20000]
trials = 2000
for name, sampler in distributions.items():
for n in ns:
z_scores = []
for t in range(trials):
x = sampler(n)
z = (x.mean() - x.mean()) / (x.std(ddof=1)/sqrt(n)) # standardized sample mean
# compare empirical distribution of z to standard normal, e.g., KS statistic or quantile errors
record KS or max quantile deviation vs n
plot deviation vs n on log-log scale per distribution
Interpretation: compare slopes; light-tailed will show ~1/sqrt(n) decay, moderate skew slower constant, heavy-tail may plateau or decay much slower — guiding required sample sizes. Use robust mean/trimmed mean when tails problematic.
EasyTechnical
50 practiced
State the Central Limit Theorem (CLT) precisely for IID random variables with finite variance. Explain its implications for sample means and sampling distributions in practice. Give a recommended rule-of-thumb for when the CLT can be used, and sketch a short simulation plan (pseudocode) that demonstrates CLT convergence for a highly skewed distribution.
Sample Answer
**Precise statement (IID, finite variance)** Let X1, X2, ... be independent, identically distributed random variables with mean μ = E[X1] and finite variance σ^2 = Var(X1) < ∞. Define the sample mean S_n = (1/n) Σ_{i=1}^n X_i. Then as n → ∞,
text
sqrt(n) ( S_n - μ ) ⇒ N(0, σ^2)
(in distribution). Equivalently, (S_n - μ) ~≈ N(0, σ^2 / n) for large n.**Implications for practice** - Sampling distribution of the mean becomes approximately normal even when the underlying distribution is non-normal, enabling z/t style inference. - Standard error = σ / sqrt(n) (use sample s if σ unknown). - Allows confidence intervals and hypothesis tests that rely on normality.**Rule-of-thumb** For moderately skewed distributions use n ≥ 30; for highly skewed or heavy-tailed distributions use n ≥ 50–100. If tails are very heavy, prefer robust methods or bootstrap.**Simulation plan (pseudocode)** Demonstrate convergence for an exponential(1) (highly skewed):
python
# pseudocode
for n in [5,10,30,50,100,500]:
means = []
for rep in 1..10000:
sample = draw n samples from Exponential(1)
means.append(mean(sample))
plot_histogram((means - 1) * sqrt(n)) # compare to N(0,1)
compute_ks_statistic(means, Normal(1, 1/n))
Check histograms and KS/Wasserstein distances to quantify convergence.
MediumTechnical
49 practiced
Describe one-way ANOVA: write the model, state the null hypothesis, derive (at a high level) the ANOVA F-statistic, and list model assumptions. If ANOVA rejects, explain two post-hoc procedures (e.g., Tukey HSD and Bonferroni correction), their goals, and when one may be preferable over the other.
Sample Answer
**One-way ANOVA — Model & Null**- Model (fixed-effects):
text
y_{ij} = μ + τ_i + ε_{ij}
where i = 1..k groups, j indexes observations, μ is overall mean, τ_i is group effect (sum τ_i = 0), ε_{ij} ~ iid N(0, σ^2).- Null hypothesis: H0: τ_1 = τ_2 = ... = τ_k = 0 (all group means equal)**ANOVA F-statistic (high-level derivation)**- Partition total variability into between-group and within-group:
text
SST = SSB + SSW
- Mean squares:
text
MSB = SSB / (k-1)
MSW = SSW / (N-k)
- F-statistic:
text
F = MSB / MSW
Under H0, F ~ F_{k-1, N-k}; large F implies group means differ.**Model assumptions**- Independence of observations- Normality of residuals ε_{ij}- Homogeneity of variances (σ^2 equal across groups)- Correct model specification (additivity)**Post-hoc procedures if ANOVA rejects**1. Tukey HSD- Goal: all-pairs simultaneous comparisons controlling family-wise error rate (FWER) using studentized range distribution.- Pros: exact for balanced designs, good power for pairwise tests, controls FWER across all pairs.- Prefer when: you need all pairwise contrasts and groups sizes are similar.2. Bonferroni correction- Goal: simple FWER control by adjusting per-comparison α' = α / m for m tests.- Pros: easy, works for arbitrary contrasts, conservative (safe).- Prefer when: few planned comparisons or unbalanced/sample-size concerns; when strong control needed but you accept reduced power.**Practical note (research scientist)**- Check assumptions (Levene/Bartlett, QQ plots), consider Welch ANOVA for unequal variances, or use false-discovery-rate methods (Benjamini–Hochberg) when many comparisons and exploratory goals.
Unlock Full Question Bank
Get access to hundreds of Probability and Statistical Inference interview questions and detailed answers.