Your first Experiment Script!

Today we are going to program a simple choice Experiment based on Experiment 3 reported in Kusev et al. (2007). You are going to learn how to present text stimuli on the screen, wait for a keyboard response to indicate a preference, and randomise stimuli order. We will also look at the resulting data file from running the Experiment. We will not implement all the stimuli, or all the features from the Kusev et al. (2007) Experiment. We will start small.

Kusev et al. (2007)

In Experiment 3, Kusev and Colleagues presented each Participant with 231 choices between a varying sure outcome and a constant probablistic outcome (with varying probabilities). Each choice was presented as a text string. Furthermore, they split participants into 4 conditions, with each condition receiving a slightly different phrasing of the choice scenario.

We are not going to implement an Experiment with all 231 choices and all 4 conditions. Instead, for our Experiment we will only have 1 condition and 21 choices. To create the stimuli, you can pick any of the four conditions, and any of the 11 probability levels (i.e. 0.01, 0.05 … 0.95, 0.99), but must present all 21 sure amounts.

Inquisit Basics

Last week we discussed the overall structure of Inquisit. If you recall, to program an Experiment script in Inquisit you need to define what happens at 4 different levels of the experiment; 1) What your stimuli look like, 2) What happens on a trial, 3) what happens in each block, and 4) What happens at the level of the whole Experiment. This week we will discuss how you actually give Inquisit this information.

Elements and Attributes

All the information that Inquisit needs to run your Experiment needs to be passed to it by defining special objects called elements. Inquisit has hundreds of different elements that it uses, each of which has a specific role. Today we are going to use six different elements; items, text, trial, block, expt and defaults.

Each element in Inquisit has a list of properties or attributes that you can set, which define how this specific version of that element will behave. Different elements have different attributes that apply to them, depending upon the role of that particular element. For instance text element defines how text is presented on the screen. Therefore most of its attributes define aspects of the appearance of the text such as the font (fontstyle), justification (hjustify), text size (size), location on the screen (position) etc. In a single script you may use the same type of element multiple times (e.g. multiple text elements) with different settings for its attributes each time to produce different effects at different points in the Experiment.

The best way to learn about an element and its attributes is to look at the Help page for the element. The easiest way to get the help file is to type the name of the element into the search bar under the Help menu at the top of the screen. Try this for the text element. The help file should contain a list of attributes that can be passed to text, each with a link to the help file for that attribute, as well as other useful information, like examples of usage, and an explanation of what the element does (under Remarks). You can also search directly for a attribute help file. The Help file for an attribute contains similar information. One useful piece is the list of elements that the attribute can be applies to, given under Applies to.

Creating an Element.

Creating an element is very straightforward. The first step is to type the tags for the element in your script, here is an example for a text element: <text firsttext>
</text>

For all elements the format of these tags is the same. For the open-tag (i.e. the first line of the script), you first type an < then the name of the type of element you want to create (in this case text). Then you give a name to this element that you will use later if you refer to it in the code for another element. here I have chosen the name firsttext. You then close the tag >.

An open-tag lets Inquisit know that you are now going to define attributes for this specific element. The close-tage (second line of script, which starts with </ rather than <), tells inquisit that you are finished with this element. Therefore any attributes that you want to define for this element need to be typed between the two tags. For instance we could set the justification of this text to left as follows: <text firsttext>
/hjustify=left
</text firsttext> Each attribute you want to set should be on a separate line starting with / followed by the attribute name (in this case hjustify).

Linking Elements

All elements have attributes which define how this element links to the other elements in your script. Inquisit is set up in a very heirarchical structure, so an element will refer to other elements that are lower than it in the hierarchy (e.g. block elements refer to trial elements), and will themselves be referred to by elements higher in the heirarchy. The attributes in the higher element are then used to define how the lower element is used. For example one of the elements that can be referred to in a text element is an item element, which is a list of items that the attributes of the text element should be applied to. For instance, if we had created an item called stimlist we could tell Inquisit that firsttext should use this particular item list with the following code:

<text firsttext>
/items=stimlist /hjustify=left
</text>

That covers the absolute basics. You’ll learn more as we go through the exercises.

Exercises

1. Getting Started

After opening Inquisit the first step we will take is to create a new script file. You can do this either from the menu file>new or by clicking on the blank page. Before we go further save the script in the following format surname_wpa2.iqx. This is the file you will email to me at the conclusion of class.

Now that you have a script file, copy the following code into the top of your file:

<defaults>
/quitcommand = (Ctrl+'e')
/fontstyle=("Arial", 3%)
</defaults>

