24小时热门版块排行榜    

Znn3bq.jpeg
查看: 2702  |  回复: 3

dingjh1992

新虫 (小有名气)

[求助] 求助,matlab中的卡方检验怎么弄 已有2人参与

在help中输入chi2test然后查不到。。网上说是用这个指令

发自小木虫Android客户端
回复此楼

» 猜你喜欢

» 本主题相关价值贴推荐,对您同样有帮助:

已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

ocnzhao

木虫 (正式写手)

游戏

【答案】应助回帖

感谢参与,应助指数 +1
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.
% [p,Q] = chi2test([15,10; 7,11; 9,7; 20,15; 26,21; 19,16])
% 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
数学软件交流群84998420
2楼2016-09-17 10:37:05
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

ocnzhao

木虫 (正式写手)

游戏

matlab 2016b没有这个函数
数学软件交流群84998420
3楼2016-09-17 10:37:38
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

FMStation

至尊木虫 (知名作家)

【答案】应助回帖

感谢参与,应助指数 +1
https://www.mathworks.com/help/stats/chi2gof.html

chi2gof
Chi-square goodness-of-fit test
4楼2016-09-17 23:11:32
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
相关版块跳转 我要订阅楼主 dingjh1992 的主题更新
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[基金申请] 今年审到国自然15份,谈谈感受 +3 国自然国社科中 2026-05-17 3/150 2026-05-17 12:44 by naifen008
[考博] 找博士生导师 +3 小代想上岸 2026-05-15 4/200 2026-05-17 09:20 by YuY66
[基金申请] 重磅!青年科学基金项目(C类)资助增幅预计超过50% +7 水和泥不是水泥 2026-05-13 9/450 2026-05-17 08:28 by soxiaomucong
[考博] 售SCI一区T0P文章,我:8.O.5.5.1.O.5.4,科目齐全,可+急 +3 7hlccowb3h 2026-05-15 4/200 2026-05-17 07:46 by 11n4dfd8yn
[公派出国] 售SCI一区T0P文章,我:8.O.5.5.1.O.5.4,科目齐全,可+急 +6 l7k6xnh0yc 2026-05-14 6/300 2026-05-17 07:16 by 11n4dfd8yn
[基金申请] 售SCI一区T0P文章,我:8.O.5.5.1.O.5.4,科目齐全,可+急 +3 ky2p12rrjj 2026-05-15 3/150 2026-05-17 00:55 by ue3ir18jc3
[论文投稿] 售SCI一区T0P文章,我:8.O.5.5.1.O.5.4,科目齐全,可+急 +5 v9tggjlwd0 2026-05-15 5/250 2026-05-17 00:32 by xiangfeng
[公派出国] 售SCI一区T0P文章,我:8.O.5.5.1.O.5.4,科目齐全,可+急 +3 v9tggjlwd0 2026-05-15 4/200 2026-05-17 00:15 by ue3ir18jc3
[找工作] 售SCI一区T0P文章,我:8.O.5.5.1.O.5.4,科目齐全,可+急 +4 l7k6xnh0yc 2026-05-14 4/200 2026-05-16 23:10 by ue3ir18jc3
[硕博家园] 售SCI一区T0P文章,我:8.O.5.5.1.O.5.4,科目齐全,可+急 +5 l7k6xnh0yc 2026-05-14 6/300 2026-05-16 22:55 by ue3ir18jc3
[考博] 现在不知道怎么办,感觉很痛苦 +5 qweww 2026-05-11 6/300 2026-05-16 19:57 by Equinoxhua
[基金申请] 请问大佬b0816评完了吗 +4 市民华南虎 2026-05-12 8/400 2026-05-16 19:54 by Equinoxhua
[考研] 售SCI一区T0P文章,我:8.O.5.5.1.O.5.4,科目齐全,可+急 +5 cjf4bx70cj 2026-05-14 6/300 2026-05-16 16:17 by 0i5p09z61n
[硕博家园] 售SCI一区T0P文章,我:8.O.5.5.1.O.5.4,科目齐全,可+急 +3 k37jurhrau 2026-05-16 3/150 2026-05-16 13:57 by vcdazktkjx
[硕博家园] 考博自荐 +3 科研狗111 2026-05-13 4/200 2026-05-16 11:45 by 科研狗111
[硕博家园] 申请博士 +3 呃?呃 2026-05-15 3/150 2026-05-16 11:01 by a4742549
[基金申请] 青C资助名额大幅增加! +11 西葫芦炒鸡蛋 2026-05-13 15/750 2026-05-15 14:36 by ambravo
[教师之家] 教学课件你会给同学吗 +8 硕士研究生吗 2026-05-13 8/400 2026-05-14 22:23 by 常规沥青
[考博] 26应届毕业生考博求助 +3 wo一定上岸 2026-05-13 3/150 2026-05-14 21:47 by 明海天涯
[论文投稿] 求助大佬sci投稿哪个好中 +3 江沅188 2026-05-12 4/200 2026-05-13 14:35 by 江沅188
信息提示
请填处理意见