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; 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 Rhat Bulk_ESS Tail_ESS
Intercept 29.82 1.22 27.51 32.25 1.00 2420 2327
moincome 14.95 0.65 13.67 16.23 1.00 2419 2562
Simplex Parameters:
Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
moincome1[1] 0.71 0.04 0.64 0.79 1.00 2762 2024
moincome1[2] 0.17 0.05 0.08 0.26 1.00 3984 2630
moincome1[3] 0.12 0.05 0.03 0.21 1.00 3584 2056
Family Specific Parameters:
Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
sigma 6.84 0.49 5.95 7.89 1.00 3170 2776
Samples were drawn 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; 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 Rhat Bulk_ESS Tail_ESS
Intercept 21.84 2.34 17.36 26.44 1.00 4098 2624
income_num 14.75 0.90 12.97 16.51 1.00 4077 2410
Family Specific Parameters:
Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
sigma 10.19 0.74 8.85 11.76 1.00 3320 2834
Samples were drawn 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; 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 Rhat Bulk_ESS Tail_ESS
Intercept 29.66 1.23 27.24 32.03 1.00 3440 2835
income2 32.14 1.80 28.62 35.65 1.00 3546 3081
income3 39.62 2.00 35.73 43.48 1.00 3303 2743
income4 45.18 1.86 41.51 48.74 1.00 3101 2624
Family Specific Parameters:
Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
sigma 6.84 0.49 5.97 7.88 1.00 4388 2961
Samples were drawn 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 -336.2 7.5
p_loo 4.9 0.9
looic 672.5 15.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 'fit2':
Computed from 4000 by 100 log-likelihood matrix
Estimate SE
elpd_loo -374.8 5.7
p_loo 2.6 0.3
looic 749.6 11.4
------
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 -336.2 7.5
p_loo 4.8 0.8
looic 672.3 14.9
------
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.1 0.2
fit2 -38.6 7.0
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; 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 Rhat Bulk_ESS Tail_ESS
Intercept 29.78 1.25 27.35 32.21 1.00 3297 2714
moincome 14.99 0.62 13.80 16.19 1.00 2887 2932
Simplex Parameters:
Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
moincome1[1] 0.71 0.04 0.64 0.79 1.00 3151 2441
moincome1[2] 0.17 0.04 0.08 0.26 1.00 3987 2701
moincome1[3] 0.12 0.04 0.03 0.21 1.00 2874 1869
Family Specific Parameters:
Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
sigma 6.84 0.49 5.96 7.88 1.00 3034 2502
Samples were drawn 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 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 Rhat Bulk_ESS Tail_ESS
Intercept 34.08 3.85 26.62 41.81 1.00 1572 2427
age -0.11 0.09 -0.29 0.07 1.00 1463 2104
moincome 14.95 2.37 10.71 19.89 1.00 997 1767
moincome:age 0.00 0.06 -0.12 0.11 1.00 976 1833
Simplex Parameters:
Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
moincome1[1] 0.71 0.07 0.57 0.86 1.00 1174 1594
moincome1[2] 0.16 0.06 0.03 0.27 1.00 1805 997
moincome1[3] 0.13 0.06 0.02 0.26 1.00 1499 1207
moincome:age1[1] 0.34 0.24 0.01 0.84 1.00 2061 1844
moincome:age1[2] 0.32 0.23 0.01 0.82 1.00 2298 2129
moincome:age1[3] 0.34 0.24 0.01 0.87 1.00 1631 1475
Family Specific Parameters:
Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
sigma 6.82 0.51 5.91 7.91 1.00 3082 2367
Samples were drawn 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; 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 Rhat Bulk_ESS Tail_ESS
sd(Intercept) 15.29 4.39 9.05 26.07 1.00 1232 1811
sd(moincome) 0.99 0.81 0.03 2.92 1.00 1432 1571
cor(Intercept,moincome) -0.01 0.54 -0.93 0.93 1.00 4032 2428
Population-Level Effects:
Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
Intercept 30.34 6.82 17.44 43.90 1.00 1177 1599
age -0.14 0.11 -0.38 0.06 1.00 1575 1819
moincome 14.47 2.62 9.29 19.75 1.00 1174 1698
moincome:age 0.01 0.06 -0.12 0.13 1.00 1145 1530
Simplex Parameters:
Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
moincome1[1] 0.72 0.08 0.57 0.88 1.00 1731 1798
moincome1[2] 0.17 0.06 0.04 0.29 1.00 3137 2385
moincome1[3] 0.11 0.06 0.01 0.26 1.00 2547 1962
moincome:age1[1] 0.36 0.24 0.02 0.85 1.00 2928 2543
moincome:age1[2] 0.31 0.23 0.01 0.82 1.00 4318 2810
moincome:age1[3] 0.33 0.24 0.01 0.85 1.00 3202 3223
Family Specific Parameters:
Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
sigma 6.84 0.54 5.88 7.98 1.00 4055 2995
Samples were drawn 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.