summaryrefslogtreecommitdiff
path: root/331/CH9/EX9.23/Example_9_23.sce
blob: 94a914c6cd89bee1e616e123a8f67cba977ab973 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
//Caption:Kruskal-Wallis Test (H Test)
//Example9.23
//Page350
//Ho: There is no significant difference between the production volumes of units assmebled by the three operators
//H1: There is significant difference between the production volumes of units assmebled by the three operators
clear;
clc;
X1 = [29,34,34,20,32,45,42,24,35];//Operator-1:production volume of Units Assembled
X2 = [30,21,23,25,44,37,34,19,38];//Operator-2:production volume of Units Assembled
X3 = [26,36,41,48,27,39,28,46,15];//Operator-3:production volume of Units Assembled
n1 = length(X1);//number of shifts worked by operator-1
n2 = length(X2);//number of shifts worked by operator-2
n3 = length(X3);//number of shifts worked by operator-3
N = n1+n2+n3;//total number of shifts
X =[X1,X2,X3];
[X_sort,ind] = gsort(X,'g','i');
j = 1;
for i = 1:N
   R(i)=i;
   if (i~=N) then
       if (X_sort(i)==X_sort(i+1)) then
           K(j)=i;
           j = j+1;
       elseif (i>1)&(X_sort(i)==X_sort(i-1))
           K(j)= i;
           j = j+1;
       end
   end
end
disp(X_sort,'Observations of all samples=')
disp(R,'Ranks of all observations')
for i = 1:length(K)
    R(K(i))= sum(K(:))/length(K);
end
for i =1:N
    for j= 1:n1
        if(X_sort(i)==X1(j))
            R_S1(j) =  R(i);
        elseif (X_sort(i)==X2(j))
            R_S2(j) =  R(i);
        elseif (X_sort(i)==X3(j))
            R_S3(j) = R(i);
        end
    end
    
end
R_S1 = gsort(R_S1,'g','i');
disp(R_S1,'Ranks of Sample-1=');
R_S2 = gsort(R_S2,'g','i');
disp(R_S2,'Ranks of Sample-2=');
R_S3 = gsort(R_S3,'g','i');
disp(R_S3,'Ranks of Sample-3=');
Sum_R_S1 = sum(R_S1);
disp(Sum_R_S1,'The sum of the ranks of the sample-1')
Sum_R_S2 = sum(R_S2);
disp(Sum_R_S2,'The sum of the ranks of the sample-2')
Sum_R_S3 = sum(R_S3);
disp(Sum_R_S3,'The sum of the ranks of the sample-3')
H = (12/(N*(N+1)))*((Sum_R_S1^2/n1)+(Sum_R_S2^2/n2)+(Sum_R_S3^2/n3))-3*(N+1);
disp(H,'H~chi-square distribution with (K-1) degrees of freedom, where K is the total number of samples H=')
H_table = 5.991;//for 2 degrees of freedom & significance level = 0.05
disp(H_table,'H~chi-square table value for 2 degrees of freedom and significance level of 0.05=')
if(H<H_table)
    disp('Since the calculated value of H is < the table chi-square table, accept the null hypothesis' )
else
    disp('Reject null hypothesis')
end
//Result
 
// Observations of all samples=   
// 
// 
//         column  1 to 17
// 
//    15.    19.    20.    21.    23.    24.    25.    26.    27.    28.    29.    30.    32.    34.    34.    34.    35.  
// 
//         column 18 to 27
// 
//    36.    37.    38.    39.    41.    42.    44.    45.    46.    48.  
// 
// Ranks of all observations   
// 
//    1.   
//    2.   
//    3.   
//    4.   
//    5.   
//    6.   
//    7.   
//    8.   
//    9.   
//    10.  
//    11.  
//    12.  
//    13.  
//    14.  
//    15.  
//    16.  
//    17.  
//    18.  
//    19.  
//    20.  
//    21.  
//    22.  
//    23.  
//    24.  
//    25.  
//    26.  
//    27.  
// 
// Ranks of Sample-1=   
// 
//    3.   
//    6.   
//    11.  
//    13.  
//    15.  
//    15.  
//    17.  
//    23.  
//    25.  
// 
// Ranks of Sample-2=   
// 
//    2.   
//    4.   
//    5.   
//    7.   
//    12.  
//    15.  
//    19.  
//    20.  
//    24.  
// 
// Ranks of Sample-3=   
// 
//    1.   
//    8.   
//    9.   
//    10.  
//    18.  
//    21.  
//    22.  
//    26.  
//    27.  
// 
// The sum of the ranks of the sample-1   
// 
//    128.  
// 
// The sum of the ranks of the sample-2   
// 
//    108.  
// 
// The sum of the ranks of the sample-3   
// 
//    142.  
// 
// H~chi-square distribution with (K-1) degrees of freedom, where K is the total number of samples H=   
// 
//    1.0299824  
// 
// H~chi-square table value for 2 degrees of freedom and significance level of 0.05=   
// 
//    5.991  
// 
// Since the calculated value of H is < the table chi-square table, accept the null hypothesis   
//