I got a problem while trying to approximate the functional form of a density in R with approxfun()
. The minimal example is as follows.
Example = seq(0.5, 1.5, 0.005)
dens = density(Example)
estim = approxfun(dens)
plot(estim)
plot(dens)
The problem is that plot(estim)
gives the following plot
but plot(dens)
gives the full plot,
with the x-axis covering all values and not stopping at 1 as with the approxfun plot. Hence, approxfun()
does not appropriately capture the density.
What am I doing wrong here? I did try several configurations of approxfun
in order to somehow include the whole x-axis but without success.