How to carry out a chi-squared distribution fit?

10 ビュー (過去 30 日間)
J.Cam
J.Cam 2020 年 3 月 25 日
コメント済み: Jeff Miller 2020 年 3 月 27 日
My task is to build a matlab function with 2 inputs: the table of observed data and the level of significance. This function has to compute the chi squared test and deduce which hypothesis to accept.
Now the function is able to compute the chi square but I'm finding difficulty in using the (chi2gof)
function [chi2, df] = Untitled(n)
%% degrees of freedom
r = size(n,1);
c = size(n,2);
df = (r-1)*(c-1)
% Calculate R, C, and T
R = sum(n,2);
C = sum(n);
T = sum(R);
% Calculate \chi^2
CR = (C'*R')';
S = ((n - CR/T).^2)./(CR/T);
chi2 = sum(S(:))
[h,p, stats] = chi2gof(n,'CDF','Alpha',0.05);
end

採用された回答

Jeff Miller
Jeff Miller 2020 年 3 月 25 日
chi2gof is not the function you want here--it is for an entirely different purpose. The last few lines should be something like:
% continued from above...
chi2 = sum(S(:));
p = chi2cdf(chi2,df,'upper');
% Now check p and reject H0 if p < your alpha level (usually 0.05);
% otherwise, do not reject.
% You have already computed everything that would be in stats
  2 件のコメント
J.Cam
J.Cam 2020 年 3 月 26 日
編集済み: J.Cam 2020 年 3 月 26 日
Perfect! Thank you.
Jeff Miller
Jeff Miller 2020 年 3 月 27 日
If the answer solved your problem, please accept it.

サインインしてコメントする。

その他の回答 (0 件)

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by