We will put this at the top of all scripts from now on. In it we have created an element of type defaults This is a bit different from the other elements we will define, as it doesn’t get a name because you won’t be creating multiple elements of this type. As its name suggests this element allows us to define some default behaviour in our script that will be employed unless an element directly contradicts it.

The two attributes we have defined for defaults are fontsyle which sets the default font to be used as Arial unless a specific element says otherwise and quitcommand. The quitcommand attribute sets a key combination that can be used to exit the Experiment at any time. I strongly recommend you always include a quitcommand and always check if there is a quitcommand before using anyone elses code.

Use the Help function to leanr more about these.

2. Creating our Stimuli

There are two elements that are important this week for creating our stimuli. The first is the item element, where we define our stimuli. The second is the text element where we tell inquisit how the stimuli should look.

a. Creating Items

This week our stimuli are just going to be a list of sentences. If you look at the Help file for the item element you will see that one way you can use this element is to create a list of text element stimuli. Each attribute in the list is just the specification of a number stimuli. For example the following code created an item list (called stimlist) that is just a single item, displaying text called item 1:

<item stimlist>/1=“item 1”

Alter this code, so that instead the first item of the list is the first choice that you want to be displayed to participants. Then alter the code further so that the list contains 21 items, rather than a single item.

To see the answer just click on the code button (ignore the #, they are just a necissity for hiding the code)

#<item stimlist>
#/ 1="(a) 50% chance of winning $600 or (b) a sure gain of $1"
#/ 2="(a) 50% chance of winning $600 or (b) a sure gain of $30"
#/ 3="(a) 50% chance of winning $600 or (b) a sure gain of $60"
#/ 4="(a) 50% chance of winning $600 or (b) a sure gain of $90"
#/ 5="(a) 50% chance of winning $600 or (b) a sure gain of $120"
#</item>

#I haven't defined all 21 stimuli. Your list should have 21 not 5.
#You can see that in this code that we have 5 attributes defined for this item element, with the names of the attributes just numbers from one to five. The content of each attribute is then just a choice that we want to be displayed to participants.

Items don’t have to be text strings. For example you could also specify images that we want to be used as the individual stimuli (this is what we did last week).

b. Defining how items are displayed

Now that we have defined our stimuli, we need to specify how they should look when displayed on the screen. Because our stimuli are text, we can do this by defining a text element where we call this stimuli list. We can call this element anything we wish. I suggest using the name stimlist for the text element, to make it easy for you to tell that these two elements are related. You can have multiple different elements with the same name, as long as the elements are not of the same type (i.e. you can’t have 2 item elements called stimlist).

i.

Create the text element, and have it refer to your stimuli list.

#<text stimlist>
#/ items=stimlist
#</item>
ii.

I have mentioned some of the properties you can set for this text element above. use the Help function to view these properties. Lets set our attributes so that our stimuli will be displayed in the center of the screen, with center justification, and in Arial font. To get our stimuli in the center of the screen you’ll need to use the position attribute. This attribute takes 2 coordinates that can be defined in different ways. I recommend defining the coordinates in terms of percentages of the screen where (0%, 0%) would be the top left of the screen and (100%, 100%) would be the top right:

#<text stimlist>
#/ items=stimlist
#/ position = (50%, 50%)
#/hjustify = center
#/fontstyle=("Arial", 4%)
#</text>
iii.

The final step we need to take is to define in what order our stimuli will be displayed. This is also done at the level of text element. If you look at the help file you will see an attribute called text. This determines how text stimlist selects a stimuli from item stimlist to display each time it is called. For now set this attribute to sequential (i.e. /select=sequence). This means it should display all 21 items in order (we will check this later).

#<text stimlist>
#/ items=stimlist
#/ position = (50%, 50%)
#/hjustify = center
#/fontstyle=("Arial", 4%)
#/select = sequenc
#</text>

3. Creating our Trial

So far you have defined what your stimuli are, and what they look like. Now we need to tell Inquisit what it should do with these stimuli on a trial. This means that we need to create a trial element. Lets call this trial element choice to remind us that this is what we are asking participants to do on the trial. Create the element:

<trial choice>
</trial>

Think about what you want to happen on a trial?

For this week all we really want to happen on the trial is for the stimulus to be displayed at some point, and to stay up there until the participant responds. So first we will tell Inquisit how it should display stimuli.

a. Display Stimuli

To display the stimuli we need to set the stimulustimes attribute of our trial element. Stimulustimes determines both when dring the trial stimuli should be displayed, and what stimuli should be displayed at each time. We will use this attribute more extensively in the coming weeks, but for this week see if you can work out how to display one of the stimuli we have defined, right at the start of the trial.

#<trial choice>
# /stimulustimes = [0=stimlist]
# </trial>

# In stimulustimes we define at what point in the trial a stimulus should be displayed, and what the stimuli should be (by giving the name of a text element, picture element etc.). This is all contained with []. In this case at 0 ms a stimulus should be displayed as defined by the text stimlist element (which in turn will call the item stimlist element). You can also use the stimulusframes attribute to achieve the same result. The only difference is that the time is specified in monitor refresh intervals (frames) rather than ms. 

b. Collect Responses

Now we need to tell Inquisit how to collect responses on the trial. In this case we will pretend that we have asked participants to respond by using the keyboard. In particular we have told them to press the A key if they wish to choose the risky option, and the B key if they wish to choose the sure option.

Given this, we need to tell Inquisit that it should be waiting for one of these two keys to be pressed. We can do this by setting the validresponse attribute. See if you can work out how to do it.

#<trial choice>
# /stimulustimes = [0=stimlist]
# /validresponse = ("a", "b")
# </trial>

#We can set as many valid responses as we wish. Each one just needs to be included in the list given to validreponse inside quotation marks (""). Instead of spcifying keys by name you can also specify them by key code. This is besically a number assigned to the key. We won't cover how to do this.

4. Blocks and Experiments

a. Blocks

The next step is to define what a block of our Experiment looks like, by creating a block element. We only have a single block of trials in our study. If you look at the Help file you will see that there are many behaviours we can define at the block level. As this Experiment is very simple, and we aren’t including instructions yet, we will only need to define the trials element.

The trials attribute is somewhat (not really) similar to the stimulustimes attrbute and somewhat similar to the select attribute of the text element. The trials attribute lets us define how many trials there should be in the block, and what type of trial should be displayed on each of those trials. For no we want to display the same trial type on every trial (trial choice) and we want to display all 21 version of this trial. Try it yourself, giving your block element the name choiceblock

#<block choiceblock>
# /trials = [1-21=choice]
# </block>

#In the above code we have told Inquisit that our block contains 21 trials, and that for trials 1-21 of these trials, Inquisit should display one of trial choice. Because we have already defined in our text element how stimuli should be sampled, this will insure that all 21 stimuli are displayed in sequential order.

b. Experiment

We are not going to discuss the expt element either much this week. Like the block element the exp can be used for displaying instruction pages and for setting the order in which aprticipants should view different parts of the Experiment. While the block element defines the order of trials in a block the expt element defines the order of blocks in a similar way. We only have one block and want it to be displayed once. Create an expt element to do this.

#<expt>
# /blocks = [1=choiceblock]
# </expt>

#In the above code we have told Inquisit that our block contains 21 trials, and that for trials 1-21 of these trials, Inquisit should display one of trial choice. Because we have already defined in our text element how stimuli should be sampled, this will insure that all 21 stimuli are displayed in sequential order.

Congratulations, you should now have a working Experiment. Try it out before you attempt the rest of the Exercises

5. The datafile

By default Inquisit generates a datafile when you run the Experiment. Open up the file and have a look. The default set-up for the datafile is that each row will be a separate trial, and each column a piece of information about that trial. For instance the blockcode column tells you which block the trial was part of while the trialcode column tells you which type of trial was displayed.

For now the most important columns are the response column, which indicates which key the participant pressed (as a keycode, A=30 and B=48), and the stimulusnumber1 and stimulusitem1 which tell us which stimulus was displayed on that trial. Check that the order the stimulus were displayed matches what you expected from how you defined item selection.

Most of the columns other columns give you information that should match decisions you made about the set up of your experiment, such stimulus location and trial start times.

if you ran an second participant on this Experiment, the data for the participant would be displayed in the same datafile directly underneath the current participant.

6. Randomise trial order

Currently our Experiment should display all 21 stimuli in sequential order. Change this so that instead they are in random order, with no stimuli displayed twice (hint: look at the text element)

#<text stimlist>
#/ items=stimlist
#/ position = (50%, 50%)
#/hjustify = center
#/fontstyle=("Arial", 4%)
#/select = noreplace
#</text>

7. Change Stimulus Dsiplay Times

Currently each trial begins immediately after the other. Let give participants a short break of 0.5 seconds between each trial (hint: use the trial element).

#<trial choice>
# /stimulustimes = [500=stimlist]
# /validresponse = ("a", "b")
# </trial>

Now however you have a blank screen between each trial. lets instead tell them they should get ready. This will require us to make two stages. Firstly we will want to create a new text element (we’ll call it ready) that determines where and how this instruction should be displayed. To do this normally we’d create an item element as well, but if you only want to use a small list of possible text strings (or in this case only one), you can define the items directly at the items attribute of the text element (e.g. /items =("Get Ready")). Lets display this in the center of the screen, like the other text, in a smaller font.

#<text ready>
#/ items=("Get Ready")
#/ position = (50%, 50%)
#/hjustify = center
#/fontstyle=("Arial", 3%)
#</text>

Now add this to our stimulustimes.

#<trial choice>
# /stimulustimes = [0=ready; 500=stimlist]
# /validresponse = ("a", "b")
# </trial>

What happens if you respond while the Get Ready command is still on the screen?

8. Add some reminder instructions to all trials

Sometimes it can be difficult for participants to remmber what the response keys are they need to use. I want you to create a reminder that will appear at the top of the screen on every trial of our block. This reminder should say “Press the A key if you prefer the risky option on the left, press the B key if you prefer the sure option on the right”. The first step to do this is to create another text element with this information (remember to set the position.)

#<text reminder>
#/ items=("Press the A key if you prefer the risky option on the left, press the B key if you prefer the sure option on the right")
#/ position = (50%, 10%)
#/hjustify = center
#/fontstyle=("Arial", 3%)
#</text>

Now we need to determine where this should be displayed. What happens if you try to add it in at the trial level during using stimulustimes?

Because we want this to be displayed on every trial in the block the appropriate place to call this new text element is at the block level. At the block level you can set stimuli that you want to be displayed in the background of every trial by using the bgstim attribute. Give it a go.

#<block choiceblock>
# /trials = [1-21=choice]
#/bgstim = (reminder)
# </block>

9. Change the number of trials

Change the number of trials so that there are more trials than there are stimuli. What happens? What about if you re-set the selection method back to sequence?

Further Exercises

If you have reached this far good work. The following are some slightly more advanced exercises where you will have to set up two different conditions in your Experiment.

10. Create another stimuli set.

Currently you should have created a single set of stimuli which corresponds to one of the conditions in Kusev et al. (2009). The first step is to create a second set for another one of the conditions. First create the new item element containing the list of stimuli (remember to give it a different name to the current list, I’ll use stimlist2:

#<item stimlist2>
#/ 1="(a) 50% chance of losing $600 or (b) a sure loss of $1"
#/ 2="(a) 50% chance of losing $600 or (b) a sure loss of $30"
#/ 3="(a) 50% chance of losing $600 or (b) a sure loss of $60"
#/ 4="(a) 50% chance of losing $600 or (b) a sure loss of $90"
#/ 5="(a) 50% chance of losing $600 or (b) a sure loss of $120"
#</item>

Then you need to specify a new text element (lets stay stimlist2), defining how these items are displayed.

#<text stimlist2>
#/ items=stimlist2
#/ position = (50%, 50%)
#/hjustify = center
#/fontstyle=("Arial", 4%)
#/select = noreplace
#</text>

#I'm using the same display set up for both. Otherwise I would have a confound

11. New Trial and Block elements

Similarly you will need to create new trial and block level elements. Do you need to create a new version of the Get Ready or Instruction Reminder stimulus? Why or why not?

#<trial choice2>
# /stimulustimes = [0=ready; 500=stimlist2]
# /validresponse = ("a", "b")
# </trial>
#<block choiceblock2>
# /trials = [1-21=choice2]
#/bgstim = (reminder)
# </block>

12. Seperate the blocks.

Currently we have 2 blocks, one block runs the original version of our study, the other runs the second condition. Now we want to set it up so that half of our participants see Block 1 and half see Block 2. There are several ways we can do this. We are going to use one that takes advantage of the fact that you always have to enter a Subject number at the start of every Inquisit study. This subject number can then be used by the subjects attribute of the expt element.

First create a second version of your expt element, that runs the new block instead of the old one.

#<expt>
# /blocks = [1=choiceblock2]
# </expt>

#The only change is in the block name

Now we will set it up so that every subject with an odd subject number does block 1 and every subject with an even number does block 2. The way the subjects attribute works is that it defines a condition upon which the expt element should be run. In particular it divides the subject id by a number (defined by you) and runs the specified version of the experiment if the remainder of this division meets some criteria. To make condition assignment work, you will need to define a separate subjects attribute for each of your 2 expt elements.

#<expt>
# /blocks = [1=choiceblock]
#/subjects = (1 of 2)
# </expt>

#Here the original choice block will run whenever their is one left over after dividing the subject id by 2 (i.e. the number is odd)
#<expt>
# /blocks = [1=choiceblock2]
#/subjects = (2 of 2)
# </expt>

#Here the original choice block will run whenever their is no remainder (remainder is 2) after dividing the subject id by 2 (i.e. the number is odd)
Good work, you did everything. Email me your script for the week and then you can leave. If this was really easy let me know so that I can adjust the content for next week.