This work was originally created by Malika Ihle based on materials from Joel Pick, Hadley Wickham, Kevin Hallgren, and with large contributions from James Smith.
It is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.
- Have R and RStudio installed. If you don't, follow these instructions
- Know some R basics (e.g. how to select a value in a data.frame, how to create a vector). If you don't, visit the tutorial: https://www.tutorialspoint.com/r/index.htm
-
Watch this 30 min introduction to credible research, which contextualise the importance of simulations for reliable research.
-
Fork and clone this repository (here is a reminder on how to fork and clone and what it means). If you have never been introduced to version control system, follow these instructions instead.
-
Optional (to start getting familiarised with the content of the session): Read Hallgren A. K. 2013. Conducting simulation studies in the R programming environment. Tutor Quant Methods Psychol. ; 9(2): 43–60. and answer the following 3 questions in your local copy of the reading sheet:
- describe 6 steps common to all simulations
- describe 3 types of simulations use
- describe 4 limitations of simulations
The self-paced tutorial (pages linked below) will alternate presentation of concepts and simple exercises for you to try to apply them in R. Each time you see written YOUR TURN, switch to your local copy of the exercise script (you can chose between a file with or without the solutions depending on e.g. your level of familiarity with R), review the examples if needed, complete the exercise, and check out the proposed answer (which often contains additional tips). Come back to the online tutorial and after finishing one page, you can click 'next' at the bottom to continue. The exercise script contains code for all the exercises and code that generates the plots that appear in the online tutorial, all in order of appearance in the tutorial.
It is necessary that you work through the sections of the tutorial in order. Please read the blurbs of each sections below to get an overview of this workshop.
Additional note for online instruction: The main instructor will stay in the main room. Everyone is welcome to stay there and ask questions as necessary. Two additional break out rooms will be permanently opened that you can join/leave at any time: one quiet room to work in silence and one collaborative room to work out loud. The co-instructor will answer questions in the collaborative room.
- Definition - what are simulations?
- Purpose - what can we use simulations for?
- Basic Principles - what do we need to create a simulation?
- Random Number Generators - how to generate random numbers in R?
- Repeat - how to repeat the generation of random numbers multiple times?
- Setting the seed - how can you generate the same random numbers?
- Sample size
n
- how many values should you generate within a simulation? - Number of simulations
nrep
- how many repeats of a simulation should you run? - Dry rule - how to write your own functions?
- Simulate to check alpha - write your first simulation and check the rate of false-positive findings.
- Simulate to check power - simulate data to perform a power analysis.
- Simulate to prepare a preregistration - simulate data to test statistical analyses before preregistering them.
- General structure - what is the general structure of a simulation?
- Limitations - what are the limitations to simulations?
- Real-life example - what are real life examples of simulations?
- Additional resources - what resource can help you write your own simulation?
In your local repository, write your own simulation in R to help you prepare the data analyses of your current or next study. When you require help, first push your current work on your GitHub remote (for a reminder on how to do this, see here) for us to be able to access it easily and possibly review and edit your code!