dujiaomao
有谁非参比较熟悉的
###########question one,, I don't know why xdensity1$y and
########## xdensity2$y are the same for different degree. Thanks
z=seq(-4,4,by=0.1)
library(locfit)
data=dnorm(z)
x=rnorm(2000)
xdensity1=density.lf(x,n=81,width=0.4544,deg=1,from=-4,to=4)
xdensity2=density.lf(x,n=81,width=0.4544,deg=0,from=-4,to=4)
xdensity1$y
xdensity2$y
############Question two: local_density performs more bad than ##########Rosenblatt_Parzen ??
text1=c("Rosenblatt-Parzen and local density method 500 times")
z=seq(-4,4,by=0.1)
data=dnorm(z)
library(locfit)
madevector1=1:500
madevector2=1:500
bd_simulation=function(){
for(i in 1:500){
x=rnorm(250)
xdensity1=density(x,bw=0.2272,kernel="gaussian",n=81,from=-4,to=4)
xdensity2=density.lf(x,n=81,width=0.4544,deg=1,from=-4,to=4)
madevector1=mean(abs(xdensity1$y-data))
madevector2=mean(abs(xdensity2$y-data))
}
madevector=data.frame(Rosenblatt_Parzen=madevector1,local_density=madevector2)
return(madevector)
}
y=bd_simulation()
boxplot(data.frame(y))
title(text1,cex.main=1.2)