SLIDE 7
2.1. Simulated Residuals
> simRes <- function(lambda, Y,n=250, plot=T, family='negbin', size=NULL,theta=NULL) { + require(gap) + N = length(Y) + sim = switch(family, + 'poisson' = matrix(rpois(n*N,apply(lambda,2,mean)),ncol=N, byrow=TRUE), + 'negbin' = matrix(MASS:::rnegbin(n*N,apply(lambda,2,mean),size),ncol=N, byrow=TRUE), + 'zip' = matrix(gamlss.dist:::rZIP(n*N,apply(lambda,2,mean),theta),ncol=N, byrow=TRUE), + 'zinb' = matrix(gamlss.dist:::rZINBI(n*N,apply(lambda,2,mean),sigma=theta,nu=size),ncol=N, + byrow=TRUE) + ) + a = apply(sim + runif(n,-0.5,0.5),2,ecdf) + resid<-NULL + for (i in 1:length(Y)) resid<-c(resid,a[[i]](Y[i] + runif(1 ,-0.5,0.5))) + if (plot==T) { + par(mfrow=c(1,2)) + gap::qqunif(resid,pch = 2, bty = "n", + logscale = F, col = "black", cex = 0.6, main = "QQ plot residuals", + cex.main = 1, las=1) + plot(resid~apply(lambda,2,mean), xlab='Predicted value', ylab='Standardized residual', las=1) + } + resid + }
2.2. ggplot goodness
> library(ggplot2) > theme_goodness <- theme_classic() + + theme(axis.line.x=element_line(), axis.line.y=element_line())
2.3. MCMC summaries
> MCMCsum <- function(x) { + data.frame(Mean=mean(x), median=median(x), HPDinterval(as.mcmc(x))) + } > MCMCsummaries <- function(fit) { + plyr:::adply(fit, 2, MCMCsum) + }
3.1. Poisson t-test
Format of limpets.csv data files Count Shore 1 sheltered 3 sheltered 2 sheltered 1 sheltered 4 sheltered . . .