L.G.N<-function(loi="norm",...,mean=FALSE,n1=100,n2=100,by=1,percent=0.95,Boxplot=FALSE) { max<-floor((n2-1)/by) s1<-floor(n1*(1-percent)/2) if (n1*(1-percent)/2==s1) {s1<-c(s1,s1+1)} s2<-floor(n1*(1-(1-percent)/2)) if (n1*(1-(1-percent)/2)==s2) {s2<-c(s2,s2+1)} v<-get(paste("r",loi, sep = "")) u<-matrix(0,n1,max+1) r<-matrix(0,n1,max+1) q1<-rep(0,max+1) q2<-rep(0,max+1) rp<-matrix(0,n1,n2) FG=TRUE for (p in 1:n2) { rp[,p]<-v(n1,...)} for (s in 0:max) {u[,s+1]<-apply(as.matrix(rp[,1:(1+s*by)]),1,mean);r[,s+1]<-rep((1+s*by),n1);q1[s+1]<-mean(sort(u[,s+1])[s1]);q2[s+1]<-mean(sort(u[,s+1])[s2])} par(mfrow=c(1,1)) if (Boxplot) boxplot(u~r) else { for (t in 1:n1) { if (FG & !Boxplot) { plot( 1:(max+1),u[t,],type='l',ylim=range(u),xlab='Taille de l\'échantillon',ylab='Moyenne') FG=FALSE } else lines(u[t,]) } } lines(q1,col="red") lines(q2,col="red") if (is.logical(mean)==FALSE) {abline(mean,0,col="blue")} } T.C.L<-function(loi="norm",...,mean,sd,n1=1000,n2=50,by=5,type=1) { max<-floor((n2-1)/by) m<-sqrt(max)+1 par(mfrow=c(m-1,m)) if (floor(sqrt(max))==sqrt(max)) {m<-sqrt(max);par(mfrow=c(m,m))} v<-get(paste("r",loi, sep = "")) u<-matrix(0,n1,max+1) rb<-matrix(0,n1,n2) w<-matrix(0,n1,max+1) for (p in 1:n2) {rb[,p]<-v(n1,...)} for (s in 0:max) {w[,s+1]<-sqrt(1+s*by)*(apply(as.matrix(rb[,1:(1+s*by)]),1,mean)-mean)/sd} for (s in 1:max) { if (type==1) {hist(w[,s],freq=F,main=paste('n=',1+s*by,sep=''));x<-seq(-100,100,by=0.01);lines(cbind(x,dnorm(x)),col="red")} if (type==2) {plot(function(x) dnorm(x),-3,3,main=paste('n=',1+s*by,sep=''));lines(density(w[,s]),col="red")} if (type==3) {qqnorm(as.vector(w[,s]),main=paste('n=',1+s*by,sep=''));abline(0,1,col="red")} } } ######################### Loi du Chi 2 ################################## x<-matrix(0,10000,100); for (p in 1:10000) x[p,]<-rnorm(100,160,5) hist(x,freq=F) X<-apply(x,1,mean) hist(X,freq=F) v<-seq(150,165,0.1) lines(cbind(v,dnorm(v,160,5/10)),col="red") V<-99*apply(x,1,var)/25 hist(V,freq=F) v<-seq(50,165,0.1) lines(cbind(v,dchisq(v,99)),col="red") x<-matrix(0,10000,100); for (p in 1:10000) x[p,]<-rexp(100,5) hist(x,freq=F) X<-apply(x,1,mean) hist(X,freq=F) v<-seq(0,1,0.001) lines(cbind(v,dnorm(v,1/5,1/50)),col="red") V<-99*apply(x,1,var)*25 hist(V,freq=F) v<-seq(0,250,0.1) lines(cbind(v,dchisq(v,99)),col="red") x<-matrix(0,10000,100); for (p in 1:10000) x[p,]<-runif(100,-1,1) hist(x,freq=F) X<-apply(x,1,mean) hist(X,freq=F) v<-seq(-1,1,0.001) lines(cbind(v,dnorm(v,0,sqrt(1/3)/10)),col="red") V<-99*apply(x,1,var)*3 hist(V,freq=F) v<-seq(0,250,0.1) lines(cbind(v,dchisq(v,99)),col="red") ##################### Loi de Student ############################ x<-matrix(0,10000,10); for (p in 1:10000) x[p,]<-rnorm(10,160,5) hist(x,freq=F) X<-apply(x,1,mean) V<-apply(x,1,var) T<-sqrt(10)*(X-160)/sqrt(V) hist(T,freq=F) lines(cbind(u,dt(u,9)),col="red") lines(cbind(u,dnorm(u,0,1)),col="blue") x<-matrix(0,10000,30); for (p in 1:10000) x[p,]<-rexp(30,5) hist(x,freq=F) X<-apply(x,1,mean) V<-apply(x,1,var) T<-sqrt(30)*(X-1/5)/sqrt(V) hist(T,freq=F) lines(cbind(u,dnorm(u,0,1)),col="blue")