In the consecutive-clearance inspection model, a run of consecutive good items is required to leave full inspection. With , , its Markov chain has transitions , for , and , . Thus every defect in the clearance phase resets the count, rather than preserving the cumulative total.
Writing , the stationary distribution is
To prove this, balance at gives , while balance at gives . Summing the geometric series and normalizing gives ; balance at zero follows as well. The inspected fraction is . The fraction of all production that is both defective and uninspected is ; the fraction among defective items alone is . All these long-run limits follow from the Markov chain ergodic theorem and the independent inspection coins. The distinction from cumulative clearance matters already at .
For an irreducible Markov chain on a countable state space with positive recurrence and stationary distribution , the displayed almost sure convergence holds from every initial state whenever . In particular, the empirical fraction of visits to converges to . No aperiodicity is needed. Regeneration at successive returns to a state reduces the result to the strong law of large numbers for independent excursion lengths and rewards. This extends the finite-state Markov chain ergodic theorem.
Irreducible Markov chain Created 2026-09-24 Updated 2026-10-25
For a finite, time-homogeneous Discrete-time Markov chain with row-stochastic transition matrix , irreducibility means
Equivalently, all states form one communicating class. The step count may depend on ; irreducibility does not require every one-step transition probability to be positive. Drawing an arrow whenever makes the condition exactly that of a strongly connected directed graph. It is a property of the entire chosen state space, independent of the initial probability distribution.
Irreducibility describes where the Markov chain can travel; aperiodicity describes the possible lengths of return paths. For example, restricting the second diagram in communicating class to its closed pair gives
where is the identity matrix. This Markov chain is irreducible, but each state's period of a state in a Markov chain is two. Every destination is reachable, yet a given destination cannot be reached at every sufficiently large step count. Starting at produces alternating one-time probability distributions. See Hao Wu's MIT lecture 2, irreducibility and periods for the definitions.
Adding a holding probability of a Markov chain at each state, with , gives
The arrows between the two states remain, so the Markov chain remains irreducible. A positive one-step return makes it an aperiodic Markov chain. At , both rows are and for every : the initial state is forgotten after one step. At , however, both states become absorbing states, giving two separate communicating classes and losing irreducibility.
For a finite Markov chain, irreducibility guarantees a unique stationary distribution with positive weight at every state. Adding aperiodicity guarantees convergence for every initial probability distribution; see Hao Wu's MIT lecture 4, convergence theorem. The Markov chain ergodic theorem gives convergence of empirical visit frequencies even for an irreducible periodic Markov chain. These results explain why checking connectivity is a useful first step before studying equilibrium. Conversely, any absorbing state prevents irreducibility if there is another state: it cannot reach that state. The one-state Markov chain is the exception.
Let . The residue contains all information needed for the next residue, so is a four-state Markov chain. In the order , its transition matrix is
For example, from residue , a head returns to and a tail goes to ; from either odd residue the tail leaves that residue unchanged.
The stationary distribution solves . Its equations give , , and . Normalization therefore gives
The Markov chain is irreducible: the positive-probability transitions around reach all states. It is also aperiodic because it has self-loops. The finite irreducible Markov chain ergodic theorem says that empirical state frequencies converge almost surely to the unique stationary distribution, irrespective of the initial state. Hence
Aperiodicity also permits convergence of the one-time state probabilities, although it is not needed for this empirical-frequency theorem.
During phase A every item is inspected, while during phase B inspection has probability , independently of item quality. The long-run inspected fraction is therefore the stationary reward
This can be justified by the Markov chain ergodic theorem for state occupation and the strong law for the independent inspection coins (or the corresponding bounded martingale differences).
For the printed cumulative count this gives
It does not equal the claimed expression in general. For instance , , gives , whereas the printed expression gives .
For the consecutive-clearance rule, substituting instead gives
Thus the claimed formula is valid for consecutive clearance, and false for the literal cumulative count. For the limiting inspected fraction is in either model; for it is 1 because phase A never clears.
For an irreducible positive recurrent Markov chain, the Markov chain ergodic theorem gives a unique stationary distribution , with almost-sure long-run occupation fraction in state . More generally, time averages of an integrable state reward converge to its stationary mean. If the chain is also aperiodic, then for every initial state ; the aperiodicity assumption is needed for this last distributional conclusion.
For either transition rule in part (i), permits progression through the phase-A states and a return from phase B to zero. Both chains are finite and irreducible, hence positive recurrent. State has a positive self-loop, so both are aperiodic. Therefore
using respectively the cumulative or consecutive stationary distribution given in part (i), for every starting distribution.
The excluded endpoint cases are simple: at , phase B is eventually reached and then absorbing, so the limiting law is the point mass at . At , the cumulative rule traps the chain at its current phase-A count (or eventually at zero if started in phase B), so the limit can depend on the initial count; under the consecutive rule zero is eventually absorbing. Irreducibility and the preceding stationary formulas must not be asserted unchanged at these endpoints.
Choose distinct coordinates uniformly for the starting ones; each element of then has starting probability . At each iteration choose one current one and one current zero uniformly and swap them. This implements the normalized proposal distribution from (c)(i), remains in , and needs just one precomputed matrix inverse.
mymcmc <- function(x, k, sigma) {
  n <- length(x)
  stopifnot(length(k) == 1L, is.finite(k), k == floor(k),
            k > 0L, k < n, is.matrix(sigma),
            all(dim(sigma) == c(n, n)))
  sigma_inv <- invsigma(sigma)
  u <- integer(n)
  u[sample.int(n, k, replace = FALSE)] <- 1L
  draws <- matrix(0, 100L, n)
  for (iteration in seq_len(100L)) {
    ones <- which(u == 1L)
    zeros <- which(u == 0L)
    i <- ones[sample.int(length(ones), 1L)]
    j <- zeros[sample.int(length(zeros), 1L)]
    v <- u
    v[i] <- 0L
    v[j] <- 1L
    alpha <- mylogapp(x, u, v, sigma_inv)
    if (runif(1L) < alpha) u <- v
    draws[iteration, ] <- u
  }
  colMeans(draws)
}
Sampling positions with sample.int and then indexing into ones or zeros also works when or . In R, a call such as sample(ones, 1) would incorrectly sample from 1:ones when ones is a single numeric value greater than one.
The code records the state after each of exactly transitions, including repetitions after rejection. Its answer is the vector Monte Carlo estimator
This estimates the posterior mean coordinate by coordinate; because each coordinate is binary, its entries estimate the posterior probabilities of inclusion. Every stored state has coordinate sum , so the estimated means lie in and sum to .
For neighbouring states, the symmetry of the proposal and the Metropolis–Hastings acceptance probability give detailed balance:
Thus the posterior distribution is a stationary distribution. Any two states in can be connected by moving the ones that occupy the wrong positions, and the multivariate normal distribution gives strictly positive target masses. The resulting Markov chain is therefore an irreducible Markov chain, and its long-run state averages estimate the posterior mean.
The requested iterations are a finite approximation, without a convergence guarantee or discarded burn-in. A randomly chosen starting subset has the prior distribution, rather than generally the posterior distribution. No aperiodicity assumption is needed for the finite-state Markov chain ergodic theorem for averages; indeed a uniform two-state target with gives a period-two alternating chain. This does not invalidate either the code or the state-average estimator.
Stationary distribution Created 2026-09-24 Updated 2026-10-14
A stationary distribution is a probability distribution preserved by a Markov chain's evolution. For a Discrete-time Markov chain in the row convention,
Thus is a normalized nonnegative left eigenvector of the transition matrix for eigenvalue one. Starting with distributed as makes every have that same probability distribution. For a time-homogeneous Markov chain, the path probabilities are also unchanged by shifting all observation times together: the process has strict stationarity. This does not mean its individual paths are constant. See Hao Wu's MIT lecture 2, stationary distributions.
For the sunny/rainy transition matrix, write . The sunny component of gives , so and
Moreover,
These equal stationary flows verify detailed balance and show that the Markov chain is reversible. The diagonal detailed balance equations hold automatically. Only of the stationary days are rainy, but of the days following a rainy day are rainy: stationarity permits dependence.
A finite Markov chain that is an irreducible Markov chain has a unique stationary distribution. If it is also an aperiodic Markov chain, for every initial probability distribution. The sunny/rainy example satisfies both conditions: both directions are possible and each state has a positive holding probability of a Markov chain. See Hao Wu's MIT lecture 4, convergence theorem. For an infinite state space, the additional positive recurrence hypothesis in the countable-state Markov chain convergence theorem matters.
Existence of a stationary distribution alone does not give this convergence. Consider the deterministic two-cycle
Here , but starting in the first state gives alternating probability distributions . Its period of a state in a Markov chain is two. The running fraction of visits to either state nevertheless tends to , illustrating the Markov chain ergodic theorem. Starting with instead keeps the one-time probability distributions stationary even though every path alternates.
Figure 1.
A deterministic two-cycle has a stationary law, but its one-time probabilities oscillate while its time-averaged visits converge.
Details.
A two-phase inspection model alternates between inspecting every item and inspecting each item with probability , where . Suppose item defects are independent with probability . The first phase ends after good items have been accumulated, while the second ends upon detecting a defect. With state equal to the cumulative number of good items found during the current full-inspection phase, the Markov chain has transitions , , , .
Its stationary distribution is for and . Indeed, balance gives equal mass to every phase-A state and ; normalization fixes the common mass. The finite chain is irreducible and aperiodic, so the Markov chain ergodic theorem identifies these probabilities with long-run occupation fractions. The long-run inspected fraction is . The fraction of all production consisting of undetected defective items is .
An important modeling choice is whether defects during full inspection preserve accumulated good items or reset the count. Resetting produces the distinct consecutive-clearance inspection model and changes the long-run fractions.