5.2k views
0 votes
Matlab Project Consider the script Binom_vs_PoissonRV_V5Mod.m used in class to compares a Binomial and a Poisson random variable PMFs.

Change the code to simplify it by removing the CDFs for both random variables. This way all probabilities will be computed using only PMFs.
One possible interesting range/interval to compute a probability using both PMFs is the mean +- the standard deviation:
np±σ;σ= √np(1−p) for the Binomial RV.
Use λ=np to compare the Poisson with the Binomial RVs in the computation of interval probabilities ainterval np−σNote also: If you use the PMFs you will need to be careful to use integer arguments as in previous Matlab scripts and careful not to exceed the range of the PMFs (both start at i=0 and the ending is at i=n for the Binomial)
% Matlab Script to experiment with Binomial and Poisson Random Variable
% File Name: Binom_vs_PoissonRV_V5Mod.m
% for EE3384 class demo fixed!!!
close all; clear all; clc
format long % **************** IMPORTANT *************************
N=1000; P=0.001; % Chose parameters here
MeanX = N*P; % Mean of the Binomial
PeakX = (N+1)*P; % Peak= value where it starts to decrease
A= 3.9999; B = 7.001; % Define a range to compute Prob{AMgrid = 50;
nzine=[0:(1/Mgrid):N/50]; % x-axis for CDFs
Yb=binocdf(nfine,N,P);
narray0=[0:N/50]; % x-axis for PMF
Zb=binopdf(narray0,N,P);
% Matlab Script to experiment with Poisson Random Variable CDF and PDF
lambda=N*P; % Chose parameters here to match E[] of both RVs
Yp=poisscdf(nfine,lambda);
Zp=poisspdf(narray0,lambda);
figure; stem(narray0,Zb); grid
title(['PMF of a Binomial RV , mean=' num2str(MeanX) ', peak=' num2str(PeakX) ]);
% Next do joint plots
figure; stem(narray0,Zb,'b'); grid; hold on
stem(narray0,Zp,'*r'); hold off
title('PMFs for binomial (blue) and Poisson (red) random variables, lambda=N*p')
figure; stem(narray0,log10(Zb),'b'); grid; hold on
stem(narray0,log10(Zp),'*r'); hold off
title('Log10 PMFs for binomial (blue) and Poisson (red) random variables, lambda=N*p')
figure; plot(nfine,Yb,'b',nfine,Yp,'r'); grid
title('CDF of a Binomial (blue) vs Poisson (red) Random Variable');
a=int16(ceil(A)) % convert to integer index (one based)for PMF evaluation
b=int16(floor(B)) % convert to integer index (one based)for PMF evaluation
ac= int16(Mgrid*a) % Very carefully choose values for CDF evaluation (left limit)
bc= int16(Mgrid*b) % Very carefully choose values for CDF evaluation (right limit)
% Binomial
Pbinomial_CDF = Yb(bc+1) - Yb(ac) % subtract CDF values making sure the second value
%is below the discontinuity

sum=0;
for k=a+1:b+1
sum=sum+Zb(k); % add PMF values of Binomial
end
Pbinomial_PMF=sum
% Next Poisson
Ppoisson_CDF = Yp(bc+1) - Yp(ac) % subtract CDF values,same way
sum=0;
for k=a+1:b+1
sum=sum+Zp(k); % add PMF values
end
Ppoisson_PMF=sum
Diff_Perc_PMF = 100*abs(Pbinomial_PMF - Ppoisson_PMF)/Pbinomial_PMF
Diff_Perc_CDF = 100*abs(Pbinomial_CDF - Ppoisson_CDF)/Pbinomial_CDF

User Statikuz
by
7.8k points

1 Answer

2 votes

Final answer:

The task is to modify a Matlab script to compare Binomial and Poisson distributions using only PMFs by calculating interval probabilities around the mean adjusted by the standard deviation. The script will sum PMF values within the interval and compare the probabilities from both distributions.

Step-by-step explanation:

The task involves modifying a Matlab script that compares the probability mass functions (PMFs) of a Binomial and a Poisson random variable. The modification includes removing the cumulative distribution functions (CDFs) from the code and calculating probabilities solely using PMFs. The script then calculates the interval probabilities around the mean ± standard deviation, which is np±σ for a Binomial random variable, where λ=np matches the mean for the Poisson distribution.

The Binomial distribution is a discrete random variable that results from a fixed number of n independent Bernoulli trials with probability p of success on each trial. The mean is μ=np and the standard deviation is σ = √npq. The Poisson distribution is also a discrete random variable that counts the number of events occurring in a fixed interval, with a known average rate λ, and is used to approximate the Binomial when p is small and n is large.

To compute the probabilities for the specified interval using PMFs, the script iterates over the range of integer values that span the interval, summing the PMF values for both Binomial and Poisson distributions. Additionally, the script compares the two distributions by computing the difference in probabilities obtained from both PMFs.

User Dave Dunkin
by
8.4k points