Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

R clarification of the meaning of the formula

I have a code:

 x1=rnorm(100,-10,1)
 sum(x1>quantile(x1,0.05))/length(x1)
 

I would like to ask someone from the forum to explain to me what exactly the second line of code does. Thank you in advance for your help.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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%.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading