File Exchange

image thumbnail

Pearson Chi-squared test of independence

version 1.0.0 (1.09 KB) by Ryan Ward
Pearson Chi-Square Test for Independence: calculates the chi-square, p-value and the test decision,

10 Downloads

Updated 17 Jul 2020

View License

Example;

x = [61, 54, 32, 26, 47, 39, 13, 26, 12, 59; 7, 14, 36, 42, 21, 29, 55, 42, 56, 9];
[h, chi, p] = chi2ind(x, 0.05)

h =

logical

1

chi =

173.0768

p =

0

Cite As

Ryan Ward (2021). Pearson Chi-squared test of independence (https://www.mathworks.com/matlabcentral/fileexchange/78339-pearson-chi-squared-test-of-independence), MATLAB Central File Exchange. Retrieved .

Comments and Ratings (3)

Gerrik Labra

Thank you Marius. I used this for a neuroengineering project to find significant transfer of entropy, and no matter what I put in the p value is always zero. Please update your code.

Marius Marinescu

Hello,
I think the degrees of freedom is incorrectly computed.
They must be
df=r*c-(r+c-1); % =(r-1)*(c-1);
where r is the numbers of rows and c the number of columns. You have the following formula
df = size(chi, 1)-1*size(chi,2);
where size(chi) is always one since chi in your code is scalar.

Marius Marinescu

MATLAB Release Compatibility
Created with R2018a
Compatible with R2018b and later releases
Platform Compatibility
Windows macOS Linux
Tags Add Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!