  We develop a new Bayesian modelling framework for the class of higher-order,
variable-memory Markov chains, and introduce an associated collection of
methodological tools for exact inference with discrete time series. We show
that a version of the context tree weighting algorithm can compute the prior
predictive likelihood exactly (averaged over both models and parameters), and
two related algorithms are introduced, which identify the a posteriori most
likely models and compute their exact posterior probabilities. All three
algorithms are deterministic and have linear-time complexity. A family of
variable-dimension Markov chain Monte Carlo samplers is also provided,
facilitating further exploration of the posterior. The performance of the
proposed methods in model selection, Markov order estimation and prediction is
illustrated through simulation experiments and real-world applications with
data from finance, genetics, neuroscience, and animal communication. The
associated algorithms are implemented in the R package BCT.
