I am trying to calculate standard errors of group means for a two-way-anova. I found two ways to do this (
predict.lm(, se = T) and
set.seed(42234) exmpl <- data.frame(DV = rnorm(40) + rep(3:6 * 10, each = 10), # Dependent Variable IV1 = factor(rep(LETTERS[1:2], each = 20)), # Independent Variable (Treatment) 1 IV2 = factor(rep(rep(LETTERS[3:4], each = 10), 2))) # Independent Variable (Treatment) 2 exmpl.lm <- lm(DV ~ IV1 + IV2, data = exmpl) # Example data was generated without interactions summary(exmpl.lm) as.data.frame(predict(exmpl.lm, data.frame(IV1 = c('A', 'B', 'A', 'B'), IV2 = c('C', 'C', 'D', 'D')), se = T))
The standard errors of some group means differ. I managed to recalculate the standard errors given by
predict() with the explanations from Practical Regression and Anova using R from Faraway (section 3.5). I couldn't find any information about the algorithms used by the
summary() function. Any ideas?
What I find really confusing is that you can change the output by relabelling one factor:
exmpl2 <- exmpl exmpl2$IV1 <- factor(exmpl2$IV1, levels = LETTERS[2:1]) exmpl2.lm <- lm(DV ~ IV1 + IV2, data = exmpl2) summary(exmpl2.lm) summary(exmpl.lm)
In the first example group A-C has a standard error of 0.2013. In the second example the standard error is given as 0.2324. The data of both examples is the same, only the order of the labels of a categorial (not ordinal) variable were changed. How does this influence the statistical model?