model.matrix (): Warum verliere ich in diesem Fall die Kontrolle über den Kontrast?
Angenommen, wir haben einen Spielzeugdatenrahmen:
x <- data.frame(x1 = gl(3, 2, labels = letters[1:3]),
x2 = gl(3, 2, labels = LETTERS[1:3]))
Ich möchte eine Modellmatrix erstellen
# x1b x1c x2B x2C
# 1 0 0 0 0
# 2 0 0 0 0
# 3 1 0 1 0
# 4 1 0 1 0
# 5 0 1 0 1
# 6 0 1 0 1
durch
model.matrix(~ x1 + x2 - 1, data = x,
contrasts.arg = list(x1 = contr.treatment(letters[1:3]),
x2 = contr.treatment(LETTERS[1:3])))
aber eigentlich bekomme ich:
# x1a x1b x1c x2B x2C
# 1 1 0 0 0 0
# 2 1 0 0 0 0
# 3 0 1 0 1 0
# 4 0 1 0 1 0
# 5 0 0 1 0 1
# 6 0 0 1 0 1
# attr(,"assign")
# [1] 1 1 1 2 2
# attr(,"contrasts")
# attr(,"contrasts")$x1
# b c
# a 0 0
# b 1 0
# c 0 1
# attr(,"contrasts")$x2
# B C
# A 0 0
# B 1 0
# C 0 1
Ich bin hier irgendwie verwirrt:
Ich habe eine explizite Kontrastmatrix übergeben, um die ersten Faktorstufen zu senken.Ich habe darum gebeten, Intercept fallen zu lassen.Warum bekomme ich dann eine Modellmatrix mit 5 Spalten? Wie kann ich die gewünschte Modellmatrix erhalten?