
On 13 Dec 2011, at 6:00 AM, r-sig-mixed-models-request@r-project.org wrote:

> Date: Tue, 13 Dec 2011 10:45:54 +0100
> From: Juan Santos <juan.santos@vi.ieo.es>
> To: r-sig-mixed-models@r-project.org
> Subject: [R-sig-ME] glmmADMB definition of levels for random component
> Message-ID: <4EE71ED2.1010902@vi.ieo.es>
> Content-Type: text/plain; charset=ISO-8859-1; format=flowed
> 
> 
> 
> First at all I would like to Thank Ben Bolker for his suggestion on how 
> to install package glmmADMB in Linux, definitely it worked. Now I would 
> ask for some
> issued regarding the mixed model specification on my data.
> 
> As a reminder, say that I'm working with 2003-2010  fishing data 
> (clustered data, Primary sampling unit [PSU]=trip, secondary sampling 
> unit [SSU]=haul);
> Specifically,  I am trying to model the numbers of fishes of a given 
> species thrown back to sea (discarded individuals as the Ultimate 
> sampling Unit [USU]) with a set of available
> covariates. The main aim of  the model is to assess if  yearly increase 
> in discards found in previous EDA,  is also found significant using a 
> formal and well fitted model.  I fitted an starting model using (1| 
> trip/ haul) as random component  (fishing hauls nested on trips, 
> following the hierarchicalsamplingdesign):
> 
> mod.admb.1<-glmmadmb(ndiscarded~year + quarter+deep+duration+ 
> (1|trip/haul), zeroInflation=TRUE,family="nbinom",data=dmod.1)
> 
> (I used zero inflation link  because previous study indicates that a 
> model with zeroInflation=FALSE  does not account for the excess of zeros 
> in the data).
> 
> "Trip" coding is
> 
> dat<-ddply(dat,.(year),function(x){
>         levels(x$trip) <-1:length(levels(x$trip))
>         return(data.frame(x))})
> 
> Meaning that trip levels restarts in every sampled year. Similar 
> approach is used for hauls within trips (hauls coding restarts for every 
> sampled trip).
> 
> But I am not sure of this codification, because using this coding means 
> that I have same trips ID in every year, but obviously  they are not the 
> same trips from one year to another (Perhaps the only similarity is that 
> they are sampled in  same temporal interval each year).  As expected, 
> random coefficients [ranef ()] from mod.admb.1does not  take into 
> consideration that trip number "n" differs between years. I have some 
> ideas to solve this problem:
> 
> a) To recode trip level with not regard of the sampled  year  (using 
> factor(1: N) as levels, being N=total number of trips sampled across the 
> years)
> b) Fit models for each year separately and compare intercepts
> c) use (1|year/trip/haul) as random component,
> 
> Can someone indicate a right practice to deal with this model 
> specification problem ?
> 
> 
> Juan Santos
> Research Technician
> Instituto Espa?ol de Oceanograf?a
> C.O.Vigo
> 
> juan. santos@vi.ieo.es
> 

Hi Juan,
When specifying nested random effects, you can avoid syntax confusion by making sure each level of the random effect has it's own unique label. I got this advice here http://glmm.wikidot.com/faq in the section on nested random effects. 

A shorter version of your data for demonstration could be (5 years, 2 trips per year, 2 hauls per trip):

x=data.frame(year=rep(2000:2004, each=4),trip=rep(rep(1:2,each=2),5),haul=rep(1:2,10))

Then you should create new columns for the unique hauls and unique trips:

x$trip_haul=paste(x$trip, x$haul, sep="_")
x$year_trip=paste(x$year, x$trip,sep="_")

Then, when specifying your model, you can use simple syntax: 

> mod.admb.1<-glmmadmb(ndiscarded~year + quarter+deep+duration+ 
> (1|year_trip)+(1|trip_haul), zeroInflation=TRUE,family="nbinom",data=x)


cheers,
Mollie

Mollie Brooks
Ph.D. Candidate
NSF IGERT Fellow
Biology Department
University of Florida
mbrooks@ufl.edu
http://people.biology.ufl.edu/mbrooks

	[[alternative HTML version deleted]]


