Skip to content
Prev 304627 / 398503 Next

Histogram to KDE

Using a data.frame x with columns bins and counts:

x <- structure(list(bins = c(3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 10.5, 
    11.5, 12.5, 13.5, 14.5, 15.5), counts = c(1, 1, 2, 3, 6, 18, 
    19, 23, 8, 10, 6, 2, 1)), .Names = c("bins", "counts"), row.names =
4:16,
    class = "data.frame")

This will give you a plot of the kde estimate:

xkde <- density(rep(bins, counts), bw="SJ")
plot(xkde)

As for the standard error or the confidence interval, you would probably
need to use bootstrapping. 

----------------------------------------------
David L Carlson
Associate Professor of Anthropology
Texas A&M University
College Station, TX 77843-4352