# Week 6 – Simulation, Power

This week we’re going to talk about one of my favorite things: simulation!

Simulation is one of the most useful tools I’ve come across. You can use it to test how your data and statistical tests behave when certain assumptions are violated, how much power you have to detect a true effect, and more generally it helps you think about what you expect from the data generating process you’re interested in.

Also, for those of us who haven’t written a formal mathematical proof in awhile, it’s a simple way to demonstrate statistical problems and solutions without slogging through complicated equations.

**Our strategy for today:**

We’ll start by looking at how to draw numbers from distributions (e.g., the normal distribution), how to do this repeatedly to simulate sampling from a population, and then how to do *that* repeatedly to simulate running multiple studies (hopefully this builds up a crucial bit of insight about how frequentist statistics work, too).

After that, we’ll look at some tools (`lavaan`

and `simsem`

) that you can use to simulate more complicated experimental designs.

**Resources**

- Hadley’s simulation lecture (part 1)
- Hadley’s simulation lecture (part 2)
- Daniel Laken’s power simulation code from this coursera course
- Exploring false positive rates
- Power to detect mediation (
`lavaan`

and`simsem`

) - Model comparison power (more advanced
`simsem`

) - Distributions!