Skip to content
Prev 302875 / 398503 Next

Density

You can use approx(d, xout=) (or spline()) on the output of density()
to get density estimates at the points in xout.  E.g.,
   > X <- c(rnorm(20, -1, 1), rgamma(50,1/2))
   > d <- density(X)
   > plot(d)
   > points(approx(d, xout=-2:2))

Or you could use the functions in package:logspline to fit the density
function and evaluate it where you wish
  > z <- logspline(X)
  > points(-2:2, dlogspline(-2:2, fit=z), col="red")

(The vector '-2:2' about could be any set of numbers, including your
original data points.)

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com