1

I am new to this so please be nice.

I have longitudinal data for my control and group 1. Within control and group 1 I have more groups. e.g person id number. Essentially I want to know the best stats test to compare longitudinal data in my control and my response group.

I've managed to do LMER analysis for my control and group 1 and have found the best model for each of them using ANOVA. Now I have plotted their best models onto a same plot. But I want to analyse whether the plots of group 1 is significantly different to control group. I've again used ANOVA, but I am missing data for this and its not lining up.

now should I be comparing the two plots in a different way? or do something else?

Control

ID Week Response

Group 1

ID Week Response

Some weeks having missing data, and the groups do not have the same number of participants.

museoks
  • 13

1 Answers1

1

Apologies in advance if you specifically want to compare plots, because I don't know about that. But, I assume you have a continuous dependent variable and either continuous or factorial predictor or maybe several predictors. In this case I would compare the two groups statistically by putting them into the same lmer model - e.g. (with one continuous predictor):

model<-lmer(outcome ~ (1|person_id) + group*predictor, data=data) #edited to remove code redundancy

"group" being a factorial variable with two levels, group1 and control. Then, if the group*predictor interaction is significant, you have evidence that outcome ~ predictor relationship is statistically different for group1 vs. control. Then, you can run the simple models of outcome ~ predictor + (1|person_id) separately for each group and report the fixed main effects separately for each group, and also plot the 2 slopes into the same figure.

Edited to respond to your comment: I think you got an output from R looking like this:

Linear mixed model fit by REML. t-tests use Satterthwaite's
  method [lmerModLmerTest]
Formula: outcome ~ (1 | id) + group * predictor
   Data: df

REML criterion at convergence: 851.8

Scaled residuals: Min 1Q Median 3Q Max -2.05211 -0.66622 -0.02345 0.67188 2.56591

Random effects: Groups Name Variance Std.Dev. id (Intercept) 0.004382 0.0662
Residual 0.967369 0.9835
Number of obs: 300, groups: id, 60

Fixed effects: Estimate Std. Error df t value (Intercept) 4.34483 0.32619 295.67804 13.320 group1 -0.84478 0.44085 295.96649 -1.916 predictor -0.08481 0.07839 287.76043 -1.082 group1:predictor 0.19004 0.10647 288.70985 1.785 Pr(>|t|)
(Intercept) <2e-16 *** group1 0.0563 .
predictor 0.2802
group1:predictor 0.0753 .

(this is made based on simulated data with 60 participants and 5 observations per participant. I have no significant effects there, but never mind that).

So, if you look at the "Fixed effects" part, "group1" effect is an effect comparing group 1 to the control group (estimate for "predictor" is the continuous predictor main effect, here non-significant and negative). Because "group" is a factorial effect, it compares one group to another. "Control" is the default to which "group1" is compared to. That's why it is not shown in the output. With a factorial predictor, you always see in the output the number of levels of the predictor minus 1 level - because that's the level the other levels are compared to.

In my mock data, the results suggest that outcome was lower in group1 than in control group, because the estimate is negative, but not significantly so. If your "group1" effect was significant and positive, it suggests that outcome was significantly higher for people in group1 than in control, and vice versa if it was significant and negative. You get estimated marginal means for "control" and "group1" from emmeans package:

library(emmeans)
em<-emmeans(model, specs = pairwise ~ group)

Or, you can of course check and plot raw means by group too.

Of course, if the interaction is significant, you should focus on that more than on "group" main effect. You can for instance plot separate slopes of predictor for each group by using:

library(ggplot2)
library(ggeffects)

preds<-ggpredict(model, c("predictor", "group")) plot1<-ggplot(preds)+geom_line(aes(x=x, y=predicted, color=group)) plot2<-plot1+scale_color_discrete(name="Group", labels=c("Control", "Group1")) plot3<-plot2+labs(x="Predictor", y="Outcome", title="title")

Sointu
  • 1,846
  • Hi, thank you so much for your reply, it means a lot. – museoks Oct 21 '22 at 20:54
  • Technically predictor + group + group*predictor is redundant (but harmless); group*predictor expands to group + predictor + group:predictor (where : denotes the interaction term) – Ben Bolker Oct 22 '22 at 19:40
  • Oops, thank you! I'll edit my answer. – Sointu Oct 23 '22 at 16:40
  • Thank you so much, I'm new to stats and didn't really understand. Should the factor variables be Control and Group 1, or binary numbers such as 0 and 1? For my results, I am only seeing groupControl*Predictor, is the group 1 just inferred or have I done something wrong? I grouped control first and then group 1. – museoks Oct 23 '22 at 17:41
  • Sorry I only see group1*Predictor and not control. Is this inferred or an error? – museoks Oct 23 '22 at 18:16
  • It's as expected. See https://stackoverflow.com/questions/41032858/lm-summary-not-display-all-factor-levels/41033764#41033764 – Ben Bolker Oct 24 '22 at 01:40
  • I'll edit my answer, @museoks – Sointu Oct 24 '22 at 06:09
  • See the edit. Your "group1" estimate is an estimate of how much and into what direction group1 differs from control group. – Sointu Oct 24 '22 at 08:30
  • Hi @Sointu I want to thank you for your help. But I am now stuck on something else. I don't know If I should make a new question or not. I want to now compare if my SLOPE for group 1 is significantly different to the SLOPE of control. I have MAR data and have generated LMER graphs for both my groups. I appreciate your help – museoks Nov 29 '22 at 22:31
  • Hi, I haven't done simple slope testing in R, but there are several suggestions available online, see for instance: https://stats.stackexchange.com/questions/587910/compare-conditional-effects-simple-slope-from-regression-model and https://stats.stackexchange.com/questions/483488/comparing-simple-slopes-with-one-another-in-r – Sointu Nov 30 '22 at 09:22
  • to add: you have a categorical x continuous interaction, right? With 2 levels in the categorical variable, group and control? In such cases, if the interaction is significant, I have simply run the simple models (outcome ~ (1|id) + predictor) separately for each group, and reported the significance of the continuous predictor for each group. – Sointu Nov 30 '22 at 11:41
  • Hi @Sointu I really do appreciate your help. I have continuous X data against Time, but I have this for 2 groups. I have used what you have stated, but am receiving insignificant results. I am unsure how to go forward. – museoks Nov 30 '22 at 20:52
  • Hi @museoks, I'm glad I was able to help a little bit. I think it might be best if you opened a new question and posted your code and output, as well as a description of your current problem. – Sointu Dec 01 '22 at 09:20