[R] Coeficients estimation in a repeated measures linear model

Sergio PV serpalma.v at gmail.com
Wed Dec 6 15:17:14 CET 2017


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]]



More information about the R-help mailing list