[R-sig-ME] multilevel nested data in lmer models

Hallstrom, Wayne (Calgary) Wayne.Hallstrom at WorleyParsons.com
Fri Feb 23 03:14:14 CET 2007


OK finally back to work on this.
I am using:

R-2.4.0-win32.exe

Package: lme4
Version: 0.9975-10
Date: 2006-12-01

I was having trouble with the program not recognizing the appropriate
structure in the dataset, and claiming that there were 'too many
groups'. I followed the advice of D M Bates to assess the dataset
structure, and found the following:
> str(FEall)
'data.frame':   1230 obs. of  20 variables:
 $ InOut      : Factor w/ 2 levels "in","out": 1 1 1 1 1 1 1 1 1 1 ...
 $ FenceEnd   : Factor w/ 7 levels "1e","1w","de",..: 1 1 1 1 1 1 1 1 1
1 ...
 $ FEsectn    : int  1 1 1 1 1 1 1 1 1 1 ...
 $ MIT_UNMIT  : Factor w/ 2 levels "mit","unmit": 1 1 1 1 1 1 1 1 1 1
...
 $ YEAR       : int  1985 1986 1987 1988 1989 1990 1991 1992 1993 1994
...
 $ BLAC       : int  NA NA NA NA NA NA NA NA NA NA ...
 $ COUG       : int  NA NA NA NA NA NA NA NA NA NA ...
 $ COYO       : int  NA NA NA NA NA NA NA NA NA NA ...
 $ deer       : int  NA NA NA NA NA NA NA 1 NA NA ...
 $ ELK        : int  NA NA NA NA NA NA 1 NA NA NA ...
 $ GRIZ       : int  NA NA NA NA NA NA NA NA NA NA ...
 $ LYNX       : int  NA NA NA NA NA NA NA NA NA NA ...
 $ MOOS       : int  NA NA NA NA NA NA NA NA NA NA ...
 $ SHEE       : int  NA NA NA NA NA NA NA NA NA NA ...
 $ WOLF       : int  NA NA NA NA NA NA NA NA NA NA ...
 $ WOLV       : int  NA NA NA NA NA NA NA NA NA NA ...
 $ carn.coyo  : int  0 0 0 0 0 0 0 0 0 0 ...
 $ carn       : int  0 0 0 0 0 0 0 0 0 0 ...
 $ ung        : int  0 0 0 0 0 0 1 1 0 0 ...
 $ Grand.Total: int  0 0 0 0 0 0 1 1 0 0 ...

>From this I noted that FEsectn was not registered as a factor and so I
changed it into one, after which the model structure worked fine. Seems
that problem is solved.
> FEsection<-factor(FEsectn)
> m0 <- lmer(carn ~ 1 + (1|FenceEnd/FEsection/MIT_UNMIT),
family=quasipoisson(link = "log"))
> m00 <- lmer(ung ~ 1 + (1|FenceEnd/FEsection/MIT_UNMIT),
family=quasipoisson(link = "log"))
> summary(m0)@AICtab
     AIC      BIC   logLik deviance
 313.374 333.8330 -152.687  305.374


However, I now have the problem that some of the groups in this model
definition are formed by the treatment variable MIT_UNMIT (fencing or no
fencing on highway to exclude wildlife). I need some advice on how to
deal with this in the model, for example is this model m1 valid? I have
the idea maybe it is not, but how else do I go about finding the effect
coefficient for the MIT_UNMIT variable, or the FEsection variable?

m1 <- lmer(carn ~ MIT_UNMIT + (1|FenceEnd/FEsection/MIT_UNMIT),
family=quasipoisson(link = "log"))

To give some context, 5 segments of wildlife exclusion fencing were
built over a period of 25 years, some contiguous and some not, resulting
in 7 different fence ends existing at different times. All roadkill was
recorded both before and after the fencing. Yearly wildlife roadkills
counts were assigned by UTM map location to each of 10 500m long
segments around each fence end, with 5 of these 'inside' the fence and 5
'outside'. I am trying to determine whether fence ends constitute a
significant source of wildlife mortality postfencing by examining
intersegment and pre/post treatment distribution of roadkill at each
fence end versus that afterwards.

I had examined this using an MSExcel-based G-test with STP since that
method allowed exact definition of how wildlife mortality differs
between highway segments, and it allowed me to subsequently match the
results to the local topography etc. I had run tests for each fence end
individually, but then it was suggested that I try this method in order
to generalize the results of overall FenceEnd effect(it was 4 with a FE
effect and 3 without...). As I am not very familiar with the LMER
procedure and am a bit stuck here I could use some advice.

Thank you for your time,
Wayne Hallstrom



======================================

-----Original Message-----
From: dmbates at gmail.com [mailto:dmbates at gmail.com] On Behalf Of Douglas
Bates
Sent: Thursday, February 15, 2007 3:33 PM
To: Hallstrom, Wayne (Calgary)
Cc: r-sig-mixed-models at r-project.org
Subject: Re: [R-sig-ME] multilevel nested data in lmer models

On 2/15/07, Hallstrom, Wayne (Calgary)
<Wayne.Hallstrom at worleyparsons.com> wrote:
> I have what should be a simple question about structure of the formula

> for an lmer model. However, I can find no detailed description of how 
> to write multilevel nested formulas for lmer though so I need some
advice.
>
> Count data were collected at 10 subsample locations nested within each

> of 7 general locations over a 20 year period of repeated measures. At 
> each of the 7 general locations there was a treatment applied partway 
> through the 20 year period to 1/2 of the subsample locations.
>
> I thought running the lmer routine with the following general formula 
> setup would account for the fixed effects of the treatment and the 
> random effects of the nesting structure. A Quasipoisson distribution 
> was used to account for over/underdispersed data.
>
> model1 <- lmer(count ~ a + (1 | b / c), dataset)
>
> This model returns an error message though - "too many groups, only 
> the first is used".  I thought this formula should account for the 
> grouped and nested data structure. I have used this model structure 
> with a different dataset and a similar lmer model and it worked fine, 
> nesting the one explanatory variable within the other in the proper 
> arrangement and producing reasonable results. This time it does not 
> work. Is there a different way the formula should be set up?

Could you show us the structure of the data set (use

str(dataset)

and a transcript of your attempt to fit the model?  The reason I ask is
because I don't think that error message occurs in the lme4 package.  I
just did a quick check on both the R and the C sources and I can't find
it.

Also please include the output of

sessionInfo()

in your message so we know what versions of various packages you are
using.

> Someone with more background in this method must have had a similar 
> problem before while using this lmer routine, so hopefully another 
> perosn on the list can describe/advise how to deal with this kind of 
> nested data and what may be the problem here...
>
>
>
> Thank you,
>
> Wayne Hallstrom
>
> *** WORLEYPARSONS GROUP NOTICE ***
> "This email is confidential.  If you are not the intended recipient,
you must not disclose  or  use the  information  contained in it.  If
you have received this email in error,  please notify us immediately by
return email and delete the email and any attachments. Any personal
views or opinions expressed by the writer may not necessarily reflect
the views or opinions of any company in the WorleyParsons Group of
Companies."
>
>         [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-mixed-models at r-project.org mailing list 
> https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models
>
*** WORLEYPARSONS GROUP NOTICE ***
"This email is confidential.  If you are not the intended recipient, you must not disclose  or  use the  information  contained in it.  If you have received this email in error,  please notify us immediately by return email and delete the email and any attachments. Any personal views or opinions expressed by the writer may not necessarily reflect the views or opinions of any company in the WorleyParsons Group of Companies."




More information about the R-sig-mixed-models mailing list