Timers & Randomization

Adding Timers & Delays

When you tried out the experiment, you probably noticed that the trials came in rapid sequence without any pauses between them, with picture selection (or end of audio) marking the end of the trial, followed by an immediate transition to the next trial.
It would probably be a good idea to add some time both at the beginning and at the end of a trial, to create a brief pause between trials. To do this, simply use newTimer:

your script should also still contain the welcome trial above this

[js new=”3-6,32-35″]Template( variable =>
newTrial(
newTimer(500)
.start()
.wait()
,
newAudio(“description”, variable.AudioFile)
.play()
,
newText(variable.Description)
.unfold(2600)
,
newImage(“two”, variable.PluralImageFile)
.size(200,200)
,
newImage(“one”, variable.SingularImageFile)
.size(200,200)
,
newCanvas(450,200)
.add( 0 , 0 , getImage(“two”) )
.add( 250 , 0 , getImage(“one”) )
.print()
,
newSelector()
.add( getImage(“two”) , getImage(“one”) )
.keys( “F” , “J” )
.log()
.wait()
,
getAudio(“description”)
.wait(“first”)
,
newTimer(500)
.start()
.wait()
)
.log( “ID” , getVar(“ID”) )
.log( “Item” , variable.Item )
.log( “Ending” , variable.Ending )
.log( “Group” , variable.Group )
)[/js]

(Note that using a template makes things much easier when we want to update details of our trial structure for a whole sequence of trials!)

Following the general logic of PennController, creating a timer element in the cache does not on its own start the timer, in much the same way that creating a text or an image element does not print it. If you don’t want to freeze your experiment, make sure that a timer has been started prior to a .wait command relating to it being executed.

Randomization

There are at least two things you might want to randomize in your experiment.

The images’ positions

Having a static layout for your stimuli, with fixed positions for images of a certain type, is usually not a good idea, unless it was part of your design for some reason.
In our case, it could be that participants are in general faster to choose any image that appears on the left (maybe English readers tend to process visual information from left to right, leading to reaction time advantage for images on the left) and since our current version always prints the two images on the left, this creates a potential confound that could wrongly lead us to conclude that people are faster to notice the absence of -s than the presence of -s.

To remedy this, we can randomly shuffle the positions of all the elements contained in a selector using the command .shuffle:

[js new=”26″]Template( variable =>
newTrial(
newTimer(500)
.start()
.wait()
,
newAudio(“description”, variable.AudioFile)
.play()
,
newText(variable.Description)
.unfold(2600)
,
newImage(“two”, variable.PluralImageFile)
.size(200,200)
,
newImage(“one”, variable.SingularImageFile)
.size(200,200)
,
newCanvas(450,200)
.add( 0 , 0 , getImage(“two”) )
.add( 250 , 0 , getImage(“one”) )
.print()
,
newSelector()
.add( getImage(“two”) , getImage(“one”) )
.shuffle()
.keys( “F” , “J” )
.log()
.wait()
,
getAudio(“description”)
.wait(“first”)
,
newTimer(500)
.start()
.wait()
)
.log( “ID” , getVar(“ID”) )
.log( “Item” , variable.Item )
.log( “Ending” , variable.Ending )
.log( “Group” , variable.Group )
)[/js]

It is important here that .shuffle gets executed after the images are printed (through the canvas’ .print command above) and added to the selector (otherwise, there is nothing to shuffle) but also before the command .keys is executed: this way, shuffling happens before key assignment, and whichever image ends up to the left and right will be respectively associated with the F and J keys. If .keys were executed before .shuffle then the association would take place before the shuffling. (Such a scenario would maybe make sense if you wanted to respectively associate the two and one images with the numeric keys 2 and 1 regardless of where each image ends up on the screen.)

The sequence of trials

Manipulating the order in which the trials are presented requires labeling them first. Note that labels are not unique IDs: two trials can share the same label, which we will make use of.

For all the trials you define with newTrial(...), you can specify a label using a string as the first argument: newTrial( "label" , ... ).

(Note that some steps in the trial sequence require a slightly different format. For example, you can define a label for the command SendResults like this: [js]SendResults( “label” )[/js].)

To gain explicit control over the order of the overall trial sequence, you can specify your own order using the command Sequence:

[js new=”3″ highlight=”5,32,75,78″]PennController.ResetPrefix(null)

Sequence( “welcome” , randomize(“experiment”) , “send” , “final” )

newTrial( “welcome” ,
defaultText
.print()
,
newText(“

Welcome!

“)
,
newText(“

In this experiment, you will have to report which of two pictures matches a description.

“)
,
newText(“

Press the F key for the picture on the left, or the J key for the picture on the right.

“)
,
newText(“

Please enter your ID and then click the button below to start the experiment.

“)
,
newTextInput(“inputID”)
.print()
,
newButton(“Start”)
.print()
.wait()
,
newVar(“ID”)
.global()
.set( getTextInput(“inputID”) )
)
.log( “ID” , getVar(“ID”) )

Template( variable =>
newTrial( “experiment” ,
newTimer(500)
.start()
.wait()
,
newAudio(“description”, variable.AudioFile)
.play()
,
newText(variable.Description)
.unfold(2600)
,
newImage(“two”, variable.PluralImageFile)
.size(200,200)
,
newImage(“one”, variable.SingularImageFile)
.size(200,200)
,
newCanvas(450,200)
.add( 0 , 0 , getImage(“two”) )
.add( 250 , 0 , getImage(“one”) )
.print()
,
newSelector()
.add( getImage(“two”) , getImage(“one”) )
.shuffle()
.keys( “F” , “J” )
.log()
.wait()
,
getAudio(“description”)
.wait(“first”)
,
newTimer(500)
.start()
.wait()
)
.log( “ID” , getVar(“ID”) )
.log( “Item” , variable.Item )
.log( “Ending” , variable.Ending )
.log( “Group” , variable.Group )
)

SendResults( “send” )

newTrial( “final” ,
newText(“

Thank you for your participation!

“)
.print()
,
newText(“

Click here to validate your participation.

“)
.print()
,
newButton(“void”)
.wait()
)[/js]

Our command [js]Sequence( “welcome” , randomize(“experiment”) , “send” , “final” )[/js] does not change the order much here, since it still corresponds to the order of trial elements in the script. However, the additional specification of [js]randomize(“experiment”)[/js] makes sure that all the trials labeled experiment (all the table-generated trials, see line 32) will be run in a random order.

The list of commands like randomize that you can use within Sequence (which come from the basic Ibex setup, and are not special to PennController) are listed in the Ibex manual.


Next: Data analysis in R