[R-sig-ME] random slopes and intercepts using glmmadmb - negative binomial
Ben Bolker
bbolker at gmail.com
Wed Oct 9 23:50:41 CEST 2013
Bayes Student <bayes.student at ...> writes:
>
> Hello,
> I am new to mixed modeling and using the glmmadmb package. I am interested
> in using glmmadmb to model count data with a negative binomial
> distribution, using year and site sampled as my random
> effect variables, as
> both should be allowed to vary independently. I would like to consider
> random intercepts for both factors, but also random
> slopes for sites across
> all years. I am not sure how to code this in R, and have tried several
> different ways. Usually R just takes a super long time and
> does not seem to
> complete the computation - which leads me to think my syntax is incorrect.
> Any suggestions/ thoughts would be greatly appreciated!
> I'm using Windows 7
> with RStudio v.0.98.312.
The version of R and glmmADMB are more relevant than the version of
RStudio, for what it's worth.
>
> Here is what works - random intercepts model:
>
> mod <- glmmadmb(species~(1|year)+(1|site),data=cs,
> family="nbinom2",link="log")
>
> Here are some iterations I have tried which did not seem to work:
>
> mod <- glmmadmb(species~(1+site|year)+(1|site),data=cs,...)
> mod <- glmmadmb(species~(site|year)+(1|site),data=cs,...)
> mod <- glmmadmb(species~(1|year)+(1|site)+(0|site),data=cs,...)
>
[snip]
I think you're looking for species ~ year + (1|year) + (year|site) ,
equivalent to species ~ year + (1|year) + (1+year|site)
In the syntax (A|B), B is the *grouping variable* and A represents
the factor or factors that vary among groups. The slight oddity
of this model is that year appears three times, once as a main effect
(the overall log-linear effect of year), once as a grouping variable
(the year-by-year variation across all sites around the log-linear
trend) and once as a random effect (the random variation of log-linear
trend among sites).
More information about the R-sig-mixed-models
mailing list