Answers are grounded in this paper and cite their sources.
Computer simulation is a powerful tool that is often used to guide statistical practice. Simulations give us a way to understand complex systems when their behavior is too complicated to predict theoretically. For example, statisticians may be able to mathematically work out how a statistical test will perform on idealized data (eg, normally distributed, no missing data, and perfectly measured), but they may need simulations to predict the test's performance on messy, real-world data. Because simulations avoid complicated mathematical derivations, they are intuitive, easy to perform, and easy to understand. Unfortunately, many clinical researchers are only vaguely familiar with computer simulation and its many applications. This article reviews how computer simulation works and why it is useful. Computer simulation has numerous applications, including: (1) testing the robustness of statistical tests in nonideal conditions; (2) comparing the performance of alternative statistical approaches; (3) answering statistical debates; (4) calculating sample size and statistical power; (5) calculating P values and confidence intervals for nonideal data; (6) teaching statistical concepts; and (7) developing statistical intuition. Whenever I am trying a new statistical test or applying a familiar test in a new way, I first run computer simulations to convince myself that the statistic works as advertised and to develop my intuition about the test. What follows are 3 concrete examples that illustrate the utility of computer simulation. This histogram shows the results of a computer simulation exploring the expected number of heads in 100 fair coin tosses. The computer repeatedly recorded the number of heads in 100 virtual coin tosses. As expected, 50 heads was the most common outcome, occurring in 8016 out of 100,000 runs, or about 8% of the time. I chose to repeat my simulation 100,000 times. The number of repeats must be large enough to capture the long-run behavior of the phenomenon but not so large that it hangs up my computer. I can run this simple simulation 100,000 times on my desktop computer in less than 1 second. In contrast, repeating the simulation 100 million times increases the processing time to 10 minutes without markedly changing the results. For more complicated simulations, as in examples 2 and 3 below, I typically reduce the number of repeats to 1000 to reduce computer processing time. Figure 1 shows my simulation results. As expected, the most common outcome was 50 heads. This outcome occurred 8016 out of 100,000 times, or 8.016% of the time. Our outcome of interest—fewer than 40 or more than 60 heads—occurred 3512 times, or 3.512% of the time. Thus, the empirical probability of getting this outcome is 3.512%. This empirical probability is very close to the theoretical probability of 3.52%, which I computed mathematically. With more repeats, our empirical probability converges on the theoretical probability with increasing precision (for example, with 100 million repeats the empirical probability was 3.522%). Researchers can calculate sample size or statistical power for simple studies—such as straightforward 2-group comparisons—using available formulas and online calculators. However, more complicated study designs require more sophisticated calculations. Fortunately, power and sample size are easy to estimate with computer simulation 1. Power is the probability that one will achieve a statistically significant result if the effect is real, which can be estimated as the percent of simulated studies in which the effect achieves statistical significance. Goal: Generate N = 50 virtual subjects. Goal: Build in a true interaction effect between the 2 exposure variables. Goal: Determine whether the interaction term is significant in the virtual sample. Goal: Repeat the simulation a large number of times. Goal: Calculate the empirical statistical power. Goal: Calculate power for additional sample sizes. Goal: Calculate power for additional interaction strengths. For this simulation, I limited the number of repeats to 1000 to keep it tractable on my computer. Figure 2 displays the results graphically. The stronger the interaction, the fewer participants are needed to detect that interaction. For a weak interaction (blue stars) with a sample size of N = 50, the interaction term was significant in only 101 of 1000 virtual studies. This finding tells us that the statistical power for this scenario is only 10.1%. For weak interaction (blue stars), we don't achieve 80% power until we have a sample size of 600. For a moderate interaction effect (green triangles), 400 participants are needed to achieve 80% power; for a stronger interaction effect (red circles), only 200 participants are needed. This graph shows the results of a simulation to estimate statistical power for a range of possible sample sizes (N = 50 to N = 1000) and 3 interaction strengths (strong, moderate, and weak). The empirical power is calculated as the percentage of virtual studies (out of 1000) in which the interaction effect achieved statistical significance. When the interaction is stronger, fewer participants are needed to detect the interaction effect. Computer simulation also can answer questions about how statistical approaches perform when applied to real-world data. For example, researchers often use regression to statistically adjust for important confounding variables, but if variables are measured imperfectly, this results in some leftover—or “residual”—confounding. One important question is: How large an impact can residual confounding have? Computer simulation has previously been used to answer this question 2, and it makes an excellent example for illustrating how computer simulation works. Goal: Generate continuous values for the confounder variable for 100 virtual subjects. Goal: Build in a positive relationship between the confounder and the outcome and between the confounder and the exposure. Goal: For each virtual subject, flip a virtual coin with probability of heads P to determine if the subject has the exposure. Repeat for the outcome. Goal: Repeat the simulation a large number of times. Goal: Observe the average effect of imperfect confounder adjustment across the 1000 simulated studies. Goal: Repeat the simulation varying the strength of the confounder. Figure 3 shows the results of the simulation. When we do not adjust for the confounder (red dots), we observe spurious associations between the exposure and the outcome that are proportional to the strength of confounding. When we adjust for the confounder as a continuous variable (blue stars), we completely remove the effect of confounding, revealing no association between the exposure and outcome (odds ratio = 1.0). However, when we adjust for the confounder as a binary variable (green triangles), we observe odds ratios that range from 1.0 to 1.8 depending on the strength of confounding, which gives us a sense of the potential impact of residual confounding. In the extreme, we could observe spurious odds ratios as high as 1.8, but residual confounding is unlikely to explain effects larger than this. This information is helpful for interpreting studies with imprecisely measured confounders. Readers should carefully consider the role of residual confounding for odds ratios below 1.8 but can be confident that odds ratios above 1.8 are unlikely to be explained away by residual confounding. Results of a simulation exploring the effects of residual confounding on the exposure-outcome odds ratio. Results are displayed for 10 levels of confounding (from weak confounding to very strong confounding). Red dots show the unadjusted results; green triangles show the effect of adjusting for the confounder as a binary variable; and blue stars show the effect of adjusting for the confounder as a continuous variable. Residual confounding (green triangles) produced spurious odds ratios as high as 1.8. This outcome suggests that readers should be cautious when encountering odds ratios lower than 1.8 in observational studies, because it is possible to get odds ratios this large entirely as a result of residual confounding. Ever-increasing computing power has made it possible for many statistical questions to be answered by computer simulation rather than mathematical theory. Clinical researchers should be aware of this powerful and versatile tool. Many statistical papers relevant to clinical research involve computer simulation; and these papers are often accessible to researchers with minimal statistical and mathematical training. Simulations also have many practical applications for clinical researchers, including those in PM&R, such as for calculating statistical power, gauging the potential effects of confounders or missing data, and learning about statistics. The barriers to implementing a statistical simulation are also low—one just needs a statistical package such as SAS or R and a few lines of code. For more details about how to design a computer simulation or how to implement one in R, see references 3 or 4, respectively 3, 4.
No takes yet. Share an insight, caveat, or question.
Kristin L. Sainani (2015) studied this question.
Synapse has enriched 10 related papers. Consider them for comparative context: