I've got data that looks like a univariate distribution, but it is represented by two variables: x being the independent variable, and y being proportional to its probability density (it would be if the area under the curve was 1). The y values are continuous. How can I transform this data set into a single variable so I can fit the distribution?
The best I could come up with was:
library(fGarch)
# simulate data from skewed distributions
i <- 10000
x <- rsnorm(i, xi = 0.5)
x.fit <- snormFit(x)
x.dens <- density(x, bw = "SJ", n = length(x))
# generate integral reps
k <- 1e6
times <- floor(x.dens$y*k)
# upsample
out <- rep(x.dens$x, times)
# downsample
x.smp <- sample(x = out, size = length(x))
# show that it seemed to work
plot(x = x.dens$x, y = x.dens$y, type = "l")
lines(density(x.smp, bw = "SJ"), col = "red")
Is there a smarter way to do this that doesn't lead to an extreme number of ties? I suppose I could fit some kind of a smoothing function to the "densities".