91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

  • 大小: 1KB
    文件類型: .rar
    金幣: 2
    下載: 0 次
    發(fā)布日期: 2024-01-31
  • 語言: Matlab
  • 標簽:

資源簡介

卡方檢驗代碼,用于MATLAB中,可以根據(jù)此代碼檢驗數(shù)據(jù)是否符合卡方檢驗

資源截圖

代碼片段和文件信息

function?[p?Q]=?chi2test(x)

%?Usage:?[p?Q]=?chi2test(x)
%?
%?The?chi-squared?test.?
%?
%?Given?a?number?of?samples?this?function?tests?the?hypothesis?that?the?samples?are?
%?independent.?If?Q?>?chi2(p?nu)?the?hypothesis?is?rejected.?
%?
%?Each?column?represents?a?variables?each?row?a?sample.
%?
%?If?you?find?any?errors?please?let?me?know:?.
%?
%?ARGUMENTS:
%?x?????Absolut?numbers.
%?p?????The?prob?ability?value?calculated?from?Q.
%?Q?????The?resulting?Q-value.
%?
%?EXAMPLE?1
%?In?region?A?324?of?556?cows?were?red?whereas?in?region?B?98?of?260?were?red.
%?[p?Q]=?chi2test([324?556-324;?98?260-98])
%?p=
%????4.2073e-08
%?Q=
%????30.0515
%?With?an?error?risk?of?about?4e-08?we?can?claim?that?the?samples?are?independent.
%?
%?EXAMPLE?2
%?Throw?two?different?dices?to?see?if?they?have?the?same?probability?of?1?(and?2?3?4?5?6).
%?We?don‘t?check?if?they?are?symetrical?only?if?the?both?behave?in?the?same?way.
%?[pQ]?=?chi2test([1510;?711;?97;?2015;?2621;?1916])
%?p=
%????0.8200
%?Q?=
%????2.2059
%?The?dices?don‘t?significantly?behave?differently.?That?is?they?seem?to?behave?in?the?same?way.
%
%?HISTORY:????v.1.0?first?working?version?2007-08-30.
%?
%?COPYRIGHT:??(c)?2007?Peder?Axensten.?Use?at?own?risk.

%?KEYWORDS:???chi-squared?test?chi-squared?chi2?test

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%?Check?the?arguments.
if(nargin?~=?1) error(‘One?and?only?one?argument?required!‘); end
if(ndims(x)?~=?2) error(‘The?argument?(x)?must?be?a?2d?matrix!‘); end
if(any(size(x)?==?1)) error(‘The?argument?(x)?must?be?a?2d?matrix!‘); end
if(any(~isreal(x))) error(‘All?values?of?the?argument?(x)?must?be?real?values!‘); end

%?Calculate?Q?=?sum(?(a-np*)^2/(np*(1-p*))?)
s= size(x?1);
r= size(x?2);
np= sum(x?2)/sum(sum(x))?*?sum(x); %?p=sum(x?2)/sum(sum(x))?and?n=sum(x)
Q= sum(sum((x-np).^2./(np)));

%?Calculate?cdf?of?chi-squared?to?Q.?Degrees?of?freedom?v?is?(r-1)*(s-1).
p= 1?-?gammainc(Q/2?(r-1)*(s-1)/2);
end

?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----

?????文件???????2040??2009-03-25?08:04??chi2test.m

-----------?---------??----------?-----??----

?????????????????2040????????????????????1


評論

共有 條評論

相關資源