## Demonstrate some density estimation ideas.
vSamples <- rnorm(50)
# histogram with breaks chosen by R
hist(vSamples, freq=FALSE, col="blue", xlim = c(-3,3), ylim = c(0,0.4))
# histogram with even sized breaks; adjust bandwidth and offset
offset <- min(vSamples)-0.2
bandwidth <- 0.5
hist(vSamples, breaks=seq(offset, max(vSamples)+1, bandwidth), freq=FALSE, col="blue", xlim = c(-3,3), ylim = c(0,0.4))
# density estimation with moving window
hist(vSamples, freq=FALSE, xlim = c(-3,3), ylim = c(0,0.8),col="blue")
lines(density(vSamples,kernel="rectangular", bw=0.1), col="red")
lines(density(vSamples,kernel="rectangular", bw=1), col="green")
lines(density(vSamples,kernel="rectangular", bw="ucv"), col="purple")
legend("topright",legend=c("R-histogramm","h=0.1","h=1","cv"),col=c("blue","red","green","purple"),lty=1)