> #7.8 Milk Bacteria Example > x<-rbind( + c(0, 56), + c(1, 104), + c(2, 80), + c(3, 62), + c(4, 42), + c(5, 27), + c(6, 9), + c(7, 9), + c(8, 5), + c(9, 3), + c(10, 2), + c(11, 1)) > > #Negative-binomial class probabilities from Jarvis (1989, p50) > #note the table on page 7.2 is incorrect > expected<-c(60.88,90.76,85.16,64.12,42.32,25.58,14.49,7.85,4.09,2.07,1.02,1.66) > tab<-cbind(x[,2],expected) > colnames(tab)<-c("Observed","Expected") > rownames(tab)<-x[,1] > tab Observed Expected 0 56 60.88 1 104 90.76 2 80 85.16 3 62 64.12 4 42 42.32 5 27 25.58 6 9 14.49 7 9 7.85 8 5 4.09 9 3 2.07 10 2 1.02 11 1 1.66 > > #totals & plot > apply(tab,2,sum) Observed Expected 400 400 > barplot(t(tab),beside=T,legend.text=c("Observed","Expected")) > > #DDR and plot > ddr<-sqrt(4*tab[,1]+2)-sqrt(4*tab[,2]+2) > ddr[tab[,1]==0]<-1-sqrt(4*tab[,2]+1)[tab[,1]==0] > plot(x[,1],ddr,xlab="Category",ylab="DDR",type="n") > points(x[,1],ddr,cex=2) > > #gof stuff - note have to specify how many parameters were estimated > #Note here attribute the estimated parameters to solving for the location/scale components to be zero > GOF(tab,q=2,qcomps=c(1,2)) Note 2 parameters were estimated to calculate expected values The particular component indices given zero df to compensate are: 1 2 This information is only used to calculate partition dfs and p-values $AndersonDarling [1] 0.3152322 $Vr [1] -0.1079944 0.3685941 0.4063124 -1.2799103 -0.2240622 -1.6235069 [7] 0.7291098 -0.2663582 -0.6055996 -0.4172515 1.0388703 $partition df SS pvalue Location 0 0.0116628 NA Dispersion 0 0.1358616 NA Skewness 1 0.1650898 0.6845131 Kurtosis 1 1.6381705 0.2005767 Residual 7 4.9086275 0.6711129 Total 9 6.8594122 0.6517539 >