[R-sig-ME] GLMM Q: Categorical fixed effects with more than 2 levels
pauljohn32 at gmail.com
Sun Jul 22 01:19:05 CEST 2012
On Sat, Jul 21, 2012 at 9:24 AM, Julie Kern <juliekern27 at googlemail.com> wrote:
> I’m running a lmm (with lme) to investigate the influence of several
> fixed effects on call rate. The model also includes the random terms
> of group & individual identity. Several of my fixed effects are
> categorical & some have more than 2 categories (up to 5). E.g. The
> fixed effect habitat contains the categories ‘open’, ‘medium’ &
> ‘dense’. The model has shown habitat to be a significant predictor of
> call rate, but I would now like to test the differences between these.
> E.g. Are call rates in open, medium & dense habitats different from
> each other? I am unsure how best to go about this as I still have to
> take into account repeated measures from the same individuals & groups
> so don’t think I can simply use a Wilcoxon signed-rank test.
I don't think there is an 'honestly significant difference' test that
can check whether the 3 are different from each other. However, I
think you could ask a more specific comparison, such as "does it make
a difference if I assume the effects of open and medium are the same
as the effect of dense"?
You can create a new factor variable that recodes open and medium to
be the same thing. I find the procedure to do that is difficult to
describe to my students. To make that easier, I have a little package
of regression tools called "rockchalk". It has in there a function
combineLevels. you could run (if dat is the data frame)
dat$hab2 <- combineLevels(dat$habitat, levs = c("open", "medium"),
newLabel = c("oOrMed"))
if you run that model again, replacing habitat by hab2, then the anova
function will calculate a likelihood ratio test to check if you have
lost explanatory power by fixing the coefficients of open and medium
to be the same.
now, if you have a 5 level variable, say
c("lo","lom","medium","mhi","hi"), and you want to reduce the model
to a comparison that combines "lo" and "lom" versus
"medium","mhi","hi", you have to run combineLevels twice, first
putting together "lo" and "lom" and then "medium", "mhi", "hi".
You aren't required to do that with rockchalk, but otherwise you have
a somewhat conceptually difficult series of steps.
1. Take the levels of the existing variable,
2. Add the new level for the combined category
3. Create a new factor variable that uses the new levels object
4. Reassign the cases to the new label.
If the factor is ordinal, then this is a little spicy to splice the
new one into the levels list at the right spot. But you can see how
if you read the code for combineLevels.
> Any advice would be greatly appreciated, I'm new to R & have spent a
> long time searching for this on the web but am going round in ever
> more confusing circles!
> Thank you!
> R-sig-mixed-models at r-project.org mailing list
Paul E. Johnson
Professor, Political Science Assoc. Director
1541 Lilac Lane, Room 504 Center for Research Methods
University of Kansas University of Kansas
More information about the R-sig-mixed-models