#--1
#--Cargamos libreria y datos
library(MASS)
data(geyser)
attach(geyser)
hist<-hist(waiting)
help(hist,freq=F)
hist(waiting,breaks=50,freq=F)
hist(waiting,breaks=100,freq=F)




#--2
#---- Función Naive
naive<-function(x,muestra,h){
    nx=length(x)
    fx=numeric(nx)
    for (i in 1:nx){
    fx[i]=mean((x[i]-h<muestra)&(muestra<x[i]+h))/(2*h)
    }
return(fx)
}
x<-seq(min(waiting),max(waiting),by=0.01)
h<-4
est_naive<-naive(x,waiting,h)
plot(hist,freq=F)
lines(est_naive~x)


#--3
nucleo_uniforme<-function(x){
    if(abs(x)<1){
    sol<-1/2
    }
}
nucleo_epa<-function(x){
    if(abs(x)<1){
    sol<-3/4*(1-x^2)
    }
}

est_nucleo<-function(x,h,nucleo,muestra){
    nx<-length(x)
    sol=numeric(nx)
    for(i in 1:nx){
    sol<-(1/nx*h)*sum(nucleo(x[i]-muestra/h))
    }
}

est_nucleo(x,h,nucleo_uniforme,waiting)
