Reply To: Randomizing trials, with 1/5 of trials followed by a comprehension question

PennController for IBEX Forums Support Randomizing trials, with 1/5 of trials followed by a comprehension question Reply To: Randomizing trials, with 1/5 of trials followed by a comprehension question

#9552
Jeremy
Keymaster

Hi,

1. Starting with line 316 of Context_5y_mot_1.csv, some <br>s are replaced with [br]s

2. Each Template command browses the whole CSV file and outputs as many trials labeled accordingly. So your script outputs 120 trials, half labeled “trial” and half labeled “trial-Q”, which are duplicates of each other except for the addition of a comprehension question for the latter.

I think the part subsequence(repeat(randomize("trial"),4),"trial-Q") does something like, I randomly draw 5 trials from the 60 trials, and for these 5 trials, the first 4 trials are assigned to the “trial” template (with no comprehension question) and are randomized for order, and the last trial is assigned to the “trial-Q” template (with a comprehension question).

This is not how Template and trial references work. Each trial has a label, and you can refer to those labels in setting up the experiment’s sequence. Simply referencing "trial-Q" will refer to all the trials labeled “trial-Q” (60 trials in your case); randomize("trial") represents all the trials labeled “trial” (again, 60 trials in your case) but in a randomized order. repeat(randomize("trial"),4) represents a way of iterating over series of four trials from that set of 60 trials; inserting it inside subsequence will iterate until the series exhausts all the trials from the set. So subsequence(repeat(randomize("trial"),4),"trial-Q") will repeat a series of 4 (different) trials labeled “trial” followed by a (different) trial from the set of the 60 trials labeled “trial-Q”, until all the former have been drawn: in the end, you’ll have 15 subsequences of a series of 4 “trial” trials followed by one “trial-Q” trial, so all the 60 “trial” trials, and 15 “trial-Q” trials. Note that those 15 “trial-Q” trials will have been generated from the same CSV lines as 15 of the “trial” trials, so you’ll have duplicates, in that sense

If you know in advance you’ll have 60 trials, the easiest thing to do is create an array of 60 boolean entries, 15 true and 45 false, and shuffle that array. Then, you only generate 60 trials all labeled the same way, and pop the value at the top of the array for each trial: if it’s true then you include the question, otherwise you don’t.

arrayTrialQ = [...Array(60)].map((v,i)=>i<15)
fisherYates(arrayTrialQ)

Template("Context_5y_mot_1.csv" , row =>
  newTrial("trial",
    newVar("correct").global()
    ,
    newTimer("pre-trial", 500).start().wait()
    ,
    newText("target1", row.context).center().print()
    ,
    newText("line1", " ").center().print()
    ,
    newScale("answer", row.D1, row.D2) 
      .center()
      .button()
      .print()
      .log()
      .wait()
    ,
    getScale("answer")
      .test.selected(row.ans==row.D1 ? row.D1 : row.D2)
      .success( getVar("correct").set(true) )
      .failure( getVar("correct").set(false) )
      .remove()
    ,
    newTimer("post-trial", 500).start().wait()
    ,
    getText("target1").remove()
    ,
    getText("line1").remove()
    ,
    newVar("correctQ").global().set("NA")
    ,
    ...( arrayTrialQ.pop() == true ? [
      newText("target2", row.question)
        .center().print()
      ,
      newText("line2", " ")
        .center().print()
      ,
      newScale("answer-Q", "[Yes]", "[No]") 
        .center()
        .button()
        .print()
        .log()
        .wait()
      ,
      getScale("answer-Q")
        .test.selected(row.ansQ=='[Yes]' ? "[Yes]" : "[No]")
        .success( 
            getVar("correctQ").set(true),
        )
        .failure( 
            getVar("correctQ").set(false),
        )
      ,
      newTimer("post-Q", 500).start().wait()
    ] : [] )
  )
  .log("context", row.context)
  .log("Correct", getVar("correct"))
  .log("Question", getVar("correctQ"))
)

Then just use randomize("trial") in Sequence instead of the whole subsequence command. In the results file, the “Question” column will read “NA” for those trials without a comprehension question, and “true” or “false” for the ones with a comprehension question

Jeremy