Multilevel models for groups that have different predictors Imagine I am trying to fit a multilevel model on products, and want to group by product type.
In cases where product types have all the same predictors this is straight-forward.  E.g. you might estimate the effect of color on sales or something similar.
But what if some predictors only make sense for some of the product types?  Like a "leg length" feature might make sense for shorts if people have preference for how far above or below the knee they like their shorts, but not for pants which are always full length.  And it may make yet less sense for shirts, since the do not at all have a leg length.
In that case, is there a way to handle that or is it best to have different models per group?  For the features that are shared and are expected to be drawn from the same distribution, I guess we lose some benefit there, so that's why I'm wondering if the models can be done as a single model.
I've thought about a number of things (e.g. for products that don't have the feature, setting it to a constant value, or to a random value drawn from a distribution of feature values from products where the feature does make sense, etc) but all seem to have very obvious problems.
 A: There's a pretty sensible way of doing this if you centre all your predictors by subtracting the mean value.
Using your example, say you have athletic shorts, shorts, and jeans, and your numeric predictors are a) brightness (defined for all categories), and b) short length (defined for shorts only, NA for trousers). Now, if you centre your both your numeric predictors, you get measures of a) whether the items are darker or lighter than average, and b) whether the shorts are shorter or longer than average. You can safely say that the trousers are $\pm0$ cm shorter or longer than average, and so impute a value of 0 for this predictor for all items that aren't shorts (they're neither shorter nor longer than average). You can then fit a multilevel as you normally would, allowing all predictors to vary across categories:
lmer(sales ~ 1 + centred_colour + centred_leg_length + 
             (1 + centred_colour + centred_leg_length | category),
     data=sales_data)

Since this predictor only varies for the different kinds of shorts, only sales of those items will have an effect on this parameter. Since it's set to 0 for all other products, this predictor won't affect inferences or predictions about them.
If it happens that you end up with only one category of shorts in your data,
if won't be possible to include it as a random effect, and you'll have to change your model accordingly:
lmer(sales ~ 1 + centred_colour + centred_leg_length + 
             (1 + centred_colour | category),
     data=sales_data)

A: Try to create a dummy variable that is 0 when a product does not have the feature (i.e. does not have leg), and 1 when it has this feature. Turn then this dummy variable into a factor.
When a dummy does not have a feature, replace the missing value with zero.
Then in your model, interact your continuous variable of interest with the dummy factor variable. Add also the dummy factor variables.

Note: I am happy to read from a more knowable person why this works (or does not work in the general case).
