Can anybody help me to solve this?
Mostrar comentarios más antiguos
How to generate a Binomial random variable by using Bernoulli random variables? The idea is: (i) Generate Bernoulli random variables Yi's with mean p (ii) Set X = sum(Yi's).
This will give us a Binomial random variable with parameters n and p. (Convolution method). How to do this in MATLAB
1 comentario
ASWATHI V
el 21 de Ag. de 2018
Respuestas (2)
Does this help?
p=0.3;
n = 100000;
b=(rand(1,n)<p);
%test it
mean(b)
2 comentarios
Adam Danz
el 22 de Ag. de 2018
I'm not sure what you mean. I don't know what this means: " Set X = sum(Yi's)."
If you want " a Binomial random variable with parameters n and p", then that's what I showed you. If you want to sum them,
x = sum(b)
It's not clear conceptually what you're looking for.
p = 0.3;
n = 25;
nsample_binomial = 1000000;
for i = 1:nsample_binomial
bernoulli = (rand(1,n)<=p);
binomial(i) = sum(bernoulli);
end
%Test for mean and variance
mean(binomial)-n*p
var(binomial)-n*p*(1-p)
4 comentarios
Walter Roberson
el 22 de Ag. de 2018
Without a loop:
p = 0.3;
n = 25;
nsample_binomial = 1000000;
binomial = sum(rand(n, nsample_binomial) <= p);
For computing and plotting cdf, see https://www.mathworks.com/matlabcentral/answers/24299-computing-cdf#answer_322552
ASWATHI V
el 26 de Ag. de 2018
Walter Roberson
el 26 de Ag. de 2018
Shrug. We do not know exactly what plots you need.
Categorías
Más información sobre Univariate Discrete Distributions en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!