#Biostatistics 420 #CHI-SQUARE TEST FOR GOODNESS OF FIT #ZAR EXAMPLE 22.8 ZAR=read.table("ZarEX22.8R.txt") ZAR attach(ZAR) chisq.test(observed,p=expected,rescale.p=TRUE) #G-TEST FOR GOODNESS OF FIT #APPROPRIATE TEST FUNCTION NOT YET FOUND IN R #THEREFORE, I HAD TO DO THIS FROM SCRATCH: #G STATISTIC: G=2*sum(observed*log(observed/expected)) G #CRITICAL VALUE: alpha=0.05 k=4 g=0 df=k-g-1 C=qchisq(1-alpha,df) C #PROBABILITY: P=(1-pchisq(G,df)) P #YATES CORRECTION: ZAR2=read.table("ZarEX22.1R.txt") ZAR2 attach(ZAR2) df=1 #YATES CORRECTED G STATISTIC: obs=c(84-0.5,16+0.5) Gc=2*sum(obs*log(obs/expected)) Gc #YATES CORRECTED PROBABILITY: Pc=(1-pchisq(Gc,df)) Pc