3

i using bionrnd() function to generate a random vector and Laplace approximation formula to approximate the binomial distribution. but Laplace histogram dose not like the binomial distribution histogram. where is my mistake in coding? help me please and here is my code :

clear
clc
close all

n = input ('Please Enter Number of Exams : ');
p = input ('Please Enter Probability : ');

eta=n*p;
sigma=sqrt(n*p*(1-p));

for x=1:n*100;
a=rand(1,n);
b=0;
for i=1:n
    if(a(i)>=1-p)
        b=b+1;
    end
end
c(x)=b;
d(x)=binornd(n , p);
e(x)=(1./(sqrt(2*pi*x*p*(1-p)))).* exp(-(((x+1)*p-(x*p)).^2)./(2*x*p*(1-p)));

end

E=sigma*e+eta;

histfit(c);
axis([0 n 0 inf])
M = mean(c);
varc=var(c);
disp(['var is : ', num2str(varc)]);
disp(['Mean is : ', num2str(M)]);
figure
histfit(d);
axis([0 n 0 inf])
M2 = mean(d);
varc2=var(d);
disp(['var is : ', num2str(varc2)]);
disp(['Mean is : ', num2str(M2)]);
figure
histfit(e,100);
axis([0 n 0 inf])
M3 = mean(e);
varc3=var(e);
disp(['var is : ', num2str(M3)]);
disp(['Mean is : ', num2str(M3)]);

the e(x) is formula of Laplace approximation in this link : De Moivre Laplace theorem formula

output is : output of running code for n=100 and p=0.5

kjetil b halvorsen
  • 63,378
  • 26
  • 142
  • 467
Hector
  • 131
  • 3
  • 2
    Some people voted for this being off-topic. This is clearly on-topic. Somebody is asking help to understand what is wrong in his understanding of De Moivre's formula. It is not `routine data processing, or details of the language` (as stated in our [Help Centre](https://stats.stackexchange.com/help/on-topic)). – usεr11852 Jan 29 '15 at 19:29
  • 1
    The formula in the code for `e(x)` is not recognizable as being a Normal approximation to binomial probabilities. Could you tell us precisely what you think the formula for the "Laplace approximation" is? – whuber Jan 29 '15 at 20:59
  • my target is "Generating random sequences with the binomial distribution and proof the Laplace approximation". i know binomial distribution but i do not know any thing about Laplace approximation or poisson points. – Hector Jan 29 '15 at 21:19
  • 2
    Your formula for `e(x)` definitely is not that of the link. You should seek to understand this *Normal approximation to the Binomial distribution* before you attempt to code it. Consult an elementary textbook on statistics or look through [related answers](http://stats.stackexchange.com/search?q=binomial+normal+approximation+self-study+score%3A1+is%3Aanswer) on our site. – whuber Jan 29 '15 at 21:39
  • 1
    Why do you need random numbers for this? Why not just compare the exact distribution (`binopdf`) with the approximation? – Part of your problem could be that the binomial is a discrete distribution with a probability mass function, while the normal approximation is a density. You have to account for the discreteness in order to get a match. – A. Donda Jan 30 '15 at 01:22
  • 1
    Dear hosein, please do *not* crosspost ([1](http://stackoverflow.com/questions/28203772/laplace-approximation-for-binomial-distribution-in-matlab)) ([2](http://math.stackexchange.com/questions/1124714/laplace-approximation-for-binomial-distribution-in-matlab)) your question to multiple Stack Exchange sister sites. Choose the single best one and post it there. If you do not receive an adequate response after a few days, you can request that a moderator migrate it to another site. Cheers. – cardinal Jan 30 '15 at 03:31

0 Answers0