# Gausovo jezgro
K = function(t) {
  return(exp(-t^2/2)/sqrt(2*pi))
}

podaci = c(-0.77, -0.60, -0.25, 0.14, 0.45, 0.64, 0.65, 1.19, 1.71, 1.74)
n = length(podaci)

par(mfrow = c(2, 2))
# grafik ocene gustine za razlicite parametre glatkosti
for (h in c(0.25, 0.4, 0.6, 1)) {
  # tacke u kojima se ocenjuje gustina
  y = seq(-4, 4, 0.01) 
  f = rep(0, length(y)) 
  
  plot(y, f, type = "n", xlab = "", ylab = "", 
       main = paste("h = ", h), xlim = c(-4, 4), ylim = c(0, 0.5))
  
  for (i in 1:n) {
    fi = K((y - podaci[i])/h) 
    # ocena gustine na osnovu samo jednog podatka: podaci[i]
    lines(y, fi/(n*h), col = i + 1) 
    f = f + fi/(n*h)
  }
  # ocena gustine na osnovu svih podataka
  lines(y, f, lwd = 2) 
}