5

I have the following model fitted using the lme4 package in R:

mod <- lmer(var1 ~ var2 * var3 + (1|var4) , data=s1, REML=F)

I want to express this as an equation. I have the following:

$$ Y_{i} = \beta_0 + \beta_{0\varpi} + \beta_{1\nu}\nu_i + \beta_{1\varsigma}\varsigma_i + \beta_{1\vartheta}\nu_i\varsigma_i + e_{i} $$

Where $\nu=var2$, $\varsigma=var3$ and $\varpi = var4$, so $\beta_0$ is the overall intercept, $\beta_{0\varpi}$ is the random intercept for var4, $\beta_{1\nu}\nu_i$ is the slope for var2, $\beta_{1\varsigma}\varsigma_i$ is the slope for var3 and $\beta_{1\vartheta}\nu_i\varsigma_i$ is the slope for the interaction (var2,var3).

I am wondering if this is the best way to express this model/if there are any better alternatives (such as expressing var2 and var3 as a matrix)?

amoeba
  • 104,745
  • 4
    It's conventional to use Latin letters for variables and Greek for coefficients. I would write: \begin{gather} y\sim\mathcal N(\beta_0 + \beta_1\cdot x + \beta_2\cdot y + \beta_3\cdot xy, \sigma^2_e) \ \beta_0 \sim \mathcal N(\bar\beta_0, \sigma^2_0) \end{gather}With a slight abuse of notation one can also write it a bit simpler as \begin{gather} y = \beta_0 + \beta_1\cdot x + \beta_2\cdot y + \beta_3\cdot xy\ \beta_0 \sim \mathcal N(\bar\beta_0, \sigma^2_0) \end{gather} – amoeba Oct 18 '17 at 12:15
  • 1
    @amoeba, post as answer? You can express this in matrix notation ($\mathbf y = \mathbf X \mathbf \beta + \mathbf Z \mathbf b$ etc.) but I think amoeba's notation is probably clearer. Depends on your audience. – Ben Bolker Oct 18 '17 at 12:56
  • @amoeba, thanks for that, just 2 questions: 1) you use $y$ twice - for a fixed effect variable and the dependent variable...is this not a bit confusing, or am I missing something? 2) where is the random intercept in your equation? – tribalsoul Oct 18 '17 at 13:33
  • @BenBolker, is the matrix notation was more widely used? It seems to be in text books. But thinking about it, my audience will probably be better off with the long hand form – tribalsoul Oct 18 '17 at 13:36
  • 1
    (1) You are right, this should be changed. Do your variables var1, var2, etc. have some meaningful names? If so, I would write smth like $$\mathrm{Height}=\beta_0+\beta_1\cdot\mathrm{Age}+\beta_2...$$ As long as you have only a handful of variables this is going to be fine. (2) $\beta_0$ is the intercept and the second line shows that it's random. $\bar\beta_0$ is the "fixed intercept" and $\sigma^2_0$ is the variance of random intercept. – amoeba Oct 18 '17 at 13:43
  • 1
    By the way, this assumes that your var2 and var3 are continuous. If they are categorical, then the model has to be written differently. – amoeba Oct 18 '17 at 13:46
  • @amoeba, great, thank you. But yes, they are not all continuous. var1 and var2 are continuous, var3 and var4 are categorical. So I shouldn't express them as normally distributed. To give them more meaningful names: $Rating = \beta_0 + \beta_{0Subject} + \beta_1 \cdot Distance + \beta_2 \cdot Item + \beta_3 \cdot Item \cdot Distance + e$ Where $Subject$ is random categorical, $Distance$ is fixed continuous, $Item$ is fixed categorical – tribalsoul Oct 18 '17 at 14:22
  • Well, this information is crucial. If Item is categorical then it does not make any sense to write $\beta_2\cdot\mathrm{Item}$... The value of Item is an integer, but we are not multiplying beta with this integer. Instead, one can write $\gamma_i$ where $i$ can take values from 1 to K-1 where K is the number of levels of the Item factor. You are essentially fitting different intercepts for different values of Item. And similarly for the interaction term. – amoeba Oct 18 '17 at 21:29
  • Ok, I'm confused now! I have seen this notation used for categorical variables in a couple of places (equation 1 on page 9 of [this doc] (http://talklab.psy.gla.ac.uk/KeepItMaximalR2.pdf) and in this course video (from around 1m in). I feel that I'm missing something obvious here? Just to clarify, are you saying the equation would be: – tribalsoul Oct 18 '17 at 22:13
  • (cont.) $Rating = \beta_0 + \beta_{0Subject} + \beta_1 \cdot Distance + \gamma_i + \beta_3 \cdot Distance \cdot \gamma_i + \epsilon $? That doesn't look right to me either. Would you mind clarifying? – tribalsoul Oct 18 '17 at 22:36
  • @tribalsoul (Please ping me with @amoeba when you reply.) Eq 1 on page 9 in Barr et al. considers X that is indeed categorical but has only 2 levels. That's a bit of a special case, because then there is only one additional intercept to be estimated, so one can write $\beta\cdot X$ as they do. Is your Item also binary or does it have more levels? – amoeba Oct 19 '17 at 07:49
  • @amoeba, sorry, I realise that this would have been much more efficient had I included all the pertinent information at the outset. $Item$ has 30 levels (and $Subject$ has ~50 levels). I now see why $\beta_2 \cdot Item$ would only apply for 2 levels (one being the base (in r), and the coefficient being the difference from base, for the second level. I have 30 coefficients for $Item$, and 30 for the interaction $Item * Distance$. I am starting to think matrix notation may be the best way to express this, although I prefer the long form, if it doesn't mean listing out all the coefficients. – tribalsoul Oct 19 '17 at 15:01
  • [cont.] Could the $\beta_2$ and $\beta_3$ set of coefficients not be expressed as vectors? – tribalsoul Oct 19 '17 at 15:02
  • 1
    So if Item is categorical then instead of $\beta \cdot \mathrm{Item}$ you can write something like $\gamma_k$ and explain that $k$ stands for Item number $k$, or you can write the same thing more explicitly as $\gamma_k \cdot I(\mathrm{Item}=k)$. Here $I()$ is an indicator function. By the way, note that 30 levels is quite a lot, so you should consider making Item a random effect. – amoeba Oct 19 '17 at 15:16
  • (I am considering to write a proper answer to this question but if so I'd like it to be comprehensive and as you can see this gets quite involved...) – amoeba Oct 19 '17 at 15:19
  • @amoeba, great, thanks. That makes sense. I'm aware 30 levels is a lot, but the main thing I am interested in is the 30 coefficients for the interaction (I want to evaluate how good a predictor $Distance$ is at each level of $Item$. I calculate the CIs for each of the interaction coefficients, and am interested in cases of $Item$ where the CIs do not cross 0 (i.e. sig neg/pos slopes). The model does not seem deficient doing this. I appreciate your input and would happily upvote an answer. I think it would be useful to others also. – tribalsoul Oct 19 '17 at 16:10
  • I have similar question here, could someone help to answer this? Thanks a lot. – ah bon Apr 02 '20 at 07:02

0 Answers0