For 1,000,000 observations, I observed a discrete event, X, 3 times for the control group and 10 times for the test group.
I need to preform a Chi square test of independence in Matlab. This is how you would do it in r:
m <- rbind(c(3, 1000000-3), c(10, 1000000-10))
# [,1] [,2]
# [1,] 3 999997
# [2,] 10 999990
chisq.test(m)
The r function returns chi-squared = 2.7692, df = 1, p-value = 0.0961.
What Matlab function should I use or create to do this?
Here is my own implementation that I use:
And an example to illustrate:
Note that the results are different from yours because
chisq.testperforms a correction by default, according to?chisq.testAlternatively if you have the actual observations of the two events in question, you can use the CROSSTAB function which computes the contingency table and return the Chi2 and p-value measures:
the equivalent in R would be:
Note: Both (MATLAB) approaches above require the Statistics Toolbox