Skip to main content

Section 5.3 Creating Our Data

In this chapter, we are not going to be loading any previously captured data. Instead, we will be utilizing R to help create our own data. Our data is going to contain two variables:
  1. method: identified their studying methods, either flashcards, rereading the material, or taking practice tests
  2. score: how well they scored on a memory test after studying.
With our focus being reproducibility, how can we manage to make sure that the data we create here is the same data you will create? In R, we do this by using the set.seed command. What this does is makes sure the β€œrandom” data creation is the same no matter who is creating the data.
Imagine we had a deck of cards. We need to shuffle them before we deal them to our players. set.seed() is the equivalent to that deck of cards being shuffled in a specific order, that way, if it is shuffled that way every single time, each player is going to be dealt the same cards.

With regards to set.seed().

As long as we put the same number in set.seed() then the same data will be created.
Next, we can use the rnorm() command to dictate quantity, mean, and standard deviation of each.
library(tidyverse)

set.seed(123)  # ensures reproducibility

memory <- tibble(
  method = rep(c("Flashcards", "Rereading", "Testing"), each = 20),
  score = c(
    rnorm(20, mean = 75, sd = 8),  # Flashcards group
    rnorm(20, mean = 70, sd = 9),  # Rereading group
    rnorm(20, mean = 85, sd = 7)   # Testing group
  )
)

glimpse(memory)
Rows: 60
Columns: 2
$ method <chr> "Flashcards", "Flashcards", "Flashcards", "Flashcards", "Flashc…
$ score  <dbl> 70.51619, 73.15858, 87.46967, 75.56407, 76.03430, 88.72052, 78.…
We have successfully created our first dataset!