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 assumend 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, while an additional parameter vector, \(\zeta\), estimates the normalized distances between consecutive predictor categories. For a single monotonic predictor, \(x\), the linear predictor term of observation \(n\) looks as follows:

\[\eta_n = b \sum_{i = 1}^{x_n} \zeta_i\]

The parameter \(b\) can take on any real value, while \(\zeta\) is a simplex, which means that is it satisfies \(\zeta_i \in [0,1]\) and \(\sum_{i = 1}^C \zeta_i = 1\) with \(C\) being the number of categories (or highest integer in the data).

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; sigma = identity
Formula: ls ~ mo(income)
Data: dat (Number of observations: 100)
Samples: 4 chains, each with iter = 2000; warmup = 1000; thin = 1;
total post-warmup samples = 4000
Population-Level Effects:
Estimate Est.Error l-95% CI u-95% CI Eff.Sample Rhat
Intercept 30.32 1.34 27.68 32.89 2775 1.00
moincome 46.56 1.99 42.59 50.45 2541 1.00
Simplex Parameters:
Estimate Est.Error l-95% CI u-95% CI Eff.Sample Rhat
moincome1[1] 0.58 0.04 0.50 0.66 2396 1.00
moincome1[2] 0.33 0.05 0.24 0.42 3647 1.00
moincome1[3] 0.10 0.04 0.02 0.17 3180 1.00
Family Specific Parameters:
Estimate Est.Error l-95% CI u-95% CI Eff.Sample Rhat
sigma 7.11 0.52 6.18 8.24 3151 1.00
Samples were drawn using sampling(NUTS). For each parameter, Eff.Sample
is a crude measure of effective sample size, 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; sigma = identity
Formula: ls ~ income_num
Data: dat (Number of observations: 100)
Samples: 4 chains, each with iter = 2000; warmup = 1000; thin = 1;
total post-warmup samples = 4000
Population-Level Effects:
Estimate Est.Error l-95% CI u-95% CI Eff.Sample Rhat
Intercept 18.50 2.14 14.31 22.76 3351 1.00
income_num 16.29 0.81 14.74 17.86 3440 1.00
Family Specific Parameters:
Estimate Est.Error l-95% CI u-95% CI Eff.Sample Rhat
sigma 9.07 0.65 7.93 10.47 3381 1.00
Samples were drawn using sampling(NUTS). For each parameter, Eff.Sample
is a crude measure of effective sample size, 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; sigma = identity
Formula: ls ~ income
Data: dat (Number of observations: 100)
Samples: 4 chains, each with iter = 2000; warmup = 1000; thin = 1;
total post-warmup samples = 4000
Population-Level Effects:
Estimate Est.Error l-95% CI u-95% CI Eff.Sample Rhat
Intercept 30.10 1.35 27.46 32.67 3046 1.00
income2 27.17 2.07 23.10 31.25 3075 1.00
income3 42.41 1.89 38.67 46.16 3434 1.00
income4 46.83 2.05 42.74 50.84 3947 1.00
Family Specific Parameters:
Estimate Est.Error l-95% CI u-95% CI Eff.Sample Rhat
sigma 7.11 0.51 6.18 8.20 4074 1.00
Samples were drawn using sampling(NUTS). For each parameter, Eff.Sample
is a crude measure of effective sample size, 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 -340.0 6.9
p_loo 4.8 0.8
looic 680.0 13.7
------
Monte Carlo SE of elpd_loo is 0.0.
All Pareto k estimates are good (k < 0.5).
See help('pareto-k-diagnostic') for details.
Output of model 'fit2':
Computed from 4000 by 100 log-likelihood matrix
Estimate SE
elpd_loo -363.2 6.5
p_loo 2.8 0.5
looic 726.4 13.0
------
Monte Carlo SE of elpd_loo is 0.0.
All Pareto k estimates are good (k < 0.5).
See help('pareto-k-diagnostic') for details.
Output of model 'fit3':
Computed from 4000 by 100 log-likelihood matrix
Estimate SE
elpd_loo -340.0 6.8
p_loo 4.8 0.8
looic 680.0 13.6
------
Monte Carlo SE of elpd_loo is 0.0.
All Pareto k estimates are good (k < 0.5).
See help('pareto-k-diagnostic') for details.
Model comparisons:
elpd_diff se_diff
fit3 0.0 0.0
fit1 0.0 0.2
fit2 -23.2 5.9
```

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 unorderd 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 Dirchlet 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}^K \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; sigma = identity
Formula: ls ~ mo(income)
Data: dat (Number of observations: 100)
Samples: 4 chains, each with iter = 2000; warmup = 1000; thin = 1;
total post-warmup samples = 4000
Population-Level Effects:
Estimate Est.Error l-95% CI u-95% CI Eff.Sample Rhat
Intercept 30.25 1.31 27.71 32.74 2587 1.00
moincome 46.61 2.03 42.65 50.71 2289 1.00
Simplex Parameters:
Estimate Est.Error l-95% CI u-95% CI Eff.Sample Rhat
moincome1[1] 0.58 0.04 0.50 0.66 2807 1.00
moincome1[2] 0.32 0.05 0.24 0.41 3768 1.00
moincome1[3] 0.09 0.04 0.02 0.17 2610 1.00
Family Specific Parameters:
Estimate Est.Error l-95% CI u-95% CI Eff.Sample Rhat
sigma 7.12 0.52 6.20 8.23 2967 1.00
Samples were drawn using sampling(NUTS). For each parameter, Eff.Sample
is a crude measure of effective sample size, and Rhat is the potential
scale reduction factor on split chains (at convergence, Rhat = 1).
```

