Saturday, October 5, 2013

Chi Square Test

Copy the following data in a text editor, add a blank line at the end and save as chisq.csv.

Heart Rate Increased, No Heart Rate Increase
Treated, 36,14
Not Treated, 30, 25

For details on the data,visit http://math.hws.edu/javamath/ryan/ChiSquare.html

What we are trying to do here is to test the effect of a drug.
Ho: The proportion of animals whose heart rate increased is independent of drug treatment.
Ha: The proportion of animals whose heart rate increased is associated with drug treatment.

Read the data into R:
> x <- read.csv("e:/r/chisq.csv")

If you didn't enter a line at the end of the file, you are likely to get the following warning:

Warning message:
In read.table(file = file, header = header, sep = sep, quote = quote,  :
incomplete final line found by readTableHeader on 'Chi_Square.csv'


However, lets run the test:

> chisq.test(x, correct=F)

Output:
        Pearson's Chi-squared test

data:  x
X-squared = 3.4177, df = 1, p-value = 0.0645

Look at the p-value. 
p-value of 0.065 is greater than the conventionally accepted of p > 0.05 we fail to reject the null hypothesis. In other words, there is no statistically significant difference in the proportion of animals whose heart rate increased.

No comments:

Post a Comment