# Covariates with measurement error in lme4?

I have a model something like this:

lmer(y ~ factor(month) + x + (1|subject))


Where month represents repeated measures of y. The x variable is fixed-per subject.

However x is an aggregate of multiple measurements taken before the main experiment started, and these are unbalanced. For some subjects x is based on 2 observations, but for others it's based on as many as 30.

Is there any way to include uncertainty in the measurement of x in the main model without re-running this as some kind of SEM?

EDIT: I've just discovered this is called an errors-in-measurement model, and is possible using the brms package, which in turn relies on Stan (see https://github.com/paul-buerkner/brms/issues/114). If there is a simpler way to run these models without resorting to MCMC I'd still be interested though.

It sounds like what you want is not to model measurement error but to weight x according to the number of trials the variable is based on. lme4 has a weight parameter, but I believe that's for weighting entire observations. The only thing I can think of that lets you stick with lmer is to transform x in some fashion so that it has a bigger absolute value when the number of trials is bigger. Since I have no idea what x represents, I couldn't give you a concrete suggestion of a transformation.