I have a dataset with values of limited precision. I am trying to plot its
density using package logspline. The logspline() call with default
parameters causes oscillations in the density plot. My solution was to
fuzzify the input values, using function:
> fuzz <- function(x, prec) x + runif(length(x), -prec / 2, prec /2)
Is there a better idea, perhaps setting mind?
Example:
> x <- seq(-1, 1, by = 0.01)
> ds <- rnorm(1000, sd = 0.2)
> hist(ds, breaks = 40, freq = FALSE)
> s <- logspline(ds)
> lines(x, dlogspline(x, s), col = "red")
> ds2 <- as.numeric(sapply(ds, function(x) sprintf("%.1f", x)))
> s2 <- logspline(ds2)
> lines(x, dlogspline(x, s2), col = "blue")
> ds3 <- fuzz(ds2, 0.1)
> s3 <- logspline(ds3)
> lines(x, dlogspline(x, s3), col = "green")
>
George
[[alternative HTML version deleted]]