# NOT RUN {
#generaing data
x<-rnorm(1000,10,7)
xx<-x[x>=10 & x<=20]
#create suitable postulated quantile function of data
G<-pnorm(20,5,15)-pnorm(10,5,15)
g<-function(x){dnorm(x,5,15)/G}
#Choose best M
Mmax=20
range=c(10,20)
m<-BestM(data=xx,g, Mmax,range)
# vectorize postulated quantile function
g<-Vectorize(g)
u<-g(xx)
#M has to be sufficient big, otherwise dhatL2 function will crush.
#So,here we set m eqaul 6 as an example
m<-6
comp.density<-dhatL2(data=xx,g, M=m, Mmax=Mmax,smooth=FALSE,criterion="AIC",hist.u=TRUE,breaks=20,
ylim=c(0,2.5),range=range,sigma=2)
# }
Run the code above in your browser using DataLab