We have used `sample_prior = TRUE`

to also obtain samples 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; sigma = identity
Formula: ls ~ mo(income) * age
Data: dat (Number of observations: 100)
Samples: 4 chains, each with iter = 2000; warmup = 1000; thin = 1;
total post-warmup samples = 4000
Population-Level Effects:
Estimate Est.Error l-95% CI u-95% CI Eff.Sample Rhat
Intercept 33.76 5.08 24.07 44.29 1181 1.00
age -0.08 0.12 -0.33 0.14 1132 1.00
moincome 44.05 7.23 29.91 58.60 928 1.01
moincome:age 0.06 0.18 -0.29 0.40 915 1.01
Simplex Parameters:
Estimate Est.Error l-95% CI u-95% CI Eff.Sample Rhat
moincome1[1] 0.59 0.07 0.46 0.74 1217 1.00
moincome1[2] 0.32 0.07 0.18 0.45 1902 1.00
moincome1[3] 0.09 0.05 0.01 0.20 1576 1.00
moincome:age1[1] 0.35 0.24 0.02 0.84 2118 1.00
moincome:age1[2] 0.34 0.23 0.01 0.83 2551 1.00
moincome:age1[3] 0.31 0.22 0.01 0.81 2212 1.00
Family Specific Parameters:
Estimate Est.Error l-95% CI u-95% CI Eff.Sample Rhat
sigma 7.16 0.52 6.22 8.27 3140 1.00
Samples were drawn using sampling(NUTS). For each parameter, Eff.Sample
is a crude measure of effective sample size, 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; sigma = identity
Formula: ls ~ mo(income) * age + (mo(income) | city)
Data: dat (Number of observations: 100)
Samples: 4 chains, each with iter = 2000; warmup = 1000; thin = 1;
total post-warmup samples = 4000
Group-Level Effects:
~city (Number of levels: 10)
Estimate Est.Error l-95% CI u-95% CI Eff.Sample Rhat
sd(Intercept) 13.66 4.04 8.01 23.64 1364 1.00
sd(moincome) 4.08 3.13 0.16 11.44 876 1.01
cor(Intercept,moincome) -0.11 0.49 -0.90 0.90 3305 1.00
Population-Level Effects:
Estimate Est.Error l-95% CI u-95% CI Eff.Sample Rhat
Intercept 31.88 6.99 18.27 45.56 1414 1.00
age -0.09 0.13 -0.35 0.15 1766 1.00
moincome 42.76 7.77 27.06 58.04 1557 1.00
moincome:age 0.10 0.18 -0.26 0.47 1557 1.00
Simplex Parameters:
Estimate Est.Error l-95% CI u-95% CI Eff.Sample Rhat
moincome1[1] 0.60 0.08 0.46 0.79 1918 1.00
moincome1[2] 0.31 0.08 0.14 0.45 2407 1.00
moincome1[3] 0.08 0.05 0.00 0.19 3473 1.00
moincome:age1[1] 0.36 0.24 0.02 0.84 4428 1.00
moincome:age1[2] 0.35 0.23 0.02 0.84 4207 1.00
moincome:age1[3] 0.29 0.21 0.01 0.78 4476 1.00
Family Specific Parameters:
Estimate Est.Error l-95% CI u-95% CI Eff.Sample Rhat
sigma 7.01 0.57 5.97 8.21 3322 1.00
Samples were drawn using sampling(NUTS). For each parameter, Eff.Sample
is a crude measure of effective sample size, 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*.