Open travis-leith opened 9 months ago
The problem seems to be the fact that the random intercept is grouped by t
, but that is the only thing that should be grouped by t
. If I remove the random intercept component, and set subject = "subject"
, then it gets the right answer. Other than identifying the grouping to use for the random intercept, I am not sure what effect the parameter subject
actually has. Is this a bug, or is this a user error?
Hi, the "subject" identifies the unique identifier unit. I assume this is the subject for you. The time is an explanatory variable and should be included in the right hand side of the formulas. In addition, I don't understand the (x - 1 | g) in the lmer. I would rather assume : x*g to have an effect of the covariate specific to each group g level. Think of the group g variable as any other categorical variable. The only difference with latent class models is that is it unknown, and so it needs to be retrieved from the data. But the idea is really the same as having a categorical variable in your model. Cécile
Hi @CecileProust-Lima, the (x-1|g)
means there is a random slope assigned to each g
. The -1
, just like the convention in lm
, means there is no intercept. If (x|g
) is used instead, this would specify a random slope and intercept for each g
.
Now that you mention it, an interaction effect makes sense in this simulated data. So now the model is
m_lmer <- lmer(y ~ x:g - 1 + (1 | t), data = simulated_data |> mutate(g = as.character(g)))
And this gives almost identical results in this case, although in a case with less clear separation, the random slope version would probably exhibit more shrinkage.
For the avoidance of doubt, the model being simulated is
$y_i = \beta_g x_i + \epsilon_t + \epsilon_i$, where $S(i)=s$ and $G(s)=g$.
By this I mean that the $i$ th observation, which is made of subject $s$, which belongs to latent group $g$ is a linear function of covariate $x$ and some randomness associated with time $t$ and some randomness associated with observation $i$.
If we assume that we do not know the mapping $G(s)$, can we discover it using lcmm, and still model $\epsilon_t$ at the same time?
I have need of identifying latent classes in some data. I have come up with a simulation of a very simplified version of my suspected data generating process.
To explain my data, I have some coefficients which I suspect might differ by some latent grouping, and I have some common effect due to measuring different subjects at the same time.
After I simulate the data, I estimate the effects with known groups using
lmer
, and I do the same with unknown groups usinghlme
.lmer
is able to estimate the unknown group coefficients quite well, which is not surprising since it knows the groups in the first place.However, the group coefficients (I realise I am displaying them arbitrarily since the ordering is abritrary) do not look much like the actuals.
So, my question / issue is: am I using hlme correctly? Is this a realistic test of this method?