from
Non-Uniform Bernoulli Trials Exceedance Probability
by William
Calculates the probability of exceeding a given number of hits for a collection of Bernoulli trials
|
| monte_exceedance( p, h, runs )
|
function exc = monte_exceedance( p, h, runs )
%
% MONTE_EXCEEDANCE( P, H, RUNS ) calculates the probability of equaling or
% exceeding h hits for probabilities p (column vector). Uses a monte carlo method,
% as the author finds analytical statistics tiresome. This should reflect
% binomial distribution calculations for uniform p.
%
% Example:
% There is a 30% chance of rain Saturday, and 20% Sunday. What is the
% probability that it rains this weekend?
%
% monte_exceedance([.3; .2],1)
%
% ans =
% 0.4431
%
% Which is reasonably close to the theoretical value of .44
if nargin < 3
runs = 10000;
end
r = rand(length(p),runs);
exc = mean( sum(bsxfun(@lt,r,p)) >= h );
end
|
|
Contact us at files@mathworks.com