Here is the R code for creating the observed table.
mydata <- rbind( c(26, 63), c(29, 26))
It's best to use the built-in function
chisq.test()
to perform the chi-square test, and to
use the results of this test to perform the likelihood ratio test.
chi <- chisq.test(mydata) chi # stat=7.00; P-value = 0.008
For calculating the LRT
statistic and corresponding P-value, we can use the expected
counts given within the results of chisq.test()
.
ex <- chi$expected # expected counts lrt <- 2 * sum( mydata * log(mydata/ex) ) # value = 7.92 1 - pchisq(lrt, 1) # P-value = 0.005
Perform Fisher's exact test using the
built-in function, fisher.test()
.
fisher.test(mydata) # P-value = 0.008
We reject the null hypothesis and conclude that the presence of maples is not independent of the presence of hickories.
[ Main page | 4th term syllabus | R for Windows ] | Last modified: Fri Mar 31 09:24:53 EST 2006 |