{"word_count": 453, "character_count": 3489}
By the end of May, in Toronto, we had that great talk at the SSC by Jeff Rosenthal, on monte carlo techniques, and Jeff mention the name of "the Goldilocks principle" (it was in the contect of MCMC, and I did mention it in my talk in London on MCMC, when I discussed the value of the rejection rate of the Hastings Metropolis algorithm, which should be not to large, and not too small...). In the story, Goldilocks, there are always three alternative, one is always too much in one extreme (too hot - for the soup - or too large - for the bed, or the chaiir), one is too much in the opposite extreme (too cold, or too small), and one is "just right".The principle is everywhere in statistics, where a parameter has to be fixed, and usually, ir should be not too large and not too small. In one case, there will be a small variance, and a large bias, and in the other case, there will be a small bias and a large variance. It should be "just right". For instance on kernel smoothing, for density estimation. The standard estimator iswhere  is some kernel, and  is a bandwidth. The value for the bandwidth should not be too large,&#62; n=100&#62; bsilverman=1.06*n^(-1/5)&#62; bsilverman[1] 0.4219936&#62; set.seed(1)&#62; sample_X=matrix(rnorm(n*10),n,10)&#62; b=2*bsilverman&#62; u=seq(-3,3,by=.01)&#62; plot(u,dnorm(u),col="red",+ type="l",ylim=c(0,.5),lwd=2)&#62; for(i in 1:10){+ lines(density(sample_X[,i],+ bw=b),col="blue")+ }(because here, it is too smooth, with a small variance, but a strong bias, if we compare the blue lines - based on various samples - and the red line - the true density) it should not be too small,&#62; b=bsilverman/2&#62; plot(u,dnorm(u),col="red",+ type="l",ylim=c(0,.5),lwd=2)&#62; for(i in 1:10){+ lines(density(sample_X[,i],+ bw=b),col="blue")+ }(because here, it is to heratic, with a large variance, but a small bias, if we compare the blue lines and the red one) it has to be "just right".&#62; b=bsilverman&#62; plot(u,dnorm(u),col="red",+ type="l",ylim=c(0,.5),lwd=2)&#62; for(i in 1:10){+ lines(density(sample_X[,i],+ bw=b),col="blue")+ }The standard idea is to minimize the integrated mean squared errorand the optimal value isIn the case of a Gaussian sample (that we consider here to illustrate), we have Silverman's ruleIn order to illustrate it, let use consider the optmal value obtained from 1,000 samples,&#62; nsim=1000&#62; mat_sample_x=matrix(rnorm(n*nsim),n,nsim)&#62; vec_fh=function(x,b=.3){+ sapply(1:nsim,function(i){+  density(mat_sample_x[,i],bw=b,+  from=x,to=x,n=1)$y})}&#62; f=function(x){+ dnorm(x)}&#62; mise1=+ Vectorize(function(bw){+ integrate(function(x){+ (mean(vec_fh(x,b=bw))-f(x))^2},+ lower=-Inf,upper=Inf)$value})&#62; mise2=Vectorize(function(bw){+ integrate(Vectorize(function(x){+ var(vec_fh(x,b=bw))}),+ lower=-Inf,upper=Inf)$value})&#62; mise=function(b){mise1(b)+mise2(b)}If we minimise the average (instead of the expected) integrated squared error, we get&#62; optimize(mise,c(0,2))$minimum[1] 0.4465461$objective[1] 0.03335771(which is not far away from Silverman's value), and if we plot the two parts of the MISE (the bias and the variance), we get&#62; B=seq(0.02,2,by=.02)&#62; Ymise= mise(B)&#62; Ymise1=mise1(B)&#62; Ymise2=mise2(B)&#62; plot(B,Ymise,type="l",col="black",lwd=3)&#62; lines(B,Ymise1,col="red")&#62; lines(B,Ymise2,col="blue")We clearly observe an optimal value, not too small (the estimator has to much variance) and not too large (the bias is too large), it has to be "just right".