## install.packages("glmmADMB",repos="http://glmmadmb.r-forge.r-project.org/repos",type="source")
library(glmmADMB)
dat1<-read.csv("stain.csv")
## attach(dat1) ## dangerous
names(dat1)
dat1<-transform(dat1,
                Site=factor(Site),
                ## BMB: fixed typo
                Log.code=factor(Log.code),
                Caged=factor(Caged),
                beetle.ev=factor(beetle.ev),
                Test=factor(Test))
## BMB: this could also be done via colClasses= argument to read.csv
nbin1<-glmmadmb(stainp~beetle.ev+Caged*Section/Segment+(1|Site)+(1|Log.code),data=dat1,family="nbinom",
                verbose=TRUE)

nbin1B<-glmmadmb(stainp~beetle.ev+Caged*Section/Segment+Site+(1|Log.code),data=dat1,family="nbinom",
                verbose=TRUE)

## install.packages("coefplot2",repos="http://r-forge.r-project.org")
coefplot2(nbin1B)
library(ggplot2)
ggplot(dat1,aes(x=beetle.ev:Caged,y=stainp,colour=Site))+
    stat_sum(aes(size=..n..),alpha=0.5)+
  facet_grid(Segment~Section)+opts(panel.margin=unit(0,"lines"))

summary(nbin1)

nbin2<-glmmadmb(stainp~Test+Caged*Section/Segment+(1|Site)+(1|Log.code),data=dat1,family="nbinom")
summary(nbin2)
library(coefplot2)
coefplot2(nbin2)
VarCorr(nbin2)
