summaryrefslogtreecommitdiff
path: root/331/CH9/EX9.8/Example_9_8.sce
blob: 86470ac25d3847c73b8609316025967e5e5e2859 (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
//Caption: Kolmogorov-Smirnov Test
//Example9.8
//Page322
//Ho: The given set of observations follows poisson distribution
//H1: The given set of observations does not follow the poisson distribution
clear;
clc;
X = [0,1,2,3,4,5,6]; //Arrival rate
o = [2,6,18,12,8,3,1];//Observed frequency
n = sum(o);//total observed frequencies
alpha = 0.05;//significance level
N = length(X); //Number of values of the random variable
for i = 1:length(X)
    Xo(i)= X(i)*o(i);
end
Xioi = sum(Xo);
u = Xioi/n; //mean arrival rate
for i = 1:length(X)
   P(i)= ((u^X(i))*exp(-u))/factorial(X(i));
end
op = o/n;
disp(op,'Observed Probability=');
disp(P,'Expected Probability=');
OF = cumsum(op);
EF = cumsum(P);
disp(OF,'Observed cumulative probability=')
disp(EF,'Expected cumulative probability=')
for i = 1:N
    D(i) = abs(OF(i)-EF(i));
end
disp(D,'Calculated difference absolute value D =')
Dn = 1.36/sqrt(n);//theoretical value for a significance level of 0.05
disp(Dn,'Theoretical table value for a significance level of 0.05=')
[Dcal,ind]= max(D); 
disp(Dcal,'The maximum value of D is Dcal=')
if (Dcal<Dn) then
    disp('Since Dcal is less than the table value Dn accept the null hypothesis Ho')
else
    disp('Sinc Dcal > Dn table value reject null hypothesis Ho')
end
//Result
 
// Observed Probability=   
// 
//    0.04    0.12    0.36    0.24    0.16    0.06    0.02  
// 
// Expected Probability=   
// 
//    0.0728029  
//    0.1907435  
//    0.2498740  
//    0.2182233  
//    0.1429362  
//    0.0748986  
//    0.0327057  
// 
// Observed cumulative probability=   
// 
//    0.04    0.16    0.52    0.76    0.92    0.98    1.  
// 
// Expected cumulative probability=   
// 
//    0.0728029  
//    0.2635464  
//    0.5134203  
//    0.7316436  
//    0.8745799  
//    0.9494785  
//    0.9821842  
// 
// Calculated difference absolute value D =   
// 
//    0.0328029  
//    0.1035464  
//    0.0065797  
//    0.0283564  
//    0.0454201  
//    0.0305215  
//    0.0178158  
// 
// Theoretical table value for a significance level of 0.05=   
// 
//    0.1923330  
// 
// The maximum value of D is Dcal=   
// 
//    0.1035464  
// 
// Since Dcal is less than the table value Dn accept the null hypothesis Ho