Alternative to density() in this code

Sorry for possible format problems, it's my first time in this kind of community sites.

I'm looking for an alternative code that doesn't use density() for this:

datos<-c(1.7, 2.1, 3.1, 3.3, 3.7, 4.1, 4.6)

u<-runif(1000)
z1<-1*(u<=1/6)
z2<-1*(u<=(2/6)&(u>(1/6)))
z3<-1*(u<=(3/6)&(u>(2/6)))
z4<-1*(u<=(4/6)&(u>(3/6)))
z5<-1*(u<=(5/6)&(u>(4/6)))
z6<-1*(u>(5/6))

x<-z1*rnorm(1000,datos[1],0.6)+z2*rnorm(1000,datos[2],0.6)+z3*rnorm(1000,datos[3],0.6)+z4*rnorm(1000,datos[4],0.6)+z5*rnorm(1000,datos[5],0.6)+z6*rnorm(1000,datos[6],0.6)
h <- bw.ucv(x)
f <- density(x,bw=h,kernel="gaussian",from=-1,to=6,n=1024)
plot(f,main='',ylim=c(0,0.7))

It is meant to do the kernel density estimator of the sum of the normal distributions with means saved in datos and sd=0.6.
My problem is not fully statistical but more about finding the line/s that can substitute density().

Thank you.

Ten years ago, there were twenty packages that provided functions to calculate density. Probably more today.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.