[R] contrasts for lmer model
Kay Cichini
Kay.Cichini at uibk.ac.at
Wed May 19 13:36:40 CEST 2010
hello,
i found it most convenient to use package contrast for planned comparisons
on mixed models.
for instance i have a model with 2 fixed factors, one with 4 levels (stage)
and one with 2 levels (gap) and a nested random factor (site) and i tested
gap within level A of factor stage:
library(contrast)
library(nlme)
m1<-lme(rich ~ stage*gap, random=~1|site,data=richness)
contrast(m1,
a = list(stage="A",gap="0"),
b = list(stage="A",gap="1"))
..this works fine. now i wont to do the same with lmer() because the
response is a count - but this doesn't work with contrast():
library(lme4)
detach(package:nlme)
m2<-lmer(rich ~ stage*gap+(1|site),family=poisson,data=richness)
contrast(m2,
a = list(stage="A",gap="0"),
b = list(stage="A",gap="1"))
Error in UseMethod("contrast") :
no applicable method for 'contrast' applied to an object of class "mer"
i tried with glht() from multcomp, but was not able to set it up right -
could anyone please help me with how this sort of contrast is produced with
glht()?
thanks for any help,
kay
my data:
richness<-data.frame(list(structure(list(stage = structure(c(1L, 1L, 1L, 1L,
1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,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 26L, 26L, 26L, 26L, 27L, 27L, 27L, 27L, 28L,
28L, 28L, 28L, 29L, 29L, 29L, 30L, 30L, 30L, 30L, 31L, 31L, 32L,
32L, 32L, 32L, 33L, 33L, 33L, 33L, 34L, 34L, 34L, 34L, 35L, 35L,
35L, 35L, 36L, 36L, 36L, 36L, 37L, 37L, 38L, 38L, 38L, 38L, 39L,
39L, 39L, 39L, 2L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 3L, 3L, 3L, 3L,
4L, 4L, 4L, 4L, 5L, 6L, 6L, 6L, 6L, 7L, 7L, 7L, 8L, 8L, 8L, 8L,
9L, 9L, 9L, 9L, 10L, 10L, 10L, 10L, 11L, 11L, 11L, 11L, 12L,
12L, 12L, 12L, 13L, 13L, 13L, 14L, 14L, 14L, 14L, 15L, 15L, 15L,
15L, 16L, 16L, 16L, 16L, 17L, 17L, 17L, 17L, 18L, 18L, 19L, 19L,
19L, 19L, 20L, 20L, 20L, 20L, 21L, 21L, 21L, 21L, 22L, 22L, 22L,
22L, 23L, 23L, 23L, 24L, 24L, 24L, 24L, 25L, 25L, 25L, 25L, 26L,
26L, 26L, 26L, 27L, 27L, 27L, 27L, 28L, 28L, 28L, 28L, 29L, 29L,
29L, 30L, 30L, 30L, 30L, 31L, 31L, 32L, 32L, 32L, 32L, 33L, 33L,
33L, 33L, 34L, 34L, 34L, 34L, 35L, 35L, 35L, 35L, 36L, 36L, 36L,
36L, 37L, 37L, 38L, 38L, 38L, 38L, 39L, 39L, 39L, 39L), .Label = c("A11",
"A12", "A14", "A15", "A16", "A17", "A18", "A19", "A20", "A5",
"A7", "A8", "B1", "B12", "B13", "B14", "B15", "B17", "B18", "B2",
"B4", "B7", "B8", "B9", "C1", "C10", "C11", "C15", "C17", "C18",
"C19", "C2", "C20", "C3", "C4", "C6", "D1", "D4", "D7"), class = "factor"),
gap = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L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, 4L, 3L, 3L, 5L, 9L, 4L, 5L, 6L, 7L,
4L, 5L, 4L, 7L, 4L, 6L, 5L, 2L, 3L, 2L, 6L, 1L, 4L, 5L, 6L,
3L, 5L, 4L, 4L, 3L, 2L, 4L, 1L, 4L, 3L, 4L, 3L, 6L, 2L, 9L,
8L, 10L, 5L, 7L, 10L, 7L, 7L, 4L, 5L, 5L)), .Names = c("stage",
"site", "gap", "rich"), class = "data.frame", row.names = c(NA,
-286L))))
-----
------------------------
Kay Cichini
Postgraduate student
Institute of Botany
Univ. of Innsbruck
------------------------
--
View this message in context: http://r.789695.n4.nabble.com/contrasts-for-lmer-model-tp2222682p2222682.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list