R is very confusing on this, in that the contrasts
operations define how to code factors in the model matrix; but unless those contrasts are orthonormal, the resulting regression coefficients will not be estimates of those contrasts!
Assuming that you do want estimates of the contrasts you show, I suggest you do this (having previously installed the lsmeans package):
# save your contrast coefficients as a list
my.contr <- list(c1 = c1, c2 = c2, c3 = c3, c4 = c4)
# get rid of those contrast specs
contrasts(bats$Position) <- NULL
# fit your model using the default factor coding
model2b <- lmer(logActivity ~ Ecotone*Position + (1|Site), data=bats)
# Obtain the LS means
require("lsmeans")
model2b.lsm <- lsmeans(model2b, ~ Position | Ecotone)
model2b.lsm
# Estimate the contrasts you specified
contrast(model2b.lsm, my.contr)
The code above will do the MSLS means and contrasts separately at each level of Ecotone
. You can do them marginally (averaged over Ecotone
) by omitting the | Ecotone
spec in the lsmeans()
call. However, your model specifies that the two factors interact, and it is often not meaningful to examine marginal means unless the interaction is negligible.
Actually, you will get the same LS means and contrasts even if you apply these procedures to your model2a
. I'm just emphasizing that estimating the contrasts of LS means has nothing to do with the contrasts()
coding that is used.