This vignette is about monotonic effects, a special way of handling discrete predictors that are on an ordinal or higher scale. The idea was brought to me by Emmanuel Charpentier, who deserves full credit for it. 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 31.66 1.68 28.47 34.98 2680 1.00
moincome 42.44 2.16 38.17 46.73 2552 1.00
Simplex Parameters:
Estimate Est.Error l-95% CI u-95% CI Eff.Sample Rhat
moincome1[1] 0.69 0.04 0.60 0.77 3242 1.00
moincome1[2] 0.20 0.05 0.11 0.30 4000 1.00
moincome1[3] 0.11 0.05 0.03 0.20 3166 1.00
Family Specific Parameters:
Estimate Est.Error l-95% CI u-95% CI Eff.Sample Rhat
sigma 7.26 0.54 6.30 8.41 3470 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 27.42 2.52 22.48 32.29 3861 1.00
income_num 12.73 0.88 11.06 14.47 3809 1.00
Family Specific Parameters:
Estimate Est.Error l-95% CI u-95% CI Eff.Sample Rhat
sigma 9.71 0.70 8.47 11.23 3789 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 31.31 1.65 28.20 34.70 2578 1.00
income2 29.50 2.09 25.30 33.60 2946 1.00
income3 38.20 2.30 33.51 42.60 2953 1.00
income4 42.89 2.08 38.79 46.92 2670 1.00
Family Specific Parameters:
Estimate Est.Error l-95% CI u-95% CI Eff.Sample Rhat
sigma 7.25 0.53 6.28 8.37 4000 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.

```
LOOIC SE
fit1 684.24 12.84
fit2 740.89 13.01
fit3 683.84 12.81
fit1 - fit2 -56.65 12.21
fit1 - fit3 0.40 0.55
fit2 - fit3 57.05 12.52
```

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 31.71 1.67 28.42 35.17 2635 1.00
moincome 42.37 2.15 38.08 46.52 2533 1.00
Simplex Parameters:
Estimate Est.Error l-95% CI u-95% CI Eff.Sample Rhat
moincome1[1] 0.69 0.04 0.61 0.77 3530 1.00
moincome1[2] 0.20 0.05 0.10 0.30 3052 1.00
moincome1[3] 0.11 0.04 0.03 0.20 3452 1.00
Family Specific Parameters:
Estimate Est.Error l-95% CI u-95% CI Eff.Sample Rhat
sigma 7.25 0.53 6.29 8.34 3008 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 42.69 7.29 29.99 57.92 1192 1.00
age -0.30 0.19 -0.72 0.03 1154 1.00
moincome 30.59 8.84 11.97 46.66 1092 1.00
moincome:age 0.33 0.23 -0.09 0.81 1069 1.00
Simplex Parameters:
Estimate Est.Error l-95% CI u-95% CI Eff.Sample Rhat
moincome1[1] 0.71 0.12 0.41 0.91 1339 1.00
moincome1[2] 0.18 0.11 0.02 0.44 1556 1.00
moincome1[3] 0.11 0.07 0.01 0.28 2502 1.00
moincome:age1[1] 0.52 0.25 0.03 0.90 1403 1.00
moincome:age1[2] 0.28 0.20 0.01 0.76 2254 1.00
moincome:age1[3] 0.20 0.18 0.01 0.68 1778 1.00
Family Specific Parameters:
Estimate Est.Error l-95% CI u-95% CI Eff.Sample Rhat
sigma 7.20 0.53 6.25 8.30 3225 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) 12.63 3.71 7.27 21.62 1457 1.00
sd(moincome) 2.57 2.16 0.08 8.02 2163 1.00
cor(Intercept,moincome) -0.13 0.55 -0.95 0.92 4000 1.00
Population-Level Effects:
Estimate Est.Error l-95% CI u-95% CI Eff.Sample Rhat
Intercept 41.52 8.59 25.71 59.87 1204 1.00
age -0.31 0.19 -0.74 0.02 1353 1.00
moincome 31.68 9.32 11.60 48.40 1339 1.00
moincome:age 0.29 0.24 -0.12 0.81 1338 1.00
Simplex Parameters:
Estimate Est.Error l-95% CI u-95% CI Eff.Sample Rhat
moincome1[1] 0.70 0.13 0.37 0.90 978 1.00
moincome1[2] 0.20 0.11 0.02 0.47 1165 1.00
moincome1[3] 0.11 0.07 0.01 0.27 4000 1.00
moincome:age1[1] 0.52 0.25 0.03 0.92 2138 1.00
moincome:age1[2] 0.28 0.21 0.01 0.77 3073 1.00
moincome:age1[3] 0.21 0.18 0.01 0.71 2442 1.00
Family Specific Parameters:
Estimate Est.Error l-95% CI u-95% CI Eff.Sample Rhat
sigma 7.18 0.57 6.15 8.41 4000 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.