# Categorical interaction modelling deviation from expected average

I have a model design in mind which I don’t know how to implement using brms. Suppose I have a dataset which represents height averages across gender and country. This would yield a dataset with a continuous response (height) and two categorical predictors: gender (male and female) and country (A, B and C). Now I’d like to model the interactions of country and gender as deviations from the expected average. E.g. men are taller than women globally and each country has its own average height. Suppose country A exhibits a fairly moderate average height but there, the women are taller than men hence they deviate from both their expected height associated with their gender and given that the expected height in country A is moderate, this makes women’s height stand out. However, in country B, women are also taller than the global average but men are even taller hence despite deviating from the group average associated with gender, this is not remarkable as women’s height doesn’t deviate much from the expected average associated with country. In essence, I’d like the model to reflect these deviations.

However, I don’t know how to do it and I’ve tried various categorical interaction models with or without varying intercepts but so far, none seems to do what I want it to model:

``````brm(height ~ 0 + country + gender, data = mydat)
brm(height ~ 0 + country:gender, data = mydat)
brm(height ~ 0 + country + gender + country:gender, data = mydat)
brm(height ~ 0 + country:gender + (1|country) + (1|gender), data = mydat)
``````

Also I don’t know whether including intercepts (e.g. 1 + variable) plays a role here but so far it doesn’t change anything except the coefficients’ interpretation. The closest I’ve come to a solution is the idea to fix the intercept for country and gender to the respective averages and then running an interaction model but I’m not sure how this could work in brms.

Do you have suggestions regarding how to implement such a model?

``````height ~ country * gender
`library (plyr) dat.new = ddply(mydata, c("gender"), transform, soundratio = scale(height, scale = F)) dat.new = ddply(dat.new, c("country"), transform, soundratio = scale(height, scale = F))`
`brm(height ~ 0 + country:gender, data = dat.new)`