Function 'chi2test' has already been declared within this scope.

2 ビュー (過去 30 日間)
Ehsan Shooshtari
Ehsan Shooshtari 2020 年 4 月 16 日
コメント済み: Ehsan Shooshtari 2020 年 4 月 16 日
Hello Team Support
Dear I hope you are healthy during this epidemic crisis
I am trying to use chi2test function run and use for other program, but I see this error, please help me to solve the issue.
Thanks.
function H=chi2test(x, Alpha)
% CHI2TEST: Single sample Pearson Chi Square goodness-of-fit hypothesis test.
% H=CHI2TEST(X,ALPHA) performs the particular case of Pearson Chi Square
% test to determine whether the null hypothesis of composite normality PDF is
% a reasonable assumption regarding the population distribution of a random sample X
% with the desired significance level ALPHA.
%zX
% H indicates the result ofthe hypothesis test according to the MATLAB rules
% of conditional statements:
% H=1 => Do not reject the null hypothesis at significance level ALPHA.
% H=0 => Reject the null hypothesis at significance level ALPHA.
%
% The Chi Square hypotheses and test statistic in this particular case are:
%
% Null Hypothesis: X is normal with unknown mean and variance.
% Alternative Hypothesis: X is not normal.
%
% The random sample X is shifted by its estimated mean and normalized by its
% estimated standard deviation. The tested bins XP of the assumed normal distribution
% are chosen [-inf, -1.6:0.4:1.6, inf] to avoid unsufficient statistics.
%
% Let E(x) be the expected frequency X falls within XP according to the normal
% distribution and O(x) be the observed frequency. The Pearson statistic,
% X2=SUM((E(x)-O(x))^2/E(x)) distributes Chi Square with length(XP)-3 degrees
% of freedom.
%
% The decision to reject the null hypothesis is taken when the P value (probability that Chi2
% random value with length(XP)-3 degrees of freedomd is greater than X2) is less than
% significance level ALPHA.
%
% X must be a row vector representing a random sample. ALPHA must be a scalar.
% The function doesn't check the formats of X and ALPHA, as well as a number of the
% input and output parameters.
%
% The asymptotic limit of the Chi Square test presented is reached when LENGTH(X)>90.
%
% Acknowledge: Dr. S. Loyka
%
% Author: G. Levin, May, 2003.
%
% References:
% W. T. Eadie, D. Drijard, F. E. James, M Roos and B. Sadoulet, "Statistical Methods
% in Experimental Physics", North-Holland, Sec. Reprint, 1982.
%Normalize x
N=length(x);
x=(x-mean(x))/std(x); %standardization
xp=[-inf, -1.6:.4:1.6, inf]; %tested bins
E=0.5*N*diff(erfc(-xp/sqrt(2))); %expected frequency
S=histcounts(x, xp);
O=S(1:end-1); %%observed frequency
%plot(xp(2:end),E,'k-',xp(2:end),O,'k.')
x2=sum((E-O).^2./E); %statistics
pval=1-gammainc(x2/2,(length(O)-3)/2); %p value
H=(pval>=Alpha);
end
Makes this error
>> Chi2test(3,0.05)
Cannot find an exact (case-sensitive) match for 'Chi2test'
The closest match is: chi2test in D:\Education\ \FouthSemester\M \MLpractice\chi2test.m
  2 件のコメント
Ehsan Shooshtari
Ehsan Shooshtari 2020 年 4 月 16 日
I solved the first problem and I enconter to second error which is for usage of upper function
chi2test(3,0.05)
Matrix dimensions must agree.
Error in chi2test (line 53)
x2=sum((E-O).^2./E); %statistics
Ameer Hamza
Ameer Hamza 2020 年 4 月 16 日
Check the updated answer.

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

採用された回答

Ameer Hamza
Ameer Hamza 2020 年 4 月 16 日
編集済み: Ameer Hamza 2020 年 4 月 16 日
Function names are case-sensitive in MATLAB
chi2test(3,0.05)
^ lowercase letter
To correct the error inside your function. Change line 51 in your code to
O=S(1:end); %%observed frequency
  4 件のコメント
Stephen23
Stephen23 2020 年 4 月 16 日
Ehsan Shooshtari's incorrectly posted "Answer" moved to a comment:
chi2test
Ehsan Shooshtari
Ehsan Shooshtari 2020 年 4 月 16 日
Appreciate everyone

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

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by