← Anatomy of a Transit · Deep dive for chapter 6

MCMC in detail

The theory behind the pipeline's error estimate: how Markov chains draw samples, how to recognise convergence and why a wrong valley can still look convincing. First on toy distributions, then on a simulated light curve.

While you scroll, each step sets the animation accordingly. Afterwards you can keep turning the dials freely; clicking a step restores it.

1

MCMC: the theory

A random walk with a goal

Markov chain Monte Carlo draws samples from a distribution that is known only up to a constant factor. This chapter builds the method on toy distributions in two dimensions. Part 2 applies it to a light curve, the way the pipeline does.

Step 1

Why you don't simply compute the posterior

By Bayes' theorem, the posterior is the product of likelihood and prior, divided by the evidence:

\[p(\theta\,|\,D) = \frac{\mathcal{L}(D\,|\,\theta)\;p(\theta)}{p(D)},\qquad p(D) = \int \mathcal{L}(D\,|\,\theta)\,p(\theta)\,\mathrm{d}\theta\]
p(θ | D)
posterior: probability density of the parameters once the data are known
θ
theta vector of all parameters, here two: θ₁ and θ₂
D
the measured data
𝓛(D | θ)
likelihood: how probable exactly these data would be if θ were right
p(θ)
prior: what is known about θ before the measurement
p(D)
evidence: normalising constant, does not depend on θ
∫ … dθ
integral over all possible parameter values

The numerator is quick to compute for any θ, the evidence is not: it is an integral over the whole parameter space. On a grid with 100 points per axis it costs 100d model evaluations for d parameters, so 108 for four parameters. Means and error bars are such integrals too. MCMC sidesteps both: it only needs ratios p(θ′|D)/p(θ|D), in which p(D) cancels, and replaces every integral by an average over samples.

The surface on the right is such a target distribution π(θ), banana-shaped here. Four chains wander across it.

In plain wordsWe know the shape of a mountain range, but not its total mass. Instead of surveying the whole range, we send out hikers who spend more time where it is high. Where they have often been, the parameter is likely.
Step 2

A Markov chain forgets its start

A Markov chain is a sequence θ0, θ1, θ2, … in which every step depends only on the current point, not on the history:

\[P(\theta_{t+1}\,|\,\theta_t,\dots,\theta_0) = P(\theta_{t+1}\,|\,\theta_t) = T(\theta_t \to \theta_{t+1})\]
θt
theta position of the chain after t steps
P(… | …)
conditional probability: left of the bar the event, right of it what is known
T(θ → θ′)
transition rule: probability of going from θ to θ′

If the transition rule satisfies detailed balance with the target distribution π,

