Randomization of presentation of columns in trial with last column always last

PennController for IBEX Forums Support Randomization of presentation of columns in trial with last column always last

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #7756
    gg110
    Participant

    Hi Jeremy,

    I’m trying to randomize the order of the presentation of some stimuli in such a ways that interference words are presented in some random order, and the target stimulus is presented at the end.
    The structure of the .csv file that I’m using with Template is

    set1,	set2,	set3,	set4,	target
    aa,	bb,	cc,	dd,	could gore
    ee,	ff,	gg,	hh,	deep cot
    ii,	jj,	kk,	ll,	keen lap

    and so I want for any given participant, for example, to be presented with set4, set2, set3, set1, target or set2, set3, set1, set4, target, etc.

    The rows are randomized with randomize(), but I can’t figure out how to randomize the set_ columns.

    I have the following:

    Sequence( "consent", "intro", "local_recorder", "Checking_audio", "Checking_recording", "instructions", sepWith("sendAsync",randomize("repetition")), "questionnaire", "sendSoon", SendResults() , "final" )
    
    Template("speecherrors.csv", row => 
        newTrial("repetition",
            defaultText
                .css("p")
                .center()
                .print()
            ,
            newText("Please repeat the following sets of words as fast as you can when they appear on the screen. Press start to display them.")
                .css("p")
            ,
            newButton("Start")
                .log()
                .center()
                .print()
                .wait()
                .remove()
            ,
            newTimer("wait", 1000)
                .log()
                .start()
                .wait()
            ,
            newMediaRecorder("speech_set1", "audio")
                .log()
                .record()
            ,
            newText( "blank line" )
                .hidden()
            ,
            newText("set1", row.set1)
                .log()
            ,
            newTimer("wait", 3000)
                .log()
                .callback(getMediaRecorder("speech_set1").stop())
                .start()
                .wait()
            ,
            getText("set1")
                .remove()
            ,
            newTimer("wait", 1000)
                .log()
                .start()
                .wait()
            ,
            newMediaRecorder("speech_set2", "audio")
                .log()
                .record()
            ,
            newText("set2", row.set2)
                .log()
            ,
            newTimer("wait", 3000)
                .log()
                .callback(getMediaRecorder("speech_set2").stop())
                .start()
                .wait()
            ,
            getText("set2")
                .remove()
            ,
            newTimer("wait", 1000)
                .log()
                .start()
                .wait()
            ,
            newMediaRecorder("speech_set3", "audio")
                .log()
                .record()
            ,
            newText("set3", row.set3)
                .log()
            ,
            newTimer("wait", 3000)
                .log()
                .callback(getMediaRecorder("speech_set3").stop())
                .start()
                .wait()
            ,
            getText("set3")
                .remove()
            ,
            newTimer("wait", 1000)
                .log()
                .start()
                .wait()
            ,
            newMediaRecorder("speech_set4", "audio")
                .log()
                .record()
            ,
            newText("set4", row.set4)
                .log()
            ,
            newTimer("wait", 3000)
                .log()
                .callback(getMediaRecorder("speech_set4").stop())
                .start()
                .wait()
            ,
            getText("set4")
                .remove()
            ,
            newTimer("wait", 1000)
                .log()
                .start()
                .wait()
            ,
            newMediaRecorder("speech_target", "audio")
                .log()
                .record()
            ,
            newText("target", row.target)
                .log()
            ,
            newTimer("wait", 3000)
                .log()
                .callback(getMediaRecorder("speech_target").stop())
                .start()
                .wait()
            ,
            getText("target")
                .remove()
        )
    )
    
    Template( "autismquotient.csv", row =>
        newTrial("questionnaire",
            newText("<p>Please choose the response that <strong>best</strong> describes how strongly the statement applies to you.</p>")
                .center()
                .print()
            ,
            newText("q", row.aquestions)
                .log()
                .center()
                .print()
            ,
            newText("blank line")
                .print()
                .hidden()
            ,
            newScale("rating", "Strongly agree", "Slightly agree", "Slightly disagree", "Strongly disagree")
                .log()
                .center()
                .css("border", "solid 1px black")
                .labelsPosition("right")
                .print()
                .wait()
            ,
            newText("blank line")
                .print()
                .hidden()
            ,
            newButton("click", "Submit")
                .center()
                .print()
                .wait()
        )
    )

    https://upenn.pcibex.net/r/imWBEL/

    So right now, the presentation of the stimuli is just filler (hard-coded sequentially), because I want them to be presented randomly but I wasn’t sure what to use to present those specific columns in a random order.
    Also, the reason I coded it the way above is because I want the user to only need to click Start once at the beginning of a trial to present all items one at a time without needing to click to move forward to the next pair until a new trial begins.

    • This topic was modified 2 years, 3 months ago by gg110.
    #7759
    Jeremy
    Keymaster

    Hi,

    You can reference the keys set1, set2, set3 and set4 in an array and shuffle it using Ibex’s fisherYates:

    Template("speecherrors.csv", row =>
        newTrial("repetition",
            defaultText
                .css("p")
                .center()
                .print()
            ,
            newText("Please repeat the following sets of words as fast as you can when they appear on the screen. Press start to display them.")
                .css("p")
            ,
            newButton("Start")
                .log()
                .center()
                .print()
                .wait()
                .remove()
            ,
            newTimer("wait", 1000)
                .log()
                .start()
                .wait()
            ,
            newMediaRecorder("speech_set1", "audio")
                .log()
                .record()
            ,
            newText( "blank line" )
                .hidden()
            ,
            row.sets = ["set1","set2","set3","set4"],  // array of keys
            fisherYates(row.sets)                      // shuffle the array
            ,
            newText("set1", row[row.sets[0]])          // use the first (shuffled) key
                .log()
            ,
            newTimer("wait", 3000)
                .log()
                .callback(getMediaRecorder("speech_set1").stop())
                .start()
                .wait()
            ,
            getText("set1")
                .remove()
            ,
            newTimer("wait", 1000)
                .log()
                .start()
                .wait()
            ,
            newMediaRecorder("speech_set2", "audio")
                .log()
                .record()
            ,
            newText("set2", row[row.sets[1]])          // use the second (shuffled) key
                .log()
            ,
            newTimer("wait", 3000)
                .log()
                .callback(getMediaRecorder("speech_set2").stop())
                .start()
                .wait()
            ,
            getText("set2")
                .remove()
            ,
            newTimer("wait", 1000)
                .log()
                .start()
                .wait()
            ,
            newMediaRecorder("speech_set3", "audio")
                .log()
                .record()
            ,
            newText("set3", row[row.sets[2]])          // use the third (shuffled) key
                .log()
            ,
            newTimer("wait", 3000)
                .log()
                .callback(getMediaRecorder("speech_set3").stop())
                .start()
                .wait()
            ,
            getText("set3")
                .remove()
            ,
            newTimer("wait", 1000)
                .log()
                .start()
                .wait()
            ,
            newMediaRecorder("speech_set4", "audio")
                .log()
                .record()
            ,
            newText("set4", row[row.sets[3]])          // use the fourth (shuffled) key
                .log()
            ,
            newTimer("wait", 3000)
                .log()
                .callback(getMediaRecorder("speech_set4").stop())
                .start()
                .wait()
            ,
            getText("set4")
                .remove()
            ,
            newTimer("wait", 1000)
                .log()
                .start()
                .wait()
            ,
            newMediaRecorder("speech_target", "audio")
                .log()
                .record()
            ,
            newText("target", row.target)
                .log()
            ,
            newTimer("wait", 3000)
                .log()
                .callback(getMediaRecorder("speech_target").stop())
                .start()
                .wait()
            ,
            getText("target")
                .remove()
        )
        .log("first", row[row.sets[0]])   // log the first shuffled key
        .log("second", row[row.sets[1]])  // log the second shuffled key
        .log("third", row[row.sets[2]])   // log the third shuffled key
        .log("fourth", row[row.sets[3]])  // log the fourth shuffled key
        .log("target", row.target)        // log the target word too
    )

    Jeremy

    #7760
    gg110
    Participant

    Great! Thank you for your help.

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.