#0: # Experiment zur Approximation von Binomial- durch Poisson-Verteilung source(file="http://www.wiwi.uni-bielefeld.de/~wolf/software/R-wtools/slider/slider.R") binom.to.poisson<-function(){ refresh.code<-function(...){ # Vorbereitung n<-slider(no=1); lambda<-slider(no=2); x.0<-slider(no=3) if(lambda>n)n<-slider(set.no.value=c(1,ceiling(lambda))) # Berechnung p<-lambda/n x<-max(0,round(n*p-3*lambda^0.5)):round(n*p+3*lambda^0.5); f.poisson<-dpois(x,lambda); f.binom<-dbinom(x,n,p) if(x.0max(x))x.0<-slider(set.no.value=c(3,max(x))) # Plot nice<-function(x,st=4)paste(floor(x),".",substring(round(1E4*(1+x%%1)),2,1+st),sep="") par(mfrow=c(3,1)) plot(x,f.poisson,type="h",bty="l",main=paste("poisson: lambda=",nice(lambda,1),sep="")) abline(v=x.0, col="red", lty=2) ymax<-par()$usr[4]; xdel<-diff(par()$usr[1:2]) if(lambda>5){pos<-4;xt<-par()$usr[1]+xdel/30}else{pos<-2;xt<-par()$usr[2]-xdel/6} text(xt,ymax*0.9,pos=pos,paste("P(X= ",x.0,")=",nice(dpois(x.0,lambda)),sep="")) text(xt,ymax*0.8,pos=pos,paste("P(X<=",x.0,")=",nice(ppois(x.0,lambda)),sep="")) text(xt,ymax*0.7,pos=pos,paste("P(X> ",x.0,")=",nice(1-ppois(x.0,lambda)),sep="")) plot(x,f.binom,type="h",bty="l",ylim=c(0,ymax), main=paste("binomial: n=",n,",p=",nice(p),sep="")) plot(x,f.poisson-f.binom,type="h",bty="l",main="Unterschiede") abline(h=0) par(mfrow=c(1,1)) } slider(refresh.code, c("n: Anzahl Experimente", "lambda: E(X) aus Poisson","x.0: spezielle Stelle"), c(1,1,1),c(10000,99,99),c(1,.1,1),c(100,10,5) ) } binom.to.poisson() #:0