1

I am trying to fit a linear mixed effects model with several fixed effects and a random intercept that varies per subject.

My problem is that I know that one of the fixed variables, let's call it 'A', depends on another one, 'B', which is categorical. I want to search for associations of 'A' with the response variable, taking into account that 'B' can affect 'A'.

How should I model this? Should I introduce an interaction term, 'A*B' in my model? Or should I introduce a random effect like : (-1 + A | B)? In either of the cases, which should be the association of 'A' and the response variable, how should I identify it?

Thank you very much for your time and effort,

student89
  • 71
  • 3

2 Answers2

1

You seem to mistake random effects with nested variables.

If the available values of an predictor variable A depend on the value of another predictor categorical variable (i.e. 'factor') B, then the variable A is 'nested' into B.

For example, if B can have the values B1, B2 and B3, while A is also categorical, but can have the values A1, A2, A3 for B=B1, A2, A3 for B=B2, and A3, A4, A5 for B=B2, then A is nested into B and their relationship can be modelled (e.g. in R's lmer() syntax) as:

B + A:B

Note that this signifies a full A * B interaction without the independent A term.

If, on the other hand, the effect of A on the outcome is allowed to vary on each level of B, but the available values for A are not necessarily different for each level of B, then the effect of A is random (varying by B), while A can also have a fixed effect. This effect can be modelled as:

A + (0 + A|B)

The first part is the fixed effect and the second the random one.

From what you describe, I infer that you wish to model a predictor A nested in another predictor B in a mixed model with a random intercept that varies by the subject S. So, in that case, the correct syntax would be:

outcome ~ B + A:B + (1|S)

I hope this was helpful.

0

I finally added a random effect that allowed 'A' to vary by 'B': (-1 + A | B) and that seemed to work.

The association can be verified directly by looking at the p value of the 'A' variable.

student89
  • 71
  • 3