How it works...

The first line in Step 1 simply fixes the random number generator so that we get consistent results between computers; you won't need this other than to compare the results in this book. The next part is to create a custom function that creates two sets (x and y) of 10 random numbers, then performs a t-test and returns the p-value. As these are just random numbers from the same distribution, there is no real difference. The final line uses the sapply() function to run our custom function and create a vector of 10,000 p-values.

In Step 2, we simply count the number of p-values that are lower than 0.05. We get this:

## [1] 506

This indicates that we have 506 falsely called significant results. 

In Step 3, we use the p.adjust() function to apply a correction method. The argument method can be one of several available methods. In practice, it's best to try holm or BH (Benjamini Hochberg) as these give accurate false detection rates. A widely used but not very useful method is Bonferroni; avoid this in most cases. 

In Step 4, we re-assess the number of p-values that are lower than 0.05. This time, it's as we expect:

## [1] 0

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.149.240.35