I am trying to analyze repeated measures data and am struggling to make it work in R
. My data is essentially the following, I have two treatment groups. Every subject in each group is tested everyday and given a score (the percentage correct on a test). The data is in the long format:
Time Percent Subject Group
1 0 GK11 Ethanol
2 0 GK11 Ethanol
3 0 GK11 Ethanol
4 0 GK11 Ethanol
5 0 GK11 Ethanol
6 0 GK11 Ethanol
The data resembles a logistic curve, subjects do very poorly for a few days followed by rapid improvement, followed by a plateau. I'd like to know if the treatment has an effect on the test performance curve. My thought was to use nlmer()
in the lme4
package in R
. I can fit lines for each group using the following:
print(nm1 <- nlmer(Percent ~ SSlogis(Time,Asym, xmid, scal) ~ Asym | Subject,
salinedata, start = c(Asym =.60, xmid = 23, scal = 5)), corr = FALSE)
I can than compare groups by looking at the estimates for the different parameters and standard deviations of the estimated lines but I'm not sure this is the proper way to do it. Any help would be greatly appreciated.
Best Answer
You can use normal likelihood ratio tests. Here’s a simple example. First, let’s create observations from 10 individuals based on your parameters:
Now let half of them have different asymptotes and midpoint parameters:
We can simulate response values for all the individuals, based on the model:
We can see clear differences between the two groups, differences that the models should be able to pick up. Now let’s first try to fit a simple model, ignoring groups:
Perhaps as expected, the estimates for
Asym
andxmid
are somewhere between the real parameter values for the two groups. (That this would be the case isn’t obvious, though, since the scale parameter is also changed, to adjust for the model misspecification.) Now let’s fit a full model, with different parameters for the two groups:Since the two models are nested, we can do a likelihood ratio test:
The extremely small p-value clearly shows that the simple model was too simple; the two groups do differ in their parameters.
However, the two scale parameters estimates are almost identical, with a difference of just .1. Perhaps we need only need one scale parameter? (Of course we know the answer is yes, since we have simulated data.)
(The difference between the two asymptote parameters is also just .1, but that’s a large difference when we take the standard errors into account – see
summary(fm2)
.)So we fit a new model, with a common
scale
parameter for the two groups, but differentAsym
andxmid
parameters, as before:And since the reduced model is nested in the full model, we can again do a likelihood ratio test:
The large p-value indicates that the reduced model fits as well as the full model, as expected.
We can of course do similar tests to check if different parameter values are needed for just
Asym
, justxmid
or both. That said, I would not recommend doing stepwise regression like this to eliminate parameters. Instead, just test the full model (fm2
) against the simple model (fm1
), and be happy with the results. To quantify any differences, plots will be helpful.