Binomial simulation decreasing error

조회 수: 3 (최근 30일)
LD
LD 2019년 4월 24일
답변: David Goodmanson 2019년 4월 27일
Hi all,
I would like to use a binomial simulation and investigate whether the error becomes smaller in case the number of trials increases.
My intuition tells me that this should be the case, but when I try to prove it using a simulation I do not get the result that I wanted.
I used the following commands:
ab(i/1000, :) = binornd(i, p*ones(1,N));
With N equal to 10000 and let i run from 1000 to 10000 with a stepsize of 1000 to generate a matrix with N experiments for each step i
After that I wanted to calculate the error using the absolute difference between the mean of my simulations and the real mean
d(i/1000) = 1/i * abs((mean(ab(i/1000)) - i*p));
I should want a graph slightly converging to zero. Is there someone who can help me extending this to get the results that I wanted?

답변 (1개)

David Goodmanson
David Goodmanson 2019년 4월 27일
Hello LD
Using M in place of your i, the
binornd(M,p*ones(1,N))
creates N draws from a particular binomial distribution. This would usually be denoted as
binornd(M,p,1,N).
The usual approach is to start with a distribution of fixed mean and variance, take the mean of N draws, repeat that a bunch of times and demonstrate that that the variance of the new distribution (about the mean) has decreased by a factor of 1/N compared to the variance (about the mean) of the old one. However, you appear to be increasing the distribution parameter M, not the number of draws N.
The binomial distribution has mean p*M and variance p*(1-p)*M. The new distribution created by taking the mean of N draws has mean of p*M and variance p*(1-p)*M / N. The result decreases with N but increases with M.
M = 1000;
p = .4;
q = 1-p;
N = 100; % number of draws for which the mean is taken
s = 2000; % number of times that process is repeated
x = binornd(M,p,N,s);
y = mean(x); % mean taken down columns
M*p*q/N
mean((y-M*p).^2)
% last two lines should agree fairly well
.

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by