-2

I have a variable X with summary given below. Looking at distribution it seems like skewed normal distribution. I wonder how can I find p-value associated with each value of variable X in R?

Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
1.5   318.3   399.9   367.1   447.4   500.0 

enter image description here

Chirag
  • 455
  • 1
  • 4
  • 18
  • 3
    This sounds like more of a statistics question than a programming one, so it would be better on https://stats.stackexchange.com/. But the question is also pretty unclear, I cannot follow what the p-values you are asking for are supposed to represent. – Marius Jun 02 '17 at 02:29

1 Answers1

0

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)
KenHBS
  • 6,756
  • 6
  • 37
  • 52