Abstract
Abstract:
Bayesian methods have become increasingly popular in the past two decades. With the constant rise of computational power, even very complex models can be estimated on virtually any modern computer. Moreover, interest has shifted from conditional mean models to probabilistic distributional models capturing location, scale, shape and other aspects of a response distribution, where covariate effects can have flexible forms, for example, linear, non-linear, spatial or random effects. This tutorial article discusses how to select models in the Bayesian distributional regression setting, how to monitor convergence of the Markov chains and how to use simulation-based inference also for quantities derived from the original model parametrization. We exemplify the workflow using daily weather data on (a) temperatures on Germany's highest mountain and (b) extreme values of precipitation for the whole of Germany.
Keywords
Introduction
While it is well known that the distribution of any quantity of interest is not well characterized by the mean alone, this is still frequently ignored in regression analyses since most common model specifications (linear models, generalized linear models [GLMs], generalized additive models [GAMs], etc.) focus on relating the mean of the response variable to a set of explanatory variables. While such models have the advantage of being easy to estimate and to interpret, it is in many situations very likely that other properties of the response distribution (such as variance or skewness) also depend on covariates. Ignoring this fact will then induce a sort of model misspecification which will often imply that conclusions drawn from the model estimates are misleading. In addition, in many applications, the analyst may not only be interested in effects on the mean of the response but rather on additional features of the response distribution. This is, for example, the case if one is interested in quantifying risks or extreme observations rather than the average behaviour of the response.
One common approach to overcome the obsession with means in regression analyses are quantile regression methods (see Koenker, 2005 for a detailled introduction) which are also discussed in Waldmann (2018), another contribution to this special issue. While conditional quantiles provide a characterization of local characteristics of the response distribution (indexed by the quantile level), we will focus on distributional regression models that provide a complete probabilistic characterization of the response distribution in one joint model. These models will rely on the assumption of a specific distributional type for the response, but allow potentially all parameters of this distribution to depend on covariates. Such models are also considered under the name of generalized additive models for location, scale and shape (GAMLSS; see Rigby and Stasinopoulos, 2005 and Stasinopoiulos et al., 2018) which is also contained in this special issue. We prefer the term distributional regression since in many applications, none of the parameters characterizing a distribution will be related to the location or the scale, but rather all parameters are shape parameters determining the shape of the density for the distribution of interest. Furthermore, we will focus on Bayesian inference based on Markov chain Monte Carlo (MCMC) simulations in this tutorial. While we will not include a general introduction to Bayesian inference based on MCMC, we will discuss some of the challenges associated with Bayesian treatments of distributional regression. A general introduction to Bayesian inference and MCMC can, for example, be found in Held and Sabanés Bové (2013). We also assume some familiarity with modelling ideas of GAMs, see, for example Wood (2006) or Fahrmeir et al. (2013b) for introductions.
Simulated data example, shown are the observations simulated from a
heteroscedastic normal model (derived from the formula in the right panel),
together with the estimated
%,
%,
%,
% and
% quantiles of a
homoscedastic normal model, left panel, and a heteroscedastic location-scale
normal model
Simulated data example, shown are the observations simulated from a
heteroscedastic normal model (derived from the formula in the right panel),
together with the estimated
%,
%,
%,
% and
% quantiles of a
homoscedastic normal model, left panel, and a heteroscedastic location-scale
normal model
The main idea of distributional regression is illustrated in Figure 1 for simulated data from a normal
distribution where both the mean the variance are related to a continuous covariate
While in the particular case of a normal location-scale model with only one single
covariate, as in Figure 1,
it is still fairly easy to understand the structure and implications of a
distributional regression specification, this typically becomes more difficult in
more complex specifications with either a more flexible specification of the
regression predictor or the response distribution. This tutorial, therefore, aims at
providing more insight for practitioners into the workflow of building
distributional regression models illustrated alongside meteorological examples of
daily temperature observations of the Zugspitze, the highest mountain in Germany,
and on extreme values of daily precipitation sums over the whole area of Germany.
For inference, we will follow a Bayesian approach based on MCMC which is
particularly attractive in distributional regression; since the inferential
framework provides valid credible intervals for estimators in situations where
confidence intervals for corresponding maximum likelihood estimators based on
asymptotic properties fail and also enables immediate inference for quantities
derived from the original model parameterization. Since MCMC approaches imply a
number of additional challenges for applied researchers (in particular monitoring
mixing and convergence of Markov chains), we will also provide step-by-step guidance
on those aspects of the analysis. Model fitting is carried out using the
The remainder of this article is structured as follows: The data used to illustrate
the modelling workflow are presented in Section 2. In Section 3, the models and
model terms supported by the distributional regression framework are briefly
introduced. Section 4 gives an overview on monitoring convergence of the Markov
chains, while tools for model selection are discussed in Section 5. Section 6
discusses the implementation in the R-package
As illustrative examples, we use two datasets of German daily weather observations
provided by the German
Meteorological Service (2017) (Deutscher Wetterdienst, DWD), which are
freely available (the datasets utilized in this tutorial are provided in a
pre-compiled version in the online supplemental materials). Our data are a
collection of over
Daily temperature at the Zugspitze
The main interest in the first example is to evaluate trends in temperatures not only in terms of the average temperature but also in terms of changes of the general distributional shape. For estimating time trends using meteorological data, especially temperature, it is important to ensure that the data produced by the weather station is homogenized. For example, if a station is moved to another location with higher altitude, this can result in a dramatic drop of measured temperatures. Similarly, exchanging physical sensors can shift meteorological observations which needs to be accounted for, prior to analysing the data. Since the daily temperature time series of the Zugspitze is one of the longest homogenized series in Germany, it is especially suited for estimating long term-time trends.
In the top row of Figure
2, a histogram of the daily temperature observations together with a
plot versus the day of year is shown. The histogram shows that the distribution
is not symmetric but slightly left-skewed towards lower temperatures, which had
a minimum of
Daily temperature data of the Zugspitze. The upper-left panel shows
a histogram together with a kernel density estimate of the temperature
observations. The upper-right panel shows the raw time series for each
year together with empirical mean and quantiles computed for each day of
the year. The lower panel presents the raw time series, including
empirical running mean and quantiles computed using a 20-year moving
window
Daily temperature data of the Zugspitze. The upper-left panel shows a histogram together with a kernel density estimate of the temperature observations. The upper-right panel shows the raw time series for each year together with empirical mean and quantiles computed for each day of the year. The lower panel presents the raw time series, including empirical running mean and quantiles computed using a 20-year moving window
In the bottom row of Figure
2, the full temperature time series is shown. Compared to the overall
average temperature of
In practice, (temperature) climatology models are oftentimes used for improving probabilistic weather forecasts, for example, by statistical downscaling or as a baseline model for verification. Therefore, it is important to capture the full information of the distribution such that correct inference can be made for all quantities of interest. Therefore, as already suggested from the descriptive data analysis in Figure 2, next to autocorrelation in the observations, subsequent models need to account for complex seasonal patterns, possibly varying over time, as well as varying amounts of fluctuation over season and observation time. Due to the skewness of the response data, a simple Gaussian model is most likely not capable to model all features of the data. Therefore, we exemplify a complex distributional modelling task using three different distributions for daily temperature observations.
Extreme climatological events play an important role in environmental risk
assessment and policymaking. For example, extreme precipitation events can lead
to massive flooding and thus cause considerable damage or even fatal accidents.
Therefore, the analysis of extreme events has become more and more important in
recent years, and a special focus in a modelling context is to capture the tails
of the response distribution as accurately as possible. In a distributional
regression setting, this oftentimes means that modelling the full response
distribution and calculating, for example, the
In this example, we are interested in extreme
The spatial distribution of meteorological stations in the DWD database is shown
in the left panel in Figure
3.
Distribution of available meteorological stations (left
panel) fitted generalized Pareto distribution to
Similarly to the first example, to account for possible time trends in extreme
precipitation, it is necessary to use homogenized long-term time series.
Therefore, we only used observations of meteorological stations with the highest
quality, as reported by the quality flags from the DWD. Additionally, we only
analysed data from stations that did not change in altitude more than
In this example, note that for example the computation of the mean
Most common regression specifications relate the conditional expectation of the
response variable of interest
Distributional regression models overcome this limitation and allow for regression
effects on potentially all parameters of the response distribution (Rigby and Stasinopoulos,
2005). More specifically, distributional regression assumes that the
conditional distribution is of a specific type (e.g., normal, gamma, etc.) with
For relating the different distributional parameters
To ensure regularization of the functions
In analogy to GLMs (Nelder and
Wedderburn, 1972), the predictors are then linked to the distributional
parameters via known monotonic and twice differentiable response functions
Commonly used effect types in distributional regression models
Commonly used effect types in distributional regression models
In our analysis of the temperature data of the Zugspitze presented in Section 2,
the normal distribution
We, therefore, work with two alternative, more flexible distributions with
distinguished parameters for skewness and kurtosis. More precisely, we consider
the Box–Cox t distribution
The skewness parameter Temperature data are temporally correlated, and we therefore
include daily temperature differences Due to seasonal variation over the year, we include a cyclic
trend component based on the day of the year, in To account for a potential long-term trend in temperatures, we
include an overall time trend based on the years from
To allow for time variation in the seasonal component, we
furthermore include an interaction between day of the year and year
in
Model for extreme precipitation
For modelling extreme values of precipitation, we rely on the GP distribution
Function Similarly to the temperature model, effects In addition, to account for spatial variation, we include a
spatially correlated effect Moreover, spatial variation might be pronounced for the
seasonal trend; therefore, a spatially varying seasonal effect
Estimation
Estimation of the different model specifications will be based on MCMC
simulations, using iteratively weighted least squares (IWLS) proposals. Since
distributional regression models are rather complex, including a quite high
number of parameters, finding good starting values is important. Therefore, a
backfitting algorithm for finding posterior mode estimates is commonly applied
before running the MCMC simulation, which is also the default option in the
Obviously, Bayesian distributional regression involves a number of distinct
choices and challenges an analyst is faced with. These include: the choice of a suitable class of potential response
distributions, the determination of candidate regression predictors for the
different distributional parameters and the monitoring and evaluation of Bayesian, simulation-based
inference.
In our application on
precipitation, the response distribution was chosen to be a GP based on the
theoretical argument that after applying the peak over threshold approach the GP
distribution is the limiting distribution for such data. In general and also for
the temperature data, however, there will be a multitude of candidate
distributions to choose from such that methods for comparing and evaluating the
fit of rival specifications are warranted. Similarly, we are interested in
studying spatio-temporal dynamics of temperature and precipitation in our
applications, and this leads to the corresponding predictor specifications, but
in typical applications the analyst will have to decide upon a subset of
covariates out of larger candidate set. While this is of course common to any
regression analysis, the fact that distributional regression relies on multiple
regression predictors even increases the complexity of the task.
In the following, we will provide guidance on these various aspects of performing an analysis based on Bayesian distributional regression.
Monitoring and convergence of Markov chains
Trace- and ACF plots generated from the Gaussian daily temperature
model. The samples of one smoothing variance of model term
of the
parameter are shown
in the first column together with a smooth trend line. The second column
shows the corresponding empirical ACF, while the third column visualizes the
maximum ACF values over all model parameters. The upper row illustrates the
behaviour of the Markov chain using poor starting values. The second row
shows the effect of using good starting values, for example, generated by a
backfitting algorithm. The bottom row shows samples generated from 8
parallel Markov chains with
samples, a burn in
phase of
and thinning
of
for each
chain
Trace- and ACF plots generated from the Gaussian daily temperature
model. The samples of one smoothing variance of model term
of the
parameter are shown
in the first column together with a smooth trend line. The second column
shows the corresponding empirical ACF, while the third column visualizes the
maximum ACF values over all model parameters. The upper row illustrates the
behaviour of the Markov chain using poor starting values. The second row
shows the effect of using good starting values, for example, generated by a
backfitting algorithm. The bottom row shows samples generated from 8
parallel Markov chains with
samples, a burn in
phase of
and thinning
of
for each
chain
Let us start with the situation that a fixed model specification is given and we are estimating the model based on MCMC simulations. In this case, it is important to monitor the mixing and convergence behaviour of the underlying Markov chain to avoid that spurious results are obtained. All methods discussed in the following rely on inspecting the posterior samples either based on graphical visualization or certain summary statistics. In the following, we assume some familiarity with the principles of Bayesian inference based on MCMC as provided, for example in Green (2001).
The necessity to monitor the convergence of the Markov chain arises from the fact that MCMC simulations are not optimizing a certain estimation criterion (such as least squares or the log-likelihood) where convergence implies that the estimate of interest converges to the optimal value, but rather we are interested in achieving convergence to the posterior distribution. This unfortunately implies that convergence is way harder to determine in practice, although it is guaranteed from a theoretical perspective under mild regularity conditions. Furthermore, since we are generating a Markov chain, the samples will necessarily exhibit some degree of autocorrelation that has to be taken into account. To illustrate different aspects of monitoring Markov chains in MCMC, Figure 4 contains sampling paths as well as autocorrelation functions (ACFs) for three different scenarios of the estimation process of the daily temperature model of the Zugspitze.
The first row illustrates the behaviour of the Markov chain when starting from a
badly chosen starting value. In this case, it takes roughly 300 iterations until the
Markov chain has reached the part of the parameter space that is supported by high
values of the posterior distribution. This phase is known as the burn in period of
MCMC simulations and should be discarded so that results are not impaired by the
convergence towards the posterior. Unfortunately, even after the burn in period, the
mixing of the Markov chain shown in the first row is far from satisfactory and shows
insufficient mixing as demonstrated by the extremely high autocorrelations. To
improve mixing and reduce autocorrelations, a common strategy is to apply a thinning
strategy where, for example, only every 10th sample is retained. An appropriate
thinning value can often be inferred from the autocorrelation function, but in case
of the first row in Figure
4, this would result in a really large value such that the MCMC sampler would
have to run for a huge number of iterations to obtain a post-thinning sample of
appropriate size. Hence, although one may obtain quasi-independent samples by
thinning, it is typically more efficient to determine a sample strategy with only
moderate dependence already by construction. For example, a highly efficient
sampling scheme is to construct approximate full conditionals based on a
second-order Taylor series expansion of the log-posterior centred at the last state
(see, e.g., Fahrmeir et al.,
2004; Umlauf et al.,
2017). Moreover, finding good starting values for the MCMC simulations is
especially important for smoothing variances of complex model terms, that is, for
the spatially varying seasonal effect
The Markov chain in the second row starts from better initial guesses, and therefore only shows a smaller trend towards the posterior and already considerably reduced autocorrelation. Still, the samples cannot yet be considered as being independent such that an appropriate amount of thinning should be applied. The third row contains samples from eight independent chains after removing a burn in period and after thinning the Markov chain to make the samples approximately independent. The Markov chains do not show any indication of a trend, autocorrelations are very low and repeated runs of the Markov chain produce a similar behaviour. In summary, graphical inspection of the sampling paths and the autocorrelation function provide good guidance on convergence and mixing of the Markov chains with respect to the following aspects: determination of the burn in period, thinning of the Markov chain to make the samples independent and mixing of the Markov chain by comparing different chains.
The major drawback of graphical approaches is that for complex models with hundreds
or even thousands of parameters, it is hard to monitor all parameters
simultaneously. In this case, it can be useful to rely on convergence diagnostics
that can be computed from multiple Markov chains produced for the same model (as
implemented in the Gelman and Rubin's convergence diagnostic (Gelman and Rubin, 1992; Brooks and Gelman,
1998), Geweke's convergence diagnostic (Geweke, 1992)
and Heidelberger and Welch's convergence diagnostic (Heidelberger and
Welch, 1981, 1983).
The Gelman and Rubin's convergence diagnostic is a general approach for
monitoring convergence of parallel MCMC chains. Using different starting values,
convergence is indicated if all chains approach stationarity within the first half
of the samples which is tested by calculating within-chain and between-chain
variances. For each variable, if MCMC chains have converged, the value of the
diagnostic is approximately
Similarly, Geweke's diagnostic is testing for convergence based on differences of the
mean of the first and last part of the MCMC chains. The test statistic is
asymptotically normal distributed, that is, if MCMC chains have converged,
differences should be small when quantifying them using a standard Z-score. If the
Z-score shows a lack of convergence, it is useful to successively discard more and
more samples until the chain is halved in order to identify the iteration from which
convergence is achieved. Again, convergence of the MCMC chains of the final
Heidelberger and Welch's run length control test is computed by successively
discarding samples until either the test is passed or half of the chain has been
discarded. In practice, the diagnostic can be used to automatically define an
accurate burn in phase for the MCMC chains. When computing, the test for the MCMC
chains of the final
We now turn our attention to the actual determination of suitable models for an
empirical analysis. A common way can be to proceed along the following steps:
Randomized quantile residuals
Randomized quantile residuals (Dunn and Smyth, 1996) are based on the probability integral
transform (PIT) that indicates that for a continuous random variable
Randomized quantile residuals of the daily temperature models, The
top row shows histograms of posterior mean quantile residuals together
with a kernel density estimate; the bottom row shows the resulting
quantiles versus the theoretical quantiles of the standard normal
distribution. The small black dots represent the posterior mean
quantiles of over all posterior samples, the blue-dashed lines represent
the corresponding
credible bands
Randomized quantile residuals of the daily temperature models, The
top row shows histograms of posterior mean quantile residuals together
with a kernel density estimate; the bottom row shows the resulting
quantiles versus the theoretical quantiles of the standard normal
distribution. The small black dots represent the posterior mean
quantiles of over all posterior samples, the blue-dashed lines represent
the corresponding
credible bands
Quantile residuals and the PIT mostly provide a basic check whether a candidate model provides a reasonably flexible description of the observed data, but they are not well suited to discriminate between rival model specifications in terms of covariate effects. The latter can, for example, be achieved by Bayesian analogues to frequentist information criteria such as Akaike's information criterion (AIC). The most popular approaches are the deviance information criterion (DIC; Spiegelhalter et al., 2002) and the widely applicable information criterion (WAIC; Watanabe, 2010). Both can be easily determined based on the samples for the parameters of a Bayesian model specification and can be interpreted in complete analogy to the AIC (i.e., smaller values indicate a better fit). However, since they are estimated from the data, there is inherent sampling variability such that small differences in the information criteria should not be over-interpreted. Table 2 reports the DIC for the three different models for the daily temperature data of the Zugspitze along with the estimated effective number of parameters (that provide an estimate for the effective dimension of the model). The DIC also clearly favours the BCPE model over the competing approaches, although it is also the model with the largest number of parameters.
Deviance information criterion (DIC) together with estimated
effective number of parameters (pd) of the daily temperature
models
Deviance information criterion (DIC) together with estimated effective number of parameters (pd) of the daily temperature models
When being interested in the predictive ability of distributional regression model, comparing results based on predictive proper scoring rules (Gneiting et al., 2007) can be a valuable alternative. Klein et al. (2015c) provide details on different scores for various types of responses. Basically, the goal of all specifications is to evaluate the predictive ability based on rules that favour honest predictions while simultaneously taking sharpness (i.e., precision) of the prediction into account. To obtain a truly predictive assessment, the scores will usually be evaluated based on a cross-validation approach which makes their computation numerically demanding compared to information criteria and quantile residuals which can be obtained from one single estimation run.
An implementation of the models discussed in the previous sections is provided in the
where the first two lines basically represent the standard model frame specifications
(see Chambers and Hastie,
1992). The
To give an example how to start using
Note that the file
The model is then estimated using the default MCMC sampler
where we set the number of iteration of the MCMC sampler to
where argument
Estimating models with MCMC sometimes comes at its price in terms of computation
time. For example, fitting the precipitation model specified earlier, with over one
million observations, on a Linux system with Intel i7-2600 3.40GHz processors takes
about
Empirical Analyses
Daily temperature at the Zugspitze
From our previous considerations, we found that the BCPE model provided the best
fit for the daily temperature data. Estimated effects of this model are shown in
Figure 6.
Estimated effects of the daily
A more detailed picture of the temperature time trend is provided in Figure 7. Estimated mean temperature trends of the daily
In this example, the aim is to compute a climatological risk map of Germany of
extreme
To provide better insight on the interpretation of the parameters of the
Example of
The estimated effects of altitude, the time trend and the seasonal time trend for
parameter Estimated effects of altitude, the time trend and the
seasonal time trend of the
The estimated spatial effects for parameter Estimated spatial effects of the
Finally, we computed risk maps for Germany showing estimated Estimated spatial maximum
Distributional regression models, as described in this tutorial, are a flexible extension of GAMs (Wood, 2006; Ruppert et al., 2003; Fahrmeir et al., 2013a) that allow to apply flexible, additive predictor structures not only on the mean but on potentially all parameters of even complex response distributions. This idea has been introduced in a penalized likelihood context by Rigby and Stasinopoulos (2005) as GAMLSS and transferred to a Bayesian context in Klein et al. (2015b,c). We prefer the notion of distributional regression over GAMLSS since in many distributions the parameters are not or only indirectly related to location or scale of the distribution.
The main competitor to distributional regression in applied regression analyses is quantile regression, as also discussed in Waldmann (2018) which is also part of this special issue. While the main advantage of quantile regression is that one can avoid an explicit distributional assumption for the response distribution, it also alleviates the danger of model misspecification. On the other hand, quantile regression requires strictly continuous responses (i.e., discrete or mixed discrete-continuous responses are not allowed), while distributional regression provides a convenient framework for continuous, discrete and mixed discrete-continuous distributions. Furthermore, quantile regression typically faces the risk of quantile crossing while distributional regression provides a coherent estimate for the complete distribution of the response. A final advantage of distributional regression is that it also facilitates the consideration of multivariate response structures (Klein et al., 2015a; Klein and Kneib, 2016).
Another strategy to gain information of the full response distribution is to use conditional transformation models (Hothorn et al., 2014), which directly model the distribution function using regularized transformation functions. Despite their theoretical attractiveness, these models can quickly become computationally expensive, especially in cases where a number of explanatory variables directly interact with the distribution function. A non-technical introduction of Hothorn (2018) is also part of this special issue.
In addition, variable selection in distributional regression is an important aspect. A well-established strategy is to use boosting algorithms, an introduction is provided within this special issue by Mayr and Hofner (2018).
Considering Bayesian approaches to distributional regression based on MCMC simulations is particularly attractive not only due to its flexibility but also due to the virtues of sampling-based inference. MCMC provides samples for all parameters of the distributional regression model which can be transferred to samples for any quantity of interest that depends on these parameters. In our application on extreme precipitation values, one such quantity was the 100-years return level. Based on samples from these return levels, one can determine point estimates as well as credible intervals without requiring asymptotic considerations.
A particular challenge of distributional regression is the interpretation of results, which often can no longer be achieved in a ceteris paribus-type fashion. As a consequence, designing scenarios of interest for which covariate effects can be evaluated in combination with carefully chosen visualization tools is extremely important. In the future, we will work on making such graphical tools more broadly available and easily accessible.
Acknowledgments
We thank two anonymous referees for their valuable comments that led to a significant improvement of the article. Financial support from the German Research Foundation (DFG) grant KN 922/4-2 is gratefully acknowledged.
