Reputation:
I have code:
x1=rnorm(100,-10,1)
sum(x1>quantile(x1,0.05))/length(x1)
What exactly the second line of code does?
Upvotes: 0
Views: 24
Reputation: 66415
x1 is 100 normally distributed #s from a population with mean of -10.
quantile(x1,0.05)
identifies the 5th percentile of that vector.
x1>quantile(x1,0.05)
tests each element in x1 to see if it's more than that 5th percentile, outputting TRUE (aka 1) if so, so its sum is a count of elements larger than the 5th percentile.
Finally, it's divided by the number of elements in x1: 100. So we're checking what percentage of the values are more than the 5th percentile. I'd expect 95%.
Upvotes: 1