Danielle Navarro
I am a computational cognitive scientist at the University of New South Wales. My research focuses on human concept learning, reasoning and decision making.
Danielle Navarro, UNSW (@djnavarro)
A tool to build flexible behavioural experiments in R
What about R?
# start timing
start <- Sys.time()
# draw plot
draw_plot(data$n_up[i], data$n_down[i])
# wait for (then record) response
data$response[i] <- getGraphicsEvent(
prompt = "6 = up, b = down",
consolePrompt = "",
onKeybd = response
)
# record the response time
data$rt[i] <- as.numeric(Sys.time() - start)
# clear the plot
clear_plot()
https://djnavarro.shinyapps.io/shiny/
https://psyr.org/shiny.html
???
???
???
???
???
???
Code the experiment in R with jaysire
Build to jsPsych and R server
Deploy locally or to Google
(... in brief!)
library(jaysire)
instructions <- trial_instructions(
pages = c(
"Welcome! Use the arrow buttons to browse these instructions",
"Your task is to decide if an equation like '2 + 2 = 4' is true or false",
"You will respond by clicking a button",
"Press the 'Next' button to begin!"
),
show_clickable_nav = TRUE,
post_trial_gap = 1000
)
library(jaysire)
instructions <- trial_instructions(
pages = c(
"Welcome! Use the arrow buttons to browse these instructions",
"Your task is to decide if an equation like '2 + 2 = 4' is true or false",
"You will respond by clicking a button",
"Press the 'Next' button to begin!"
),
show_clickable_nav = TRUE,
post_trial_gap = 1000
)
trial1 <- trial_html_button_response(
stimulus = "13 + 23 = 36",
choices = c("true", "false"),
post_trial_gap = 1000
)
trial2 <- trial_html_button_response(
stimulus = "17 - 9 = 6",
choices = c("true", "false")
)
library(jaysire)
instructions <- trial_instructions(
pages = c(
"Welcome! Use the arrow buttons to browse these instructions",
"Your task is to decide if an equation like '2 + 2 = 4' is true or false",
"You will respond by clicking a button",
"Press the 'Next' button to begin!"
),
show_clickable_nav = TRUE,
post_trial_gap = 1000
)
trial1 <- trial_html_button_response(
stimulus = "13 + 23 = 36",
choices = c("true", "false"),
post_trial_gap = 1000
)
trial2 <- trial_html_button_response(
stimulus = "17 - 9 = 6",
choices = c("true", "false")
)
build_experiment(
timeline = build_timeline(instructions, trial1, trial2),
path = "path_to_folder",
on_finish = fn_save_locally()
)
image_trial <- trial_image_button_response(
stimulus = insert_resource("heart.png"),
stimulus_height = 400,
stimulus_width = 400,
choices = c("Unpleasant", "Neutral", "Pleasant")
)
video_trial <- trial_video_button_response(
sources = insert_resource(c("heart.mpg", "heart.webm")),
choices = c("Unpleasant", "Neutral", "Pleasant"),
trial_ends_after_video = FALSE,
response_ends_trial = TRUE
)
build_experiment(
timeline = build_timeline(image_trial, video_trial, audio_trial),
path = temporary_folder(),
resources = build_resources("path_to_resource_folder"),
use_webaudio = FALSE,
on_finish = fn_save_locally()
)
Respond with a key press...
Etc...
Respond with a slider bar...
confidence_scale <- c(
"Very unconfident",
"Somewhat unconfident",
"Somewhat confident",
"Very confident"
)
page3 <- trial_survey_likert(
preamble = "How confident in you R skills?",
questions = list(
question_likert("Data wrangling?", confidence_scale),
question_likert("Data visualisation?", confidence_scale),
question_likert("Statistical modelling?", confidence_scale),
question_likert("Designing experiments?", confidence_scale),
question_likert("R markdown documents?", confidence_scale)
)
)
when deployed to Google App Engine responses are written to the Google Datastore
... when deployed locally
# ------ everyone should see this ------
page1 <- trial_html_button_response(
"Do you identify as LGBTIQ+?",
c("Yes", "No", "Prefer not to say")
)
# ------ only some people should see this! ------
followup <- trial_survey_multi_select(
question_multi(
prompt = "Select all that apply",
options = c(
"Lesbian", "Gay", "Bisexual/Pansexual", "Transgender",
"Nonbinary", "Genderqueer", "Intersex", "Asexual", "Other"
)
)
)
# ------ everyone should see this ------
page1 <- trial_html_button_response(
"Do you identify as LGBTIQ+?",
c("Yes", "No", "Prefer not to say")
)
# ------ only some people should see this! ------
followup <- trial_survey_multi_select(
question_multi(
prompt = "Select all that apply",
options = c(
"Lesbian", "Gay", "Bisexual/Pansexual", "Transgender",
"Nonbinary", "Genderqueer", "Intersex", "Asexual", "Other"
)
)
)
# ------ a JS function to be evaluated at run time ------
condition_check <- fn_data_condition(button_pressed == "0")
# ------ a conditional timeline ------
page1a <- build_timeline(followup) %>%
tl_display_if(condition_check)
# ------ everyone should see this ------
page1 <- trial_html_button_response(
"Do you identify as LGBTIQ+?",
c("Yes", "No", "Prefer not to say")
)
# ------ only some people should see this! ------
followup <- trial_survey_multi_select(
question_multi(
prompt = "Select all that apply",
options = c(
"Lesbian", "Gay", "Bisexual/Pansexual", "Transgender",
"Nonbinary", "Genderqueer", "Intersex", "Asexual", "Other"
)
)
)
# ------ a JS function to be evaluated at run time ------
condition_check <- fn_data_condition(button_pressed == "0")
# ------ a conditional timeline ------
page1a <- build_timeline(followup) %>%
tl_display_if(condition_check)
# ------ question to be repeated until answered correctly ------
query <- trial_image_button_response(
stimulus = insert_resource("heart.png"),
stimulus_height = 400,
stimulus_width = 400,
choices = c("Unpleasant", "Neutral", "Pleasant"),
prompt = "You will not be allowed to continue unless you select 'Pleasant'"
)
# ------ question to be repeated until answered correctly ------
query <- trial_image_button_response(
stimulus = insert_resource("heart.png"),
stimulus_height = 400,
stimulus_width = 400,
choices = c("Unpleasant", "Neutral", "Pleasant"),
prompt = "You will not be allowed to continue unless you select 'Pleasant'"
)
# ------ a looped timeline ------
page2 <- build_timeline(query) %>%
tl_display_while(fn_data_condition(button_pressed != "2"))
For anything unusual you need to write a new jsPsych plugin
The R code is used to specify a "trial" by building it from smaller parts
????????
This code is used to construct task-specific jspsych plugins at build time
data +
aesthetics +
layers +
scales +
coordinate +
theme
??? +
??? +
??? +
??? +
??? +
???
????????
????????
dx.doi.org/10.3758/s13414-011-0131-9
Elements:
????????
Stimulus:
Responses:
????????
Events:
Feedback:
A tool to build flexible behavioural experiments in R
code
build
deploy
# ----------- template -----------
trial_template <- trial_html_button_response(
stimulus = insert_variable("stimulus"),
choices = c("true", "false"),
post_trial_gap = 1000
)
# ----------- template -----------
trial_template <- trial_html_button_response(
stimulus = insert_variable("stimulus"),
choices = c("true", "false"),
post_trial_gap = 1000
)
# ----------- timeline -----------
trials <- build_timeline(trial_template) %>%
tl_add_variables(stimulus = c("13 + 23 = 36", "17 - 9 = 6", "etc")) %>%
tl_add_parameters(randomize_order = TRUE, repetitions = 2)
formr.org looks awesome, but targeted at surveys
By Danielle Navarro
Invited talk for rstudio::conf(2020L)
I am a computational cognitive scientist at the University of New South Wales. My research focuses on human concept learning, reasoning and decision making.