\section{Population-wide test for heterozygosity}

\noindent

<<echo=FALSE, results='hide'>>=
het_obs<-as.data.frame(t(sumcats$Hobs))
rownames(het_obs)<-"Observed"
colnames(het_obs)<-locNames(cats)
het_obs<-as.data.frame(t(het_obs))
het_obs$Locus<-rownames(het_obs)

het_exp<-as.data.frame(t(sumcats$Hexp))
rownames(het_exp)<-"Expected"
colnames(het_exp)<-locNames(cats)
het_exp<-as.data.frame(t(het_exp))
het_exp$Locus<-rownames(het_exp)

het_comb<-merge(het_exp,het_obs,by="Locus")
het_comb[,4]<-(het_comb[,2]-het_comb[,3])/het_comb[,2]*100
colnames(het_comb)[4]<-"% difference"
pop_het_table<-xtable(het_comb, cap="The population-wide expected and observed heterozygosity and percent difference ((E-O)/E*100) at each locus",digits=3)
write.csv(het_comb, paste(cats@other$filename,"-exp_obs_hz.csv", sep=""), row.names=TRUE)
@


<<echo=FALSE,results='asis'>>=
print(pop_het_table,include.rownames=FALSE, add.to.row=list(list(seq(1,nrow(het_comb),2)),"\\rowcolor[gray]{0.9} "))

# for future iterations consider replacing with the tests located here:
# http://www.sph.umich.edu/csg/abecasis/Exact/index.html
popbart<-bartlett.test(list(sumcats$Hexp,sumcats$Hobs))
@
\noindent
Bartlett test of homogeneity of variance. This test compares observed vs. expected heterozygosity. A significant result indicates that the population departs from HWE. \\
Bartlett's K-squared: \Sexpr{round(popbart$statistic,3)}, df = \Sexpr{popbart$parameter[[1]]}, p-value = \Sexpr{round(popbart$p.value,digits=4)}

<<echo=FALSE, results='hide'>>=
allresults$locihz<-list(obs_exp_het_comp=het_comb, Bartlett_test=popbart)
@

\FloatBarrier
