[R] Coeficients estimation in a repeated measures linear model

Jim Lemon drjimlemon at gmail.com
Wed Dec 6 22:21:24 CET 2017


Hi Sergio,
You seem to be aiming for a univariate repeated measures analysis.
Maybe this will help:

subno<-rep(1:6,2)
dat <- data.frame(subno=rep(1:6,2),,vals = c(ctrl, ttd),
   cond = c(rep("ctrl", 6), rep("ttd", 6)), ind = factor(rep(1:6, 2)))
fit<-aov(vals~ind+cond+Error(subno),data=dat)
fit
summary(fit)

Note that the assumptions of this model are easy to violate.

Jim


On Thu, Dec 7, 2017 at 1:17 AM, Sergio PV <serpalma.v at gmail.com> wrote:
> Dear Users,
>
> I am trying to understand the inner workings of a repeated measures linear
> model. Take for example a situation with 6 individuals sampled twice for
> two conditions (control and treated).
>
> set.seed(12)
> ctrl <- rnorm(n = 6, mean = 2)
> ttd <- rnorm(n = 6, mean = 10)
> dat <- data.frame(vals = c(ctrl, ttd),
>                   group = c(rep("ctrl", 6), rep("ttd", 6)),
>                   ind = factor(rep(1:6, 2)))
>
> fit <- lm(vals ~ ind + group, data = dat)
> model.matrix(~ ind + group, data = dat)
>
> I am puzzled on how the coeficients are calculated. For example, according
> to the model matrix, I thought the intercept would be individual 1 control.
> But that is clearly not the case.
> For the last coeficient, I understand it as the mean of all differences
> between treated vs control at each individual.
>
> I would greatly appreciate if someone could clarify to me how the
> coefficients in this situation are estimated.
>
> Thanks
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list