This vignette is about monotonic effects, a special way of handling discrete predictors that are on an ordinal or higher scale (Bürkner & Charpentier, in review). A predictor, which we want to model as monotonic (i.e., having a monotonically increasing or decreasing relationship with the response), must either be integer valued or an ordered factor. As opposed to a continuous predictor, predictor categories (or integers) are not assumed to be equidistant with respect to their effect on the response variable. Instead, the distance between adjacent predictor categories (or integers) is estimated from the data and may vary across categories. This is realized by parameterizing as follows: One parameter, \(b\), takes care of the direction and size of the effect similar to an ordinary regression parameter. If the monotonic effect is used in a linear model, \(b\) can be interpreted as the expected average difference between two adjacent categories of the ordinal predictor. An additional parameter vector, \(\zeta\), estimates the normalized distances between consecutive predictor categories which thus defines the shape of the monotonic effect. For a single monotonic predictor, \(x\), the linear predictor term of observation \(n\) looks as follows:
\[\eta_n = b D \sum_{i = 1}^{x_n} \zeta_i\]
The parameter \(b\) can take on any real value, while \(\zeta\) is a simplex, which means that it satisfies \(\zeta_i \in [0,1]\) and \(\sum_{i = 1}^D \zeta_i = 1\) with \(D\) being the number of elements of \(\zeta\). Equivalently, \(D\) is the number of categories (or highest integer in the data) minus 1, since we start counting categories from zero to simplify the notation.
A main application of monotonic effects are ordinal predictors that can be modeled this way without falsely treating them either as continuous or as unordered categorical predictors. In Psychology, for instance, this kind of data is omnipresent in the form of Likert scale items, which are often treated as being continuous for convenience without ever testing this assumption. As an example, suppose we are interested in the relationship of yearly income (in $) and life satisfaction measured on an arbitrary scale from 0 to 100. Usually, people are not asked for the exact income. Instead, they are asked to rank themselves in one of certain classes, say: ‘below 20k’, ‘between 20k and 40k’, ‘between 40k and 100k’ and ‘above 100k’. We use some simulated data for illustration purposes.
income_options <- c("below_20", "20_to_40", "40_to_100", "greater_100")
income <- factor(sample(income_options, 100, TRUE),
levels = income_options, ordered = TRUE)
mean_ls <- c(30, 60, 70, 75)
ls <- mean_ls[income] + rnorm(100, sd = 7)
dat <- data.frame(income, ls)We now proceed with analyzing the data modeling income
as a monotonic effect.
The summary methods yield
Family: gaussian
Links: mu = identity
Formula: ls ~ mo(income)
Data: dat (Number of observations: 100)
Draws: 4 chains, each with iter = 2000; warmup = 1000; thin = 1;
total post-warmup draws = 4000
Regression Coefficients:
Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
Intercept 30.69 1.55 27.60 33.85 1.00 2682 2354
moincome 14.71 0.66 13.39 16.04 1.00 2863 2070
Monotonic Simplex Parameters:
Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
moincome1[1] 0.65 0.04 0.58 0.72 1.00 3717 2493
moincome1[2] 0.23 0.04 0.14 0.31 1.00 3506 2615
moincome1[3] 0.13 0.04 0.05 0.20 1.00 3210 1806
Further Distributional Parameters:
Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
sigma 6.60 0.48 5.75 7.62 1.00 3385 2716
Draws were sampled using sampling(NUTS). For each parameter, Bulk_ESS
and Tail_ESS are effective sample size measures, and Rhat is the potential
scale reduction factor on split chains (at convergence, Rhat = 1).
The distributions of the simplex parameter of income, as
shown in the plot method, demonstrate that the largest
difference (about 70% of the difference between minimum and maximum
category) is between the first two categories.
Now, let’s compare of monotonic model with two common alternative
models. (a) Assume income to be continuous:
Family: gaussian
Links: mu = identity
Formula: ls ~ income_num
Data: dat (Number of observations: 100)
Draws: 4 chains, each with iter = 2000; warmup = 1000; thin = 1;
total post-warmup draws = 4000
Regression Coefficients:
Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
Intercept 25.55 2.33 20.91 30.20 1.00 3956 3139
income_num 13.32 0.80 11.76 14.87 1.00 4041 3010
Further Distributional Parameters:
Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
sigma 8.83 0.63 7.71 10.15 1.00 3673 2505
Draws were sampled using sampling(NUTS). For each parameter, Bulk_ESS
and Tail_ESS are effective sample size measures, and Rhat is the potential
scale reduction factor on split chains (at convergence, Rhat = 1).
or (b) Assume income to be an unordered factor:
Family: gaussian
Links: mu = identity
Formula: ls ~ income
Data: dat (Number of observations: 100)
Draws: 4 chains, each with iter = 2000; warmup = 1000; thin = 1;
total post-warmup draws = 4000
Regression Coefficients:
Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
Intercept 30.32 1.52 27.37 33.26 1.00 2174 2291
income2 28.88 1.99 25.09 32.82 1.00 2745 2584
income3 38.89 1.99 34.98 42.68 1.00 2787 2859
income4 44.57 1.91 40.88 48.32 1.00 2697 2641
Further Distributional Parameters:
Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
sigma 6.59 0.49 5.69 7.64 1.00 3222 2780
Draws were sampled using sampling(NUTS). For each parameter, Bulk_ESS
and Tail_ESS are effective sample size measures, and Rhat is the potential
scale reduction factor on split chains (at convergence, Rhat = 1).
We can easily compare the fit of the three models using leave-one-out cross-validation.
Output of model 'fit1':
Computed from 4000 by 100 log-likelihood matrix.
Estimate SE
elpd_loo -332.6 7.5
p_loo 4.9 0.9
looic 665.1 15.1
------
MCSE of elpd_loo is 0.0.
MCSE and ESS estimates assume MCMC draws (r_eff in [0.6, 1.0]).
All Pareto k estimates are good (k < 0.7).
See help('pareto-k-diagnostic') for details.
Output of model 'fit2':
Computed from 4000 by 100 log-likelihood matrix.
Estimate SE
elpd_loo -360.7 6.9
p_loo 3.0 0.6
looic 721.4 13.8
------
MCSE of elpd_loo is 0.0.
MCSE and ESS estimates assume MCMC draws (r_eff in [0.8, 1.0]).
All Pareto k estimates are good (k < 0.7).
See help('pareto-k-diagnostic') for details.
Output of model 'fit3':
Computed from 4000 by 100 log-likelihood matrix.
Estimate SE
elpd_loo -332.5 7.6
p_loo 4.9 0.9
looic 665.0 15.2
------
MCSE of elpd_loo is 0.0.
MCSE and ESS estimates assume MCMC draws (r_eff in [0.5, 1.2]).
All Pareto k estimates are good (k < 0.7).
See help('pareto-k-diagnostic') for details.
Model comparisons:
model elpd_diff se_diff p_worse diag_diff diag_elpd
fit3 0.0 0.0 NA
fit1 -0.1 0.3 0.61 |elpd_diff| < 4
fit2 -28.2 5.9 1.00
The monotonic model fits better than the continuous model, which is
not surprising given that the relationship between income
and ls is non-linear. The monotonic and the unordered
factor model have almost identical fit in this example, but this may not
be the case for other data sets.
In the previous monotonic model, we have implicitly assumed that all differences between adjacent categories were a-priori the same, or formulated correctly, had the same prior distribution. In the following, we want to show how to change this assumption. The canonical prior distribution of a simplex parameter is the Dirichlet distribution, a multivariate generalization of the beta distribution. It is non-zero for all valid simplexes (i.e., \(\zeta_i \in [0,1]\) and \(\sum_{i = 1}^D \zeta_i = 1\)) and zero otherwise. The Dirichlet prior has a single parameter \(\alpha\) of the same length as \(\zeta\). The higher \(\alpha_i\) the higher the a-priori probability of higher values of \(\zeta_i\). Suppose that, before looking at the data, we expected that the same amount of additional money matters more for people who generally have less money. This translates into a higher a-priori values of \(\zeta_1\) (difference between ‘below_20’ and ‘20_to_40’) and hence into higher values of \(\alpha_1\). We choose \(\alpha_1 = 2\) and \(\alpha_2 = \alpha_3 = 1\), the latter being the default value of \(\alpha\). To fit the model we write:
prior4 <- prior(dirichlet(c(2, 1, 1)), class = "simo", coef = "moincome1")
fit4 <- brm(ls ~ mo(income), data = dat,
prior = prior4, sample_prior = TRUE)The 1 at the end of "moincome1" may appear
strange when first working with monotonic effects. However, it is
necessary as one monotonic term may be associated with multiple simplex
parameters, if interactions of multiple monotonic variables are included
in the model.
Family: gaussian
Links: mu = identity
Formula: ls ~ mo(income)
Data: dat (Number of observations: 100)
Draws: 4 chains, each with iter = 2000; warmup = 1000; thin = 1;
total post-warmup draws = 4000
Regression Coefficients:
Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
Intercept 30.60 1.54 27.54 33.59 1.00 2426 2566
moincome 14.74 0.65 13.45 16.01 1.00 2173 2221
Monotonic Simplex Parameters:
Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
moincome1[1] 0.65 0.04 0.58 0.72 1.00 3276 2294
moincome1[2] 0.22 0.04 0.14 0.31 1.00 3303 2579
moincome1[3] 0.13 0.04 0.05 0.20 1.00 2776 1430
Further Distributional Parameters:
Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
sigma 6.60 0.47 5.76 7.60 1.00 2995 2500
Draws were sampled using sampling(NUTS). For each parameter, Bulk_ESS
and Tail_ESS are effective sample size measures, and Rhat is the potential
scale reduction factor on split chains (at convergence, Rhat = 1).
We have used sample_prior = TRUE to also obtain draws
from the prior distribution of simo_moincome1 so that we
can visualized it.
As is visible in the plots, simo_moincome1[1] was
a-priori on average twice as high as simo_moincome1[2] and
simo_moincome1[3] as a result of setting \(\alpha_1\) to 2.
Suppose, we have additionally asked participants for their age.
We are not only interested in the main effect of age but also in the
interaction of income and age. Interactions with monotonic variables can
be specified in the usual way using the * operator:
Family: gaussian
Links: mu = identity
Formula: ls ~ mo(income) * age
Data: dat (Number of observations: 100)
Draws: 4 chains, each with iter = 2000; warmup = 1000; thin = 1;
total post-warmup draws = 4000
Regression Coefficients:
Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
Intercept 27.51 5.28 16.90 37.86 1.00 1801 2144
age 0.08 0.13 -0.16 0.34 1.00 1651 1876
moincome 18.56 2.56 13.46 23.50 1.00 1433 1357
moincome:age -0.09 0.06 -0.21 0.03 1.00 1386 1295
Monotonic Simplex Parameters:
Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
moincome1[1] 0.57 0.07 0.45 0.70 1.00 1733 1842
moincome1[2] 0.27 0.07 0.15 0.41 1.00 1995 2040
moincome1[3] 0.16 0.06 0.07 0.29 1.00 2029 1674
moincome:age1[1] 0.28 0.21 0.01 0.76 1.00 2421 2176
moincome:age1[2] 0.42 0.24 0.03 0.88 1.00 2121 2170
moincome:age1[3] 0.30 0.21 0.01 0.79 1.00 2358 2325
Further Distributional Parameters:
Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
sigma 6.51 0.48 5.65 7.51 1.00 2784 2635
Draws were sampled using sampling(NUTS). For each parameter, Bulk_ESS
and Tail_ESS are effective sample size measures, and Rhat is the potential
scale reduction factor on split chains (at convergence, Rhat = 1).
Suppose that the 100 people in our sample data were drawn from 10
different cities; 10 people per city. Thus, we add an identifier for
city to the data and add some city-related variation to
ls.
dat$city <- rep(1:10, each = 10)
var_city <- rnorm(10, sd = 10)
dat$ls <- dat$ls + var_city[dat$city]With the following code, we fit a multilevel model assuming the
intercept and the effect of income to vary by city:
Family: gaussian
Links: mu = identity
Formula: ls ~ mo(income) * age + (mo(income) | city)
Data: dat (Number of observations: 100)
Draws: 4 chains, each with iter = 2000; warmup = 1000; thin = 1;
total post-warmup draws = 4000
Multilevel Hyperparameters:
~city (Number of levels: 10)
Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
sd(Intercept) 7.58 2.67 3.77 14.18 1.00 1274 1792
sd(moincome) 0.95 0.76 0.04 2.85 1.00 1440 1865
cor(Intercept,moincome) -0.35 0.54 -0.99 0.86 1.00 2288 2488
Regression Coefficients:
Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
Intercept 30.39 6.13 18.28 42.10 1.00 1405 2574
age 0.02 0.13 -0.23 0.29 1.00 1861 2220
moincome 18.21 2.68 12.86 23.49 1.00 1570 1855
moincome:age -0.09 0.06 -0.21 0.04 1.00 1506 1725
Monotonic Simplex Parameters:
Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
moincome1[1] 0.57 0.07 0.44 0.70 1.00 2076 2827
moincome1[2] 0.27 0.06 0.15 0.40 1.00 2592 2747
moincome1[3] 0.16 0.06 0.06 0.29 1.00 2522 2114
moincome:age1[1] 0.29 0.22 0.01 0.80 1.00 3339 1997
moincome:age1[2] 0.41 0.24 0.02 0.88 1.00 2909 2996
moincome:age1[3] 0.30 0.22 0.01 0.80 1.00 3086 2508
Further Distributional Parameters:
Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
sigma 6.55 0.51 5.65 7.64 1.00 4014 2898
Draws were sampled using sampling(NUTS). For each parameter, Bulk_ESS
and Tail_ESS are effective sample size measures, and Rhat is the potential
scale reduction factor on split chains (at convergence, Rhat = 1).
reveals that the effect of income varies only little
across cities. For the present data, this is not overly surprising given
that, in the data simulations, we assumed income to have
the same effect across cities.
Bürkner P. C. & Charpentier, E. (in review). Monotonic Effects: A Principled Approach for Including Ordinal Predictors in Regression Models. PsyArXiv preprint.