\[\pi(\theta)\,T(\theta\to\theta') = \pi(\theta')\,T(\theta'\to\theta),\]
π(θ)
pi target distribution, not the circle constant here; in the fit this is the posterior
θ, θ′
theta two arbitrary points in parameter space (θ′ read “theta prime”)
T(θ → θ′)
transition rule as above

then π is stationary: once the chain is distributed according to π, it stays so. If it can also reach every region and does not run in circles (ergodicity), it tends towards π from any start. Averages over the chain then approximate expectation values:

\[\frac{1}{N}\sum_{t=1}^{N} f(\theta_t) \;\xrightarrow{\;N\to\infty\;}\; \int f(\theta)\,\pi(\theta)\,\mathrm{d}\theta\]
N
number of steps (samples)
Σ
Sigma (capital) sum over all steps t = 1 … N
f(θ)
any quantity that follows from the parameters, e.g. θ₁ itself for the mean
→
tends to, as N goes to infinity
π(θ)
pi target distribution

On the right the chains start far out and still find the target. The histogram below approaches the true distribution (line).

In plain wordsThe hiker has no memory; it only looks at where it is standing right now. The rule is built so that, on average, as many hikers walk from one place to another as walk back. Then the right distribution sets itself up, no matter where you start.
Step 3

Metropolis-Hastings: propose, check, accept

The simplest rule with detailed balance: from point θ, a candidate θ′ is drawn from a proposal distribution q, here a round Gaussian of width s. It is accepted with probability

\[\alpha = \min\!\left(1,\;\frac{\pi(\theta')\,q(\theta\,|\,\theta')}{\pi(\theta)\,q(\theta'\,|\,\theta)}\right)\]
α
alpha acceptance probability of the proposal
min(1, x)
the smaller of the two values; probabilities above 1 are capped at 1
π(θ), π(θ′)
pi target distribution at the old and at the proposed point
q(θ′ | θ)
proposal distribution: how probable the proposal θ′ is when standing at θ
s
step size: width of the proposal distribution (slider)

For symmetric q the fraction reduces to π(θ′)/π(θ). Rejected means: the chain stays put and counts the old point once more. For a transit fit, ln π = −χ²/2 + const, so

\[\alpha = \min\!\left(1,\;e^{-\Delta\chi^2/2}\right),\qquad \Delta\chi^2 = \chi^2(\theta') - \chi^2(\theta)\]
α
alpha acceptance probability
e
Euler's number 2.718…
Δχ²
Delta (capital) chi squared: how much larger χ² is at the proposal than at the old point
χ²
chi squared: sum of the squared, error-normalised deviations between model and data

A step to smaller χ² is always accepted, Δχ² = 2 only with 37 %, Δχ² = 10 with 0.7 %. On the right a chain runs slowly: the dashed circle is the proposal width, green an accepted, red a rejected proposal.

In plain wordsThe hiker rolls a step in a random direction. If the step leads uphill (more likely), it takes it. If it leads downhill, it takes it only sometimes, and the steeper the drop, the less often. So it mostly stays high but also reaches the slopes, and their width is exactly the error bar.
Step 4

Step size decides efficiency

Consecutive points of a chain are correlated. How strongly is measured by the integrated autocorrelation time. From it follows how many independent samples a chain really contains:

\[\tau = 1 + 2\sum_{\ell=1}^{\infty}\rho(\ell),\qquad N_{\text{eff}} = \frac{N}{\tau}\]
τ
tau integrated autocorrelation time, in steps
ℓ
ell (script l) distance between two chain points in steps
ρ(ℓ)
rho correlation between points at distance ℓ; 1 = identical, 0 = independent
Σ
Sigma (capital) sum over all distances ℓ = 1, 2, 3, …; in practice up to about 5 τ
N
number of chain points
Neff
effective number of independent samples

Steps that are too small are almost always accepted but barely make progress: τ becomes large. Steps that are too large mostly land off target and are rejected: the chain stands still, and τ becomes large as well. The optimum lies in between. For Gaussian targets it is around 23 % acceptance rate for many parameters and around 44 % for one parameter (Roberts, Gelman & Gilks 1997).

On the right s = 0.15 is set, and the trace crawls. Drag the slider to about 1.7 and then to 6 and compare τ.

In plain wordsWith tiny steps the hiker hardly moves, even though it is almost never rejected. With giant leaps it nearly always lands in the abyss and stays put. Neff says how many truly independent points you have: a thousand steps with τ = 50 are only twenty real samples.
Step 5

The run-in phase is discarded

If a chain starts far out, its first points are still shaped by the start and not distributed according to π. This run-in phase (burn-in) is discarded, here the first 150 steps, shaded grey in the trace at the top right. It is over when all chains fluctuate in the same region without a trend. As a rule of thumb, a few tens of τ are discarded.

In plain wordsWhoever is dropped at the wrong end of the range needs a while to reach the summit. This approach is not counted, otherwise the result would lean towards the starting point.
Step 6

Slanted valleys: the stretch move

If the distribution is narrow and slanted because two parameters are strongly correlated, a round proposal fits poorly. Across the diagonal s has to be small, and then the chain barely moves along the diagonal. Goodman & Weare (2010) therefore run an ensemble of walkers. Walker k jumps along the line towards a randomly chosen other walker j:

\[Y = X_j + Z\,(X_k - X_j),\qquad g(Z) \propto \frac{1}{\sqrt{Z}}\ \text{ for } Z \in \left[\tfrac{1}{a},\,a\right]\]
Xk
current position of the walker that jumps
Xj
position of a randomly chosen other walker
Y
proposed new position
Z
stretch factor: 1 = stays, 2 = double the distance to Xj, 0.5 = half
g(Z)
probability density from which Z is drawn
∝
proportional to
a
stretch parameter, usually a = 2
\[\alpha = \min\!\left(1,\;Z^{\,d-1}\,\frac{\pi(Y)}{\pi(X_k)}\right)\]
α
alpha acceptance probability
d
number of parameters (dimension), here 2
π(Y), π(Xk)
pi target distribution at the proposal and at the old position

The factor Zd−1 restores detailed balance. Because the jumps follow from the distances between the walkers themselves, they adapt to any stretching and rotation of the distribution (affine invariance). This is the algorithm of the widely used Python package emcee. Switch to Metropolis for comparison.

In plain wordsInstead of a single hiker, a group sets off. Each one aims its next jump at a colleague. If they all lie in a long, slanted valley, they automatically jump along the valley instead of against its walls.
Step 7

Two peaks: checking convergence with R-hat

If π has two separate peaks, a chain can stay in the first one for a very long time: the way to the second leads through a valley in which almost every proposal is rejected. Gelman & Rubin (1992) therefore compare m chains with n points each:

\[W = \frac{1}{m}\sum_{j=1}^{m} s_j^2,\qquad B = \frac{n}{m-1}\sum_{j=1}^{m}\big(\bar\theta_j - \bar\theta\big)^2,\qquad \hat{R} = \sqrt{\frac{\frac{n-1}{n}W + \frac{1}{n}B}{W}}\]
m
number of chains
n
points per chain after the run-in phase
sj²
variance within chain j
W
mean variance within the chains (within)
θ̄j
theta bar: mean of chain j
θ̄
theta bar: mean over all chains
B
scatter between the chain means (between)
R̂
R-hat: 1 = the chains agree, clearly above = they have seen different things

Depending on how strict you are, values below 1.01 or below 1.1 count as converged. But R̂ only checks whether the chains agree, not whether they have found everything. If all start on the same peak, as set now, R̂ ≈ 1, and the second peak is still missing from the histogram. Set the start to “spread”: then chains land on both peaks, and R̂ raises the alarm.

In plain wordsFour hikers who set off together and agree at the end do not prove that there is no second mountain. Only when they start in different places does it show that they are standing on different summits. This trap reappears at egress in part 2.
Toy distributions, no measured data
\[\alpha = \min\!\left(1,\frac{\pi(\theta')}{\pi(\theta)}\right)\]
What do the symbols mean?
α
alpha acceptance probability of the proposal
π(θ)
pi target distribution at the current point θ (theta)
π(θ′)
pi target distribution at the proposed point θ′
τ
tau autocorrelation time (in the table)
Neff
effective number of independent samples
R̂
R-hat, Gelman-Rubin convergence measure

2

MCMC on a transit

Walkers in the χ² landscape of a light curve

Now the same method runs on a simulated light curve, with the pipeline's settings. The free parameters are the mid-time Tc and the radius ratio Rp/R★; everything else is held fixed. The pipeline starts at the best fit, accounts for red noise via β and reports the median and the 16th/84th percentile.

Step 1

The likelihood of a light curve

For Gaussian, independent noise the log-likelihood is a sum over all data points. Red noise enters the errors through the β factor from chapter 5 of the main page:

\[\ln\mathcal{L}(\theta) = -\frac{1}{2}\sum_{i=1}^{N}\frac{\big(f_i - m(t_i;\theta)\big)^2}{(\beta\,\sigma_i)^2} + \text{const} = -\frac{\chi^2(\theta)}{2\beta^2} + \text{const}\]
ln 𝓛(θ)
natural logarithm of the likelihood: how probable the measured data are for the parameters θ
θ
theta the free parameters, here (Tc, k)
Tc
mid-transit time; shown in the plot as offset ΔTc from the prediction in minutes
k
radius ratio Rp/R★ (planet radius divided by stellar radius)
N
number of data points
fi
measured, normalised flux of point i
m(ti; θ)
model flux at time ti for the parameters θ
σi
sigma error of point i
β
beta red-noise factor (chapter 5 of the main page); 1 = purely white noise
χ²(θ)
chi squared: sum of the squared deviations, normalised to σi
Σ
Sigma (capital) sum over all data points
const
constant that does not depend on θ and drops out in the MCMC

Held fixed are the orbit (a/R★, b, P) and the limb darkening u₁, u₂ from tables. The priors are flat here: ΔTc within ±45 min around the prediction, k between 0.03 and 0.2. The landscape is laid out at the top left. The shaded areas are the 1σ, 2σ and 3σ regions of a two-dimensional Gaussian (Δχ²/β² = 2.3 / 6.2 / 11.8).

In plain wordsFor every pair of mid-time and planet size, the model computes a light curve and measures how far it is from the data points. Where this distance is small, there is a valley. It is the mountain range from part 1, just turned upside down: high probability means small χ². The MCMC does not only look for the lowest point, it measures how wide the valley is.
Step 2

First find the best fit, then start there

The walkers do not start just anywhere. First an optimiser looks for the minimum of χ², from five starting values for Tc spread over ±30 min around the prediction. The start with the smallest χ² wins. The walkers are released in a small cloud around it. That saves most of the run-in phase and protects against side valleys, as long as one of the five starts lands in the right valley.

At the top left the five optimisers run; at the bottom right is the profile: for each mid-time, the smallest χ² reachable with any k.

\[\Delta\chi^2_{\text{prof}}(T_c) = \min_{k}\,\chi^2(T_c,k) - \chi^2_{\min}\]
Δχ²prof(Tc)
Delta (capital) chi squared in the profile: how much worse the best fit at fixed mid-time Tc is than the overall best fit
mink
minimum over all values of k with Tc held fixed
χ²min
chi squared of the overall best fit
Tc, k
mid-transit time and radius ratio Rp/R★
In plain wordsFirst look roughly for the lowest point, from five different places, then drop the hikers right there. The profile is the cross-section through the landscape along the time axis.
Step 3

Without a good start: run-in phase

For comparison, the sixteen walkers here deliberately start off target, at ΔTc = +9 min and k = 0.118. Each walker makes one stretch move from part 1 per step. With ln π = −χ²/(2β²) this becomes:

\[\alpha = \min\!\left(1,\;Z\,e^{-\Delta\chi^2/(2\beta^2)}\right)\]
α
alpha acceptance probability of the jump
Z
stretch factor of the stretch move, between 0.5 and 2; with two parameters it appears with exponent d − 1 = 1
Δχ²
Delta (capital) chi squared: χ² at the proposal minus χ² at the old position
β
beta red-noise factor

The first 80 steps count as the run-in phase and do not enter the result.

In plain wordsWithout a good start, the hikers first have to walk down into the valley. That takes time, and this approach has to be thrown away.
Step 4

From samples to error bars

After the run-in phase, the positions of all walkers are samples from the posterior. The pipeline summarises them with percentiles:

\[T_c = q_{50}\,{}^{+(q_{84}-q_{50})}_{-(q_{50}-q_{16})}\]
q50
median: 50 % of the samples lie below it
q16, q84
16th and 84th percentile; 68 % of the samples lie between them, as for ±1σ of a Gaussian
Tc
mid-transit time

For skewed distributions the two sides have different lengths, which is why + and − are reported separately. At the bottom, fifteen randomly drawn models lie over the data.

In plain wordsYou sort all collected mid-times. The middle one is the result. Between the 16th and the 84th percent of the list lie two thirds of all values: that is the error bar, and it may be longer on the upper side than on the lower.
Step 5

Red noise: β makes the errors honest

Correlated noise contains less independent information than the number of points suggests. That is why all σi are multiplied by β. Because ln 𝓛 is thereby divided by β², the posterior becomes wider by exactly the factor β in every direction:

\[\sigma_{T_c}(\beta) = \beta\cdot\sigma_{T_c}(\beta = 1)\]
σTc
sigma error of the mid-transit time
β
beta red-noise factor

The settings are β = 1.22 and 9.4 ppt per point, as for HAT-P-33b. The simulation has only 180 points instead of 1077, so its error is larger than for the real measurement.

Measurement: HAT-P-33b, 1077 frames of 20 s, 9.4 ppt per frame, β = 1.22: Tc ± 2.2 min.

In plain wordsWhen the noise comes in waves, ten consecutive points are not ten times as good as one. β accounts for this by stretching every point's error bar. The valley gets wider and the mid-time error larger, but it is honest.
Step 6

The trap: a side valley at egress

Now the ingress is missing, because the observation only begins at mid-transit. In addition, shortly after egress a thin cloud pushes the flux down by 10 ppt for 10 minutes. This gives the profile a second valley at ΔTc ≈ +25 min: a model with a later egress explains the cloud as the remainder of the transit. The walkers were released in this side valley, just as happens when the optimiser gets stuck there.

The result looks flawless: narrow histogram, normal acceptance rate, R̂ ≈ 1. Yet it is off by about 25 min. No walker crosses the ridge between the valleys, because every proposal there is rejected. And R̂ only compares walkers that all stand in the same valley. This is exactly the possibility the ExoClock reviewer pointed out: a local minimum at egress shifts Tc and with it the O−C.

In plain wordsThe hikers were dropped in the wrong valley. Because they agree and measure the valley neatly, everything looks right. Only a look at the whole profile or at the light curve at egress shows that there is a deeper valley next door.
Step 7

Remedies: search widely, check the profile

With the pipeline's five starting values, the optimisers from −30, −15 and 0 min find the right valley here, while those from +15 and +30 min get stuck in the side valley. The smaller χ² decides. That protects you as long as the right valley is also the deepest. With “New data” you can try out how often the noise makes the side valley deeper. Three additional checks cost little:

Profile scan: compute Δχ²prof(Tc) over the whole window (bottom right). A second valley with Δχ²/β² below about 10 is a warning sign.

Widely spread walkers: if you start them spread over ±30 min, some land in the side valley. The histogram gets two humps, and R̂ rises far above 1.1.

Mask the egress: repeat the fit once without the disturbed minutes. If Tc changes by more than its error, the result is not robust.

Measurements: HAT-P-33b ran with 15 chains and reached R̂ = 1.003. For KPS-1b the points scattered at egress, and the ExoClock reviewer suspects exactly such a local minimum in the fit. There, the profile scan is the first test.

In plain wordsSearch from several places, walk the whole terrain and check whether the light curve at egress is clean. An O−C that changes as soon as you leave out ten minutes of data is not a reliable O−C.
Simulated data · orbit fixed
\[\ln\mathcal{L} = -\frac{\chi^2}{2\beta^2},\quad \alpha = \min\!\left(1, Z\,e^{-\Delta\chi^2/2\beta^2}\right)\]
What do the symbols mean?
ln 𝓛
logarithm of the likelihood (without constant)
χ²
chi squared: sum of the squared, error-normalised deviations
β
beta red-noise factor
α
alpha acceptance probability of a jump
Z
stretch factor of the stretch move
Δχ²
Delta (capital) chi squared: change of χ² caused by the jump
R̂
R-hat, Gelman-Rubin convergence measure (each walker counted as its own chain)

Wir bedanken uns für die Unterstützung bei
Logo Faktor Zehn
Logo Gemeinde Michelbach
Logo W.E.B.
Logo Zieritz + Partner