Likelihood and Statistical Estimation
A binomial model calculates the probability of an alternate read count when the allele probability is known. Likelihood uses the same formula with the observed count fixed and the unknown allele probability varied.
Read distributions and calculus first. This example uses invented independent reads with no mapping bias, sequencing error, or overdispersion.
Hold the observations fixed
Section titled “Hold the observations fixed”Suppose k of n reads support an alternate allele. The binomial likelihood is proportional to p**k * (1-p)**(n-k), where p is the alternate allele probability. The binomial coefficient is constant when k and n are fixed.
Likelihood is a function of the parameter. It is not a probability distribution over that parameter. A posterior distribution would also require a prior and normalization through Bayes’ rule.
import numpy as npfrom scipy.stats import binom
alternate_reads = 7depth = 20candidates = np.array([0.1, 0.25, 0.35, 0.5, 0.8])log_likelihoods = binom.logpmf(alternate_reads, depth, candidates)for candidate, log_likelihood in zip(candidates, log_likelihoods): print(f"p={candidate:.2f}: log likelihood {log_likelihood:.4f}")p=0.10: log likelihood -6.2295p=0.25: log likelihood -2.1856p=0.35: log likelihood -1.6906p=0.50: log likelihood -2.6047p=0.80: log likelihood -11.2264The maximum likelihood estimate chooses the parameter that gives the largest likelihood for the observed data. It does not maximize the probability of the parameter being correct.
Derive the estimate
Section titled “Derive the estimate”The distinction from probability depends on what is allowed to vary. With p fixed, the binomial probabilities over every possible count sum to one. With the observed count fixed, the likelihood values across possible p values have no such requirement.
A likelihood ratio compares how well two specified parameter values explain the same observations under the same model. Taking the difference between their log likelihoods gives the logarithm of that ratio. Constants that do not depend on the parameter cancel in that comparison.
After taking natural logarithms, the parameter-dependent terms become k*ln(p) + (n-k)*ln(1-p). Differentiate with respect to p and set the derivative to zero.
k/p - (n-k)/(1-p) = 0k*(1-p) = (n-k)*pp = k/nThis interior solution applies when 0 < k < n. If no reads or all reads support the allele, the binomial maximum lies at a boundary.
estimate = alternate_reads / depthgrid = np.linspace(0.001, 0.999, 999)grid_log_likelihood = binom.logpmf(alternate_reads, depth, grid)grid_estimate = grid[np.argmax(grid_log_likelihood)]print(f"Analytic estimate: {estimate:.3f}")print(f"Grid estimate: {grid_estimate:.3f}")assert np.isclose(estimate, grid_estimate)Analytic estimate: 0.350Grid estimate: 0.350A point estimate needs uncertainty
Section titled “A point estimate needs uncertainty”Another set of reads from the same probability will usually produce a different estimate. A confidence interval describes a procedure’s coverage under repeated sampling. A realized frequentist interval does not assign a probability to the fixed parameter.
from scipy.stats import binomtest
result = binomtest(alternate_reads, depth, p=0.5)interval = result.proportion_ci(confidence_level=0.95, method="exact")print(f"Exact 95% interval: [{interval.low:.4f}, {interval.high:.4f}]")print(f"Two-sided p-value against p=0.5: {result.pvalue:.4f}")Exact 95% interval: [0.1539, 0.5922]Two-sided p-value against p=0.5: 0.2632The exact binomial interval is conservative because the observations are discrete. Its coverage can exceed the nominal level. The test asks how incompatible the observed count is with the specified null model. Its p-value is not the probability that the null is true.
Repeat the experiment
Section titled “Repeat the experiment”The repeated-sample interpretation becomes clearer when the true parameter is known in a simulation. Draw new counts from one fixed binomial probability, then construct an interval from each count. Some intervals include that fixed probability and others miss it.
rng = np.random.default_rng(42)true_probability = 0.35simulated_counts = rng.binomial(depth, true_probability, size=200)covered = 0for count in simulated_counts: simulated_interval = binomtest(int(count), depth).proportion_ci( confidence_level=0.95, method="exact" ) contains_parameter = ( simulated_interval.low <= true_probability <= simulated_interval.high ) covered += contains_parameterprint("Simulated intervals:", simulated_counts.size)print("Intervals containing the fixed probability:", covered)print(f"Observed coverage: {covered / simulated_counts.size:.3f}")Simulated intervals: 200Intervals containing the fixed probability: 198Observed coverage: 0.990The parameter stays fixed while the observations and intervals change. The observed coverage in a finite simulation fluctuates. It need not equal the nominal confidence level, and this exact interval can have higher coverage because the data are discrete.
Depth changes the likelihood curve
Section titled “Depth changes the likelihood curve”The following comparison keeps the observed fraction fixed while changing depth. Under independent binomial trials, the deeper observation gives a narrower likelihood curve.
from pathlib import Path
import matplotlib.pyplot as plt
fig, ax = plt.subplots(figsize=(7, 3.8))for count, total in [(7, 20), (70, 200)]: curve = binom.logpmf(count, total, grid) relative_likelihood = np.exp(curve - curve.max()) ax.plot(grid, relative_likelihood, label=f"{count} of {total} reads")ax.set(xlabel="Alternate allele probability", ylabel="Relative likelihood")ax.legend()fig.tight_layout()Path("outputs").mkdir(exist_ok=True)fig.savefig("outputs/allele_likelihood.png", dpi=160)plt.close(fig)
These curves have maximum height one. They are not posterior densities and need not integrate to one. Correlated reads contain less independent information than the binomial model assumes.
Sequencing depth does not replace biological replication. This example estimates a read probability within one sample. It does not estimate variation between patients.
Check your understanding
Section titled “Check your understanding”Would multiplying the likelihood by a positive constant that does not depend on p change the maximum likelihood estimate?
It would not. Every candidate value receives the same factor, so their ordering stays unchanged. This explains why the binomial coefficient can be omitted when deriving the estimate, although a probability calculation still needs it.
Further reading
Section titled “Further reading”-
MIT Introduction to Probability and Statistics
The course provides notes and problems on likelihood and confidence intervals. Use those materials to connect a likelihood curve with uncertainty across repeated samples.
-
The reference defines the probability mass, cumulative probability, and distribution parameters. These interfaces support the alternate-read likelihood calculation.
The statistical analysis section covers experimental comparisons and multiple testing. Continue with eigenvectors, SVD, and PCA.