24小时热门版块排行榜    

查看: 2661  |  回复: 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 的主题更新
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[考研] 26考研一志愿中国石油大学(华东)305分求调剂 +4 嘉年新程 2026-03-15 4/200 2026-03-21 14:44 by allen-yin
[考研] 材料与化工(0856)304求 B区 调剂 +3 邱gl 2026-03-21 3/150 2026-03-21 13:47 by lature00
[考研] 268求调剂 +8 简单点0 2026-03-17 8/400 2026-03-21 13:43 by 南粤飞花
[考研] 求调剂 +6 Mqqqqqq 2026-03-19 6/300 2026-03-21 08:04 by JourneyLucky
[考研] 299求调剂 +6 △小透明* 2026-03-17 6/300 2026-03-21 02:42 by JourneyLucky
[考研] 一志愿中海洋材料工程专硕330分求调剂 +8 小材化本科 2026-03-18 8/400 2026-03-20 23:16 by JourneyLucky
[考研] 一志愿 西北大学 ,070300化学学硕,总分287,双非一本,求调剂。 +4 晨昏线与星海 2026-03-19 4/200 2026-03-20 22:15 by JourneyLucky
[考研] 085600材料与化工 +8 安全上岸! 2026-03-16 8/400 2026-03-20 22:13 by luoyongfeng
[考研] A区线材料学调剂 +5 周周无极 2026-03-20 5/250 2026-03-20 21:33 by laoshidan
[考研] 一志愿西安交通大学 学硕 354求调剂211或者双一流 +3 我想要读研究生 2026-03-20 3/150 2026-03-20 20:13 by JourneyLucky
[考研] 319求调剂 +3 小力气珂珂 2026-03-20 3/150 2026-03-20 19:47 by JourneyLucky
[考研] 求调剂 +3 eation27 2026-03-20 3/150 2026-03-20 19:32 by JourneyLucky
[考研] 一志愿中国海洋大学,生物学,301分,求调剂 +5 1孙悟空 2026-03-17 6/300 2026-03-19 23:46 by zcl123
[考研] 085601材料工程专硕求调剂 +10 慕寒mio 2026-03-16 10/500 2026-03-19 15:26 by 丁丁*
[考研] 085600材料与化工调剂 324分 +10 llllkkkhh 2026-03-18 12/600 2026-03-19 14:33 by llllkkkhh
[考研] 286求调剂 +6 lemonzzn 2026-03-16 10/500 2026-03-19 14:31 by lemonzzn
[考研] 一志愿福大288有机化学,求调剂 +3 小木虫200408204 2026-03-18 3/150 2026-03-19 13:31 by houyaoxu
[考研] 本科郑州大学物理学院,一志愿华科070200学硕,346求调剂 +4 我不是一根葱 2026-03-18 4/200 2026-03-19 09:11 by 浮云166
[考研] 326求调剂 +5 上岸的小葡 2026-03-15 6/300 2026-03-17 17:26 by ruiyingmiao
[考研] 本科南京大学一志愿川大药学327 +3 麦田耕者 2026-03-14 3/150 2026-03-14 20:04 by 外星文明
信息提示
请填处理意见