[R-sig-ME] Repeated measures with a non-linear time effect

Jörg Albrecht albrechj at staff.uni-marburg.de
Thu Jul 21 22:47:22 CEST 2016


Hi Dan,

that was a misunderstanding. I meant you should code time as a factor and run a modified version of the model (see code below).

library(lme4)
library(lattice)
library(multcomp)

df <- data.frame(subject = rep(c("T1", "T2", "T3", "C1", "C2", "C3"), 3),
                 group = rep(c(rep("T", 3), rep("C", 3)), 3),
                 time = c(rep(1, 6), rep(2, 6), rep(3, 6)),
                 measure = c(0, 253, 155, 16, 232, 251, 1035, 1014, 760, 98, 239, 87, 371, 60, 47, 0, 260, 190),
                 col = rep(c(rep("red", 3), rep("blue", 3)), 3), stringsAsFactors = FALSE)
df$time <- as.factor(df$time)
xyplot(measure ~ time|subject, data = df)

# using the lme4 package
fit <- lmer(measure ~ time * group + (1|subject), data = df)
summary(fit)
cftest(fit)

# using anova
fit <- aov(measure ~ time * group + Error(subject), data = df)
summary(fit)

Both models are able to detect the interaction between treatment and time.

Hope this helps.

Best,

Jörg

—
Jörg Albrecht, PhD
Postdoctoral researcher
Institute of Nature Conservation
Polish Academy of Sciences
Mickiewicza 33
31-120 Krakow, Poland
www.carpathianbear.pl <http://www.carpathianbear.pl/>
www.globeproject.pl <http://www.globeproject.pl/>
www.iop.krakow.pl <http://www.iop.krakow.pl/>
> Am 21.07.2016 um 21:50 schrieb Daniel Rubi <daniel_rubi at ymail.com>:
> 
> Hi Jörg,
> 
> Unfortunately setting time as integer doesn't change anything whereas setting it as a factor means that the number of random effects will be equal to the number of samples.
> 
> Perhaps this is an alternative:
> fit1 <- gls(measure~time*group,correlation=corSymm(form=~1|subject),weight=varIdent(form=~1|time),data=df)
> 
> as it does capture the group and interaction effects but I think I need to contrast it with a null model and I'm not sure what would that null model be.
> 
> Any idea?
> 
> 
> 
> On Thursday, July 21, 2016 3:27 PM, Jörg Albrecht <albrechj at staff.uni-marburg.de> wrote:
> 
> 
> Hi Dan,
> 
> most likely the model treats your time covariate as a continuous predictor. Try str(df), then time should appear as integer (int). If you specify time as a factor (with three levels: 1, 2, 3) the model will be able to estimate the time x treatment interaction separately for each time point. However, you still have to decide whether treating time as a factorial variable makes sense for your dataset.
> 
> Best,
> 
> Jörg
> 
> 
> > Am 21.07.2016 um 20:13 schrieb Daniel Rubi via R-sig-mixed-models <r-sig-mixed-models at r-project.org <mailto:r-sig-mixed-models at r-project.org>>:
> > 
> > Hi,
> > I have repeated measures from two groups (treatment and control), three subjects in each, over three time points.
> > 
> > Here's the data in an R data.frame:df <- data.frame(subject=rep(c("T1","T2","T3","C1","C2","C3"),3), group=rep(c(rep("T",3),rep("C",3)),3), time=c(rep(1,6),rep(2,6),rep(3,6)), measure=c(0,253,155,16,232,251,1035,1014,760,98,239,87,371,60,47,0,260,190), col=rep(c(rep("red",3),rep("blue",3)),3), stringsAsFactors=F)
> > 
> > 
> > The plot shows the time x group interaction:
> > 
> > R code for producing the plot:
> > plot(df$time,df$measure,col=df$col,xlab="time",ylab="measure")
> > legend("topleft",legend=c("treatment","control"),col=c("red","blue"),pch=1)
> > 
> > 
> > My question is what model to use to capture the time x group interaction.
> > I thought:library(lmerTest)fit <- lmer(measure~time+group+time*group+(time|subject),data=df)
> > might do it.
> > But the summary of this model doesn't really capture that:> summary(fit)Linear mixed model fit by REMLt-tests use Satterthwaite approximations to degrees of freedom ['lmerMod']Formula: measure ~ time + group + time * group + (time | subject) Data: df
> > REML criterion at convergence: 210
> > 
> > Scaled residuals: 
> >    Min    1Q Median    3Q    Max 
> > -1.228 -0.448 -0.163  0.275  1.923
> > 
> > Random effects:
> >  Groups  Name        Variance Std.Dev. Corr
> >  subject  (Intercept) 0.00e+00 0.00e+00    
> >          time        3.06e-16 1.75e-08  NaN
> >  Residual            1.05e+05 3.25e+02    
> > Number of obs: 18, groups:  subject, 6
> > 
> > Fixed effects:
> >            Estimate Std. Error    df t value Pr(>|t|)
> > (Intercept)  168.89    286.35  13.78    0.59    0.56
> > time          -8.17    132.55  13.78  -0.06    0.95
> > groupT        218.33    404.96  13.78    0.54    0.60
> > time:groupT    19.83    187.46  13.78    0.11    0.92
> > 
> > Correlation of Fixed Effects:
> >            (Intr) time  groupT
> > time        -0.926              
> > groupT      -0.707  0.655      
> > time:groupT  0.655 -0.707 -0.926
> > 
> > 
> > So my question is what model to use?
> > 
> > Thanks a lot,Dan
> > 
> > <Rplot.png>_______________________________________________
> 
> > R-sig-mixed-models at r-project.org <mailto:R-sig-mixed-models at r-project.org> mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models <https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models>
> 
> 


	[[alternative HTML version deleted]]



More information about the R-sig-mixed-models mailing list