11.7 Chapter summary

You can easily write your own functions in R. This is extremely useful when you want to call the same operation multiple times within the same project: it makes your code more economical and avoids error. Your functions can have arguments that you vary at the different times you call them. It is good practice to simulate the data from your study before running it, for example to try out your analysis strategy or your planned plots. You can use either simulation or exact calculations to perform statistical power analysis. The two main principles of statistical power are that, for a given sample size, your power to detect an effect increases with the size of the effect; and that, for a given effect size, your power to detect it increases with the sample size. Power analysis is important in producing your sample size justification. Either you know the smallest effect size of interest, and you use power analysis to set the sample size; or the sample size is imposed by practical constraints, in which case you can use power analysis to determine your minimal detectable effect size with a given power.