How to build brms monotonic model with additional predictor?


We are trying to estimate the influence of an ordinal predictor and a continuous predictor on our observations.
We have found and could use the brm monotonic model presented here which works well for our case:

mu = np.mean( observations )
sd = np.std( observations )

ncat = len( np.unique(ordinal_predictor) )
df = ncat -1
con_simo = np.ones( df )

Xmo = np.zeros((len(ordinal_predictor), ncat), int)
for ic, i in enumerate(categories):
    if i > 0:
        Xmo[ic, :i+1] = np.arange(i+1)
a = theano.shared(np.zeros(1,))
with pm.Model() as brm_model:
    temp_Intercept = pm.StudentT('intercept', mu=mu, sd=sd, nu=df)
    beta = pm.Normal('beta', mu=0., sd=100.)
    simo_t = pm.Dirichlet('simo', a=con_simo)
    simo = T.concatenate([a, simo_t])
    sigma = pm.HalfStudentT('sigma', sd=sd, nu=df)    
    p = temp_Intercept + beta * T.sum(simo[Xmo], axis=1)
    obs = pm.Lognormal('obs', mu=p, sd=sigma, observed=observations)
    trace = pm.sample(draws=3000, tune=3000, chains=2)

We were wondering if you would have advices or pointers that you could give us on how to best integrate the 2nd continuous predictor to this model?
Thank you

Depending on how you are going to code the predictor, but usually you can do

beta2 = pm.Normal('beta2', mu=0., sd=10.)
p = temp_Intercept + beta * T.sum(simo[Xmo], axis=1) + beta2 * continous_predictor

Thank you for the quick answer!

I had been too vague in my previous post. We suspect that both the continuous predictor and the observations vary with the ordinal predictor. We are trying to estimate the influence of the continuous and ordinal predictor on our observations while accounting for the following interactions:

ordinal predictor => continuous predictor => observations
ordinal predictor => observations

I see, I am not sure in that case your model will be identifiable (it’s over specified), but you can add the following 2 component into your model (in addition to what you are already modeling which is ordinal predictor => observations): another ordinal regression for continuous predictor, a linear regression with continuous predictor as covariates and observations as response.