Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stimulus generation function #1

Open
CrumpLab opened this issue Aug 6, 2019 · 1 comment
Open

Stimulus generation function #1

CrumpLab opened this issue Aug 6, 2019 · 1 comment

Comments

@CrumpLab
Copy link
Owner

CrumpLab commented Aug 6, 2019

It would be nice to have helper functions for generating stimuli. For example, a set of stimuli in jsPsych for a Stroop experiment can be defined in an object as follows:

/*defining stimuli*/
var test_stimuli = [
  {
    stimulus: "<p style='color:red;font-size:60pt;'>RED</p>",
    data: { stim_type: 'congruent', response: 'r'}
  },
  {
    stimulus: "<p style='color:blue;font-size:60pt;'>RED</p>",
    data: { stim_type: 'incongruent', response: 'b'}
  },
  {
    stimulus: "<p style='color:green;font-size:60pt;'>RED</p>",
    data: { stim_type: 'incongruent', response: 'g'}
  },
  {
    stimulus: "<p style='color:yellow;font-size:60pt;'>RED</p>",
    data: { stim_type: 'incongruent', response: 'y'}
  }

The above defines 4 individual items, and it takes a bit of copying and pasting to define the remaining combinations.

GOAL

It would be nice to have the stimuli described in table, say tidy format like a dataframe:

html word color congruency
red red red con
green red green inc
blue blue yellow inc

Then, write a function that converts the data.frame to the JS object format.

@CrumpLab
Copy link
Owner Author

CrumpLab commented Aug 6, 2019

Deciding to use this thread to think about what I'm doing while doing it...

Something like this defines a data.frame in R that codes aspects of the stimulus set:

stroop_stim <- data.frame( stimuli = length(16),
                           word = rep(c("red","green","blue","yellow"), each=4),
                           color = rep(c("red","green","blue","yellow"), 4),
                           response = rep(c("r","g","b","y"), 4),
                           congruency = length(16)) %>%
  mutate(congruency = as.numeric(word==color)) %>%
  mutate(congruency = recode(congruency, `1` = "Con", `0` = "Inc"))

The stimulus column is empty and needs the appropriate html to define each stimulus. After that, the idea would be to write a function that translates this data frame to a JS object for jsPsych, with stimuli and data attributes.

But, maybe it would be helpful to also write a function that could take a dataframe like this one and generate the necessary html to describe the stimuli. The constructor would do something like, create

snippets and assign styles based on entries in the table...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant