# Is an LMER appropriate with only one x per participant?

Let's say each participant does multiple trials in a study, where x represents trial difficulty and y represents the score on that trial. Since the participant is represented by data points spread across the x and y scales, I can see the sense in using a linear mixed-effects regression, modelling random slopes and intercepts for participant.

But what if each participant is represented by just one x value, and several y values? Let's say the x is participant age and y is participant score on a series of trials. It seems nonsensical now to model participant as a random effect - if their data points are just represented by one x value I don't see how they could be modelled as a random slope or intercept.

1. Am I right in thinking an LMER with participant as random effect is not appropriate in such a case? (putting aside the question of whether to model trial as a random effect)

2. Is the 0 variance for participant in the random effects matrix below diagnostic of this specific problem when modelling a random intercept?

3. In the random-intercept example below, a regular lm() has the same output as the lmer(). Will that always be the case in such a situation?

4. Is the correlation of -1 in the random effects structure below diagnostic of this problem with modelling a random slope?

# Generate random data
df = data.frame(participant = rep(letters[seq( from = 1, to = 8)], each=3),
x = rep(c(1,2,3,4), each=6),
offset = runif(24, -0.5, 0.5))
%>% mutate(y=x+offset)

# Model random intercept
Linear mixed model fit by REML ['lmerMod']
Formula: y ~ x + (1 | participant)
Data: df

REML criterion at convergence: 17.1

Scaled residuals:
Min       1Q   Median       3Q      Max
-1.45511 -0.85896 -0.03722  0.72266  1.63586

Random effects:
Groups      Name        Variance Std.Dev.
participant (Intercept) 0.00000  0.0000
Residual                0.09449  0.3074
Number of obs: 24, groups:  participant, 8

Fixed effects:
Estimate Std. Error t value
(Intercept) -0.11465    0.15370  -0.746
x            1.02373    0.05612  18.241

Correlation of Fixed Effects:
(Intr)
x -0.913

# Model random slope
Linear mixed model fit by REML ['lmerMod']
Formula: y ~ x + (1 + x | participant)
Data: df

REML criterion at convergence: 17.1

Scaled residuals:
Min       1Q   Median       3Q      Max
-1.45511 -0.85896 -0.03722  0.72266  1.63586

Random effects:
Groups      Name        Variance  Std.Dev.  Corr
participant (Intercept) 6.469e-16 2.543e-08
x           4.309e-17 6.564e-09 -1.00
Residual                9.449e-02 3.074e-01
Number of obs: 24, groups:  participant, 8

Fixed effects:
Estimate Std. Error t value
(Intercept) -0.11465    0.15370  -0.746
x            1.02373    0.05612  18.241

Correlation of Fixed Effects:
(Intr)
x -0.913


Just because each subject only receives one level of a particular treatment doesn't mean a random intercept by subject is inappropriate. It would be completely useless to do so if there is was no systematic variation by subject or if there was no replication, i.e. for any level of the treatment there was at most one subject receiving it.

In the case of your output, there is no subject to subject variation, so it isn't surprising that it is estimated to be zero. Here is a modified snippet that serves as a counterexample:

set.seed(1)
n=100
r=3
df = data.frame(participant = rep(seq( from = 1, to = n), each=r),
p_int = rep(runif(n, -.5,.5), each=r),
x = rep(1:(n/2), each=r*2),
offset = runif(300, -0.5, 0.5)) %>%
mutate(y = x+offset+p_int)

lmer(y ~ x + (1 | participant), data=df)
Linear mixed model fit by REML ['lmerMod']
Formula: y ~ x + (1 | participant)
Data: df
REML criterion at convergence: 248.3894
Random effects:
Groups      Name        Std.Dev.
participant (Intercept) 0.2714
Residual                0.2884
Number of obs: 300, groups:  participant, 100
Fixed Effects:
(Intercept)            x
0.02259      0.99923


On the other hand, a random slope is useless because there is no way to measure a slope when subsetting on a single participant. The negative one estimated covariance that you observe may be due to the random effects being effectively redundant, but I don't know if this is a reliable diagnostic.

It is confusing that you use x to indicate trial difficulty (which I would expect to differ within participants), but also age (which in this case does not differ within participants). In both cases, it makes sense to model a random intercept w.r.t. participant:

1. Am I right in thinking an LMER with participant as random effect is not appropriate in such a case? (putting aside the question of whether to model trial as a random effect)

If x is age, the random and fixed effect might be correlated, but you can at least distinguish between the (fixed) effect attributable to age, and the random effect due to participants. However, the formula y ~ x + (1 + x | participant) does not make sense if x reflects age; then y ~ x + (1|participant) would be more appropriate. You cannot model an effect within participant (i.e., a random slope) if the variable does not vary within participant.

1. Is the 0 variance for participant in the random effects matrix below diagnostic of this specific problem when modelling a random intercept?

There is no problem, other than that all the variation in y that can be explained with your model is due to x, which does not vary within persons. So, the effect of x is completely captured by the fixed effect of x, and there is nothing left to capture with the random effect.

1. In the random-intercept example below, a regular lm() has the same output as the lmer(). Will that always be the case in such a situation?

See point 2.

1. Is the correlation of -1 in the random effects structure below diagnostic of this problem with modelling a random slope?

Yes. If x does not vary on the participant level, you cannot estimate a random slope.