--- title: 'Semiparametric regression: local methods, comparison' output: html_document --- ```{r setup, include=FALSE} knitr::opts_chunk$set(echo = TRUE) ``` In what follows we use the MC simulation strategy to compare two different smoothers with respect to their mean square errors as a function of the bandwith. # Data ```{r simulated data} n=200 #x=sort(runif(n,0,1)) #x=rbeta(n,1,6) truef=function(x) sin(2*pi*x) signaltonoise=2 simula=function(x=seq(0,1,length=n),signalnoise=signaltonoise){ my=truef(x) y=rnorm(n,my,sd=sd(my)/signalnoise) return(data.frame(x=x,y=y,truef=my)) } d=simula(x=sort(c(0,1,rbeta(n-2,3,3)))) xobs=d$x plot(d$x,d$y) lines(d$x,d$truef,col="darkred",lwd=2) ``` # The smoothers ```{r smoothers definitions} runmean0=function(x,xx,yy,h) mean(yy[abs(xx-x)