% Using Exponential: For If Else If End End

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

12/25/2020 Assignment1

k=[0 1 2 3 4];
l=length(k);

p=[271, 142, 66, 15, 6];

n=500;
m=(k(1)*p(1)+k(2)*p(2)+k(3)*p(3)+k(4)*p(4)+k(5)*p(5))/500;
lambda = 1/m;
e=exp(-lambda);

% Using Exponential
P2 = [];
lembda = 1/m;

fun = @(x) lembda*(exp(-lembda*x));


P2 = [];
for i = 1:5
if i < 5
Q = double(integral(fun, k(i), k(i+1)));
else
if i == 5
Q = double(integral(fun, k(i), inf));
end
end

P2(i) = Q;
end
E2 = [];
s = sum(p);
for i = 1:5
E2(i) = P2(i)*s;
end

figure(2)
b=[E2(1),p(1);E2(2),p(2);E2(3),p(3);E2(4),p(4);E2(5),p(5);];
disp(b)
bar(b)

legend ('Expected Values','Observed Values')


title('Chi-Square plot')
for i=1:l
X1(i)=(p(i)-P2(i))^2/P2(i);
Y=sum(X1);
end
[h,l2]=chi2gof(P2);
disp(h)
disp(l2)
% Using Poison distribution
E1 = [];
for i = 1:5
Q = (n*m^k(i)*e)/factorial(k(i));
E1(i) = Q;
end

disp(E1)

file:///C:/Users/Ibrah/html/Assignment1.html 1/3
12/25/2020 Assignment1
figure(1)
b=[E1(1),p(1);E1(2),p(2);E1(3),p(3);E1(4),p(4);E1(5),p(5);];

disp(b)

bar(b)

legend ('Expected Values','Observed Values')


title('Chi-Square plot')
for i=1:l
X1(i)=(p(i)-E1(i))^2/E1(i);
Y=sum(X1);
end
[h,l1]=chi2gof(E1);
disp(h)
disp(l1)

383.6175 271.0000
89.2927 142.0000
20.7842 66.0000
4.8378 15.0000
1.4677 6.0000

Warning: After pooling, some bins still have low expected counts.
The chi-square approximation may not be accurate
0

NaN

116.3825 79.8384 27.3846 6.2619 1.0739

116.3825 271.0000
79.8384 142.0000
27.3846 66.0000
6.2619 15.0000
1.0739 6.0000

Warning: After pooling, some bins still have low expected counts.
The chi-square approximation may not be accurate
0

NaN

file:///C:/Users/Ibrah/html/Assignment1.html 2/3
12/25/2020 Assignment1

Published with MATLAB® R2015a

file:///C:/Users/Ibrah/html/Assignment1.html 3/3

You might also like