比较超过2比例的matlab

时间:2015-08-24 07:45:42

标签: matlab comparison chi-squared significance

有4组(A,B,C,D) 他们每个人都有不同数量的男性和女性

male_A = 46
male_B = 241
male_C = 202
male_D = 113

female_A = 43
female_B = 134
female_C = 100
female_D = 53

如何识别具有统计学上不同比例的男性和女性的群体?建议使用MATLAB ...

可能的解决方案(请检查)

% 1st row: male
% 2nd row: female
cont = [46   241   202   113;
        43   134   100    53]

mychi(cont)


%this function should calculate the Chi2 
function mychi(cont)
    cont = [cont, sum(cont,2)];
    cont = [cont; sum(cont,1)];

    counter = 1;
    for i = 1 : size(cont,1)-1

        for j = 1 : size(cont,2)-1

            Observed(counter) = cont(i,j);
            Expected(counter) = cont(i,end)*cont(end,j)/cont(end:end);
            O_E_2(counter) = (abs(Observed(counter)-Expected(counter)).^2)/Expected(counter);
            counter = counter + 1;
        end

    end

    DOF = (size(cont,1)-2)*(size(cont,2)-2)
    CHI = sum(O_E_2)
end

返回的CHI应该与可以找到的p <0.05进行比较here

就我而言

DOF =

     3


CHI =

    8.0746

CHI> 0.352所以这些群体的男性和女性都有偏见...

2 个答案:

答案 0 :(得分:0)

不确定您正在寻找什么比较,但比率可以通过

获得
p = 0.05;

ratio_A = male_A ./ (male_A + female_A);
ratio_B = male_B ./ (male_B + female_B);
ratio_C = male_C ./ (male_C + female_C);
ratio_D = male_D ./ (male_D + female_D);

%一旦有比率,就可以按照上面的说明进行分析    %http://au.mathworks.com/help/stats/hypothesis-testing.html

希望这有帮助

答案 1 :(得分:-1)

我建议您将数据排列在矩阵中,并根据您的庇护使用正确的索引。这里有一个例子:

male_A = 46;
male_B = 241;
male_C = 202;
male_D = 113;

female_A = 43;
female_B = 134;
female_C = 100;
female_D = 53;

matrix = [male_A female_A;
    male_B female_B;
    male_C female_C;
    male_D female_D];

groups = ['A', 'B', 'C', 'D'];

total = (matrix(:,1)+matrix(:,2));
male_percentage = matrix(:,1)./total*100
female_percentage = matrix(:,2)./total*100

threshold = 65;   %// Example threshold 65%
male_above_threshold = groups(male_percentage>threshold)
female_above_threshold = groups(female_percentage>threshold)

maximum_male_ratio = groups(male_percentage==max(male_percentage))
maximum_female_ratio = groups(female_percentage==max(female_percentage))

在你的例子中,你会得到:

male_percentage =

   51.6854
   64.2667
   66.8874
   68.0723


female_percentage =

   48.3146
   35.7333
   33.1126
   31.9277


male_above_threshold =

CD


female_above_threshold =

   Empty string: 1-by-0



maximum_male_ratio =

D


maximum_female_ratio =

A

找出统计上不同的群体是另一个问题。您应该提供更多信息以便这样做。