Judging by your plot, I assume you have some sequence of numbers called averageRank
, for which you tried to fit a kernel density estimator using density.default()
.
Essentially you have an estimate of your probability density function (output of density.default()
). Your question states:
I wonder how can I find p-value associated with each value of variable X in R?
Which is what density.default()
gives to you indirectly, except only for 512 equidistant points, instead of something continuous. You could find, for a specific value x
the closest value outputted by density.default()
and the corresponding y
:
# Create some random data:
set.seed(123)
averageRank <- rnorm(100, mean = 300, sd = 75)
x <- 250
kde <- density.default(averageRank)
closeness <- abs(kde$x - x)
kde$y[which(closeness == min(closeness))]
# [1] 0.004370022 # is P(X = 250)
However, from the way you posed your question I get the feeling you are searching for the cumulative distribution function:
sum(kde$y[1:which(closeness == min(closeness))]/sum(kde$y)
# [1] 0.2138626 # is P(X < 250)