Skip to content

Instantly share code, notes, and snippets.

@mark-andrews
Created November 1, 2020 17:31
Show Gist options
  • Save mark-andrews/7f3d597cdaeb5e74f2222403e2ed5b0f to your computer and use it in GitHub Desktop.
Save mark-andrews/7f3d597cdaeb5e74f2222403e2ed5b0f to your computer and use it in GitHub Desktop.
stimuli <- letters[1:9]
n = 2
K <- 36
stimuli_list <- vector(mode = "list", length = K)
response_list <- vector(mode = "list", length = K)
for (i in seq(K)){
if (i <= n){
stimuli_list[[i]] <- sample(stimuli, 1)
} else {
if (runif(1) >= 0.5) {
stimuli_list[[i]] <- stimuli_list[[i-n]]
response_list[[i]] <- 'same'
} else {
while (TRUE){
stimuli_list[[i]] <- sample(stimuli, 1)
if (stimuli_list[[i]] != stimuli_list[[i-n]]) {
break
}
}
# just a check
stopifnot(stimuli_list[[i]] != stimuli_list[[i-n]])
response_list[[i]] <- 'different'
}
}
}
data_df <- tibble(stimulus = as.character(stimuli_list),
response = as.character(response_list))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment