library(ggplot2)
library(glmmADMB)
library(lme4)
library(car)
library(captioner)
source("/Users/Ang/summarySE_function.R") #load summary SE function from Rcookbook
source("/Users/Ang/overdisp_func.R") #Load  DS's overdispersion function
source("/Users/Ang/table_figs_count_function.R")

Pooling detritivore Diptera

# Sum detritivore Diptera (excluding Tanypodinae and Diptera E, a piercer):
clr$Detridipt<-clr$Syrphid+clr$Psychodid+clr$Chiron+clr$CeratopogAB+clr$Odontomyia+clr$DipteraA+clr$DipteraB+clr$DipteraD+clr$DipteraF+clr$DipteraG+clr$DipteraH+clr$DipteraI+clr$DipteraJ

## [1] "Figure  1: Forest size effects on non-shredder detritivores.Bars are standard errors of the mean"

Leaf litter and Forest Size effects

## [1] "Figure  2: Detritus and forest size effects. Bars are standard errors of the mean)"

Effects of Forest Size accross sampling Times

(Bars are standard errors)

## [1] "Figure  3: Time and forest size effects on non-shredder detritivores"

Stats

dipt.glmer<-glmer(Detridipt^0.5~Leaves*Size*Time+(1|Site),data=clr,family=poisson,control=glmerControl(optimizer="bobyqa")) #sq.root abundance
plot(resid(dipt.glmer))

qqnorm(resid(dipt.glmer))

overdisp_fun(dipt.glmer) 
##        chisq        ratio          rdf            p 
## 7.055131e+02 1.927632e+00 3.660000e+02 8.550187e-24
#ratio p=1.9 some o.d
Anova(dipt.glmer)
## Analysis of Deviance Table (Type II Wald chisquare tests)
## 
## Response: Detridipt^0.5
##                     Chisq Df Pr(>Chisq)    
## Leaves             7.0859  1   0.007769 ** 
## Size               4.2322  2   0.120500    
## Time             105.9522  1  < 2.2e-16 ***
## Leaves:Size        0.0109  2   0.994543    
## Leaves:Time        2.2901  1   0.130201    
## Size:Time          9.0888  2   0.010626 *  
## Leaves:Size:Time   7.8954  2   0.019299 *  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Better fitting, same results with glmmADMB

dipt.glmmADMB <- glmmadmb(Detridipt~Leaves*Size*Time+(1|Site),data=clr,family="nbinom")
overdisp_fun(dipt.glmmADMB)
##       chisq       ratio         rdf           p 
## 308.0739637   0.8417321 366.0000000   0.9874774
plot(resid(dipt.glmmADMB)~fitted.values(dipt.glmmADMB))

Anova(dipt.glmmADMB)
## Analysis of Deviance Table (Type II tests)
## 
## Response: Detridipt
##                   Df  Chisq Pr(>Chisq)   
## Leaves             1 4.6031   0.031914 * 
## Size               2 4.3136   0.115694   
## Time               1 7.4867   0.006216 **
## Leaves:Size        2 8.4249   0.014810 * 
## Leaves:Time        1 1.9996   0.157342   
## Size:Time          2 5.9791   0.050309 . 
## Leaves:Size:Time   2 8.1593   0.016913 * 
## Residuals        365                     
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

=> Detritivores are more abundant in small patches through interaction with late time and native leaf litter