Today’s Experiment is a risky choice task where the gambles participants choose are played immediately following the choice ( Jessup, Bishara & Busemeyer, 2008 ). On each trial of the Experiment participants were presented with a choice between a certain amount of money (3 cents) and 1 of 10 gambles (split into 2 types- high probability gambles and low probability gambles). If the participant chose the gamble, it was played and the outcome added to their payment at the end of the Experiment. Similarly if they chose the certain option, this amount was added to their payment.
Importantly howeever half of participants (the feedback condition), also saw after each trial the amount of money they had just earnt. The other half did not (no feedback). Today we are going to program this basic task. This will combine several features we have discussed before in a more detailed way such as:
We will also introduce a new type of element (a list). And if you have time, we will also use images for our stimuli (like in the original paper) and link the presentation of these images to the list.
For now we will focus only on the high-probability trials where the choice is between approximately:
Win 3c for sure Win 4c with probability .8; win 0c otherwise.
We will implement both the feedback and no feedback conditions.
Like last week we are going to start a new Inquisit file for this weeks exercises. Call this file surname_wpa10.iqx. This is the file you will send me at the end of the class. I strongly recommend that you copy the defaults element from last weeks script into the top of this file, so that you have an easy way to terminate the Experiment.
While the original Experiment uses pie charts for stimuli, to beging with we will program our Experiment using only text stimuli. In our first version of the task we will, essentially, program the no feedback version of the task for a single high probability gamble. This gamble will be repeated 5 times. You will program it so that the Gamble “Win 4c with probability .8; win 0c otherwise” is shown on the left of the screen and the Sure option “Win 3c for sure” is shown on the right. Participants will then respond left or right using the A and L keys.
First we’ll create our stimuli. Because there is, currently only a single trial type, we can do this at the level of the text element. Create text elements such that “Win 4c with probability .8; win 0c otherwise” is shown on the left of the screen and “Win 3c for sure” on the right. Keep the size of the text the same for both the Gamble and Sure option. This is similar to the first step in WPA5, so should be familiar to you.
<text Sure>
/ items = ("Win 3c for sure")
/ position = (80%, 50%)
</text>
<text Gamble>
/ items = ("Win 4c with probability .8; win 0c otherwise")
/ position = (20%, 50%)
</text>
The position is the important feature here.
Now we want to create a trial to display our stimuli. Lets vreate the trial so that both our text stimuli are displayed simultaneously and participants can respond only by pressing the A and L keys. Also put a 500ms gap between trials. Again this should all be familiar from previous weeks.
<trial choice>
/pretrialpause=500
/stimulustimes = [0=Gamble; 0=Sure]
/validresponse = ("a", "l")
</trial>
Remember that you should list both the Gamble and Sure stimuli in the stimulutimes attribute with the same start time. If you give them separate times they will be displayed at spearate times, and response recording will only begin after the 2nd is displayed.
You could also put a delay in stimulustimes, rather than in pretrialpause. I prefer to use pretrialpause.
Finally, we don’t want to just present this trial once, we want to present it multiple times (lets start with 5 times). Check out WPA5 if you don’t remember (or most other weeks).
<block choice>
/trials =[1-5 = choice]
</block>
You can also nest this in an Experiment, although it is unnecessary at this stage.
<expt>
/blocks = [1=choice]
</expt>
Now that we have the basic choice task programmed, we’ll add on the feedback section. For simplicity we’ll display the feedback on a new trial, immediately following the participants choice.
First we’ll create a version where participants see the same feedback after every choice. In particular we’ll create a version where they see the feedback “You won 3c on this trial” after every trial, in the center of the screen. We’ll display the feedback for 2 seconds, and the participant doesn’t need to make a response to continue. You should be able to do this without my instructions, so I’ll hide both the instructions and code.
Instruction
The first sep is to create a text stimulus which contains our message "You won 3c on this trial". Youll need to set the position so that it appears in the center of the screen.
Code
<text money>
/ items = ("You won 3c on this trial")
/ position = (50%, 50%)
</text>
Instruction
As usual the next step is to define a trial to display this text stimulus. For this trial you want it to end after 2 seconds (think of the timeout attribute), and for there to be no responses the participant can make (i.e. validresponse). The stimulus should appear for the whole trial.
Code
<trial feedback>
/stimulustimes = [0=money]
/timeout=2000
</trial>
Instruction
Finally we need to set it up so that everytime our choice trial is shown the feedback trial is shown afterward. Controlling the order of trial is done at the block level. You could do this manually by listing 10 trials in the block (alternating between choice and feedback). However we have covered previously how we can use selection methods (i.e. sequence, noreplace) at the block level to specify how 2 or more trial types should be distributed in a block.
Code
<block>
/trials = [1-5=sequence(choice, feedback)]
</block>
Trialing this I found some inconsistent behaviour. If you want 5 trials of chocie and 5 trials of feedback alternating, normally I would put 1-10= etc. However when I tried this 20 trials were presented. Using 1-5 instead presents 5 of each for a total of 10. This is why it is important to test your code.
Now we will make the feedback contingent upon both the ooption participants chose and, when the gamble is chosen, the outcome of a random play of the gamble.
The way we will control our feedack is by creating a custom value/variable (using the values element), that we will replace/overwrite with a different amount of money at the end of each choice trial, depending on the amount of money the participant earnt that trial. We have use custom values before, as they are variables whch we have complete control over, being about to set their value at any point in the experiment, but also access their value whenever we want for use in the task.
For our first step create a custom value, call it earn and have it start the Experiment with a value of 0.
<values>
/earn = 0
</values>
Now that we have our variable to store the current earnings on each trial, the next easiest step is to update our text stimuli used during the feedback so that it displays this variable, rather than displaying 3c every time. In my code I called this text stimuli money. If I want to dsiplay the value of a variable in a line of text remember that I need to use the full name of the variable (i.e. element.variablename) and I need to to tell Inquisit to treat this variable as a variable, not as text (by placing the name inside <% X %>, so that Inquisit treats it as an expression.
<text money>
/ items = ("You won <%values.earn%> c on this trial")
/ position = (50%, 50%)
</text>
Now we have to define how this variable is updated. Firstly we’ll do this conditional on whether they chose the Gamble or the Sure option. For now we’ll pretend that the Gamble always has an outcome of 4c (we’ll change this in the next step). So we want to set it up so that if the participant chooses the Gamble (A key), the value of earn is updated to be 4c, and if they choose Sure (L key) it is updated to be 3c.
So we need to work out how to update the variable, and when to update it. Because we want to update it contingent upon the choice the participant made on the current trial, the easiest time to update it is at the end of the current trial. Therefore we will use the ontrialend attribute. If you recall, each call of ontrialend lets us give Inquisit an expression that it evaluates at the end of the trial. This expression can be a simple action or calculation (For instance values.earn = 3) or it can be a more complex Expression, such as an if statement, which first checks if a logigcal statement is true (e.g.g if the response on the trial equals a specific value), then carries out another operation (e.g. values.earn = 3) only if the first statement was true.
We will use IF statements to set up our conditional updating (if statements are also called conditional statements). We will create 2 separate ontrialend attributes on our trial. One will check whether the A key was pressed, and replace values.earn with 4c if it was. The other will check whether the L key was pressed, and replace values.earn with 3 if it is. Give this a try. To do this you need to access the response variable for the current trial. There are some additional reminders in the hint box.
Hint
1. To create an if statment use the if function (check the functions help file). It has the format if(X) Y, where X is the logical statement you want to be true and Y is the operation to be performed if it is
2. Two equals signs (X==Y) checks whether X is equal to Y. A single equal sign (X=Y), replaces X with Y.
3. If you want to get the response given on the trial, you need to reference the response variable for that trial, by specifying both the elementtype, elementname and variable (e.g. trial.trialname.response).
4. The response variable stores a number, not a key name. Each Key corresponds to a different number (A=30 and L=38 for instance)
Answer
<trial choice>
/pretrialpause=500
/stimulustimes = [0=Gamble; 0=Sure]
/validresponse = ("a", "l")
/ontrialend = [if(trial.choice.response == "30") values.earn = 4]
/ontrialend = [if(trial.choice.response == "38") values.earn = 3]
</trial>
You should now have 2 ontrialend elements, one that runs if the participants chooses the Gamble, and one that runs if they choose the Sure option. For the Sure option this now works perfectly. For the Gamble however there are actually two possible responses we want to show participants. We want to show them either a response of 4 or a response of 0, dependent upon the outcome of the gamble they chose. So to do this we need to 1) simulate a gamble, and 2) show different amounts contingent on this gamble.
To simulate our gamble and update our earnings with the result, we are going to use Inquisits ability to generate random numbers (which we somewhat covered in WPA 8), and create a third conditional ontrialend.
To simulate our gamble we need to define a process that will randomly (from our perspective) give a response of 4c 80% of the time and 0c 20% of the time. A relatively simple way to implement this is to take advantage of the fact that Inquisit can generate random samples from a uniform distribution. Before we cover how to do this, I’ll explain why this helps us achieve our goal.
First, imagine that I take a random sample from a uniform distribution bounded by 0 and 1. Because of the definition of a uniform distribution, every number between 0 and 1 has equal probability of being drawn. So 0.111 is just as likely to be drawn as 0.567, which is just as likely as 0.232 etc. If we did this enough times we would expect 80% of our sample to be below 0.8 (because 80% of the number betwen 0 and 1 are below 0.8) and 20% to be above 0.8 (the complement). Or alternatviely there is a probability of 0.8 that we will draw a number below 0.8 and probability of 0.2 we will draw a number above 0.8.
Therefore we could use this random draw from a uniform distribution to determine the payoff of our gamble. If a number less than the probability of winning (0.8) is drawn, then the participant wins. if it is greater than the probability of winning (0.8) then they lose.
So the first step is to generate this random number. Inquisit has a function, rand (X,Y), which generates a single random number between X and Y. At the start of each trial (ontrialbegin) we’ll generate a number using this function, and we’ll save into a new variable you will create, which we will call win. Remember to create the custom variable in you code.
<trial choice>
/pretrialpause=500
/ontrialbegin = [values.win = rand(0,1)]
/stimulustimes = [0=Gamble; 0=Sure]
/validresponse = ("a", "l")
/ontrialend = [if(trial.choice.response == "30") values.earn = 4]
/ontrialend = [if(trial.choice.response == "38") values.earn = 3]
</trial>
<values>
/earn = 0
/win = 0
</values>
Now we want to link this random number to the outcome paticipants recieve. We will do this at the end of the trial, by creating two version of the Gamble response ontrial end. One will run if the participant chose Gamble, and the random number is less than the specified winning probability. The other if the response if Gamble and the random number is greater than the winning probabitlity.
The first of these will set the earnings for the trial to the winning amount (i.e. 4c), the second will set it to the losing amount (i.e. 0c).
To create these Expressions, remember that you can combine multiple logical statements using either the OR (||) or AND (&&) operators. Which would be appropriate in this case?
Also remember that to check if X is strictly less than Y, use X<Y, while if you want to check if X is less than or equal to Y, use X<=Y.
<trial choice>
/pretrialpause=500
/ontrialbegin = [values.win = rand(0,1)]
/stimulustimes = [0=Gamble; 0=Sure]
/validresponse = ("a", "l")
/ontrialend = [if(trial.choice.response == "30"&&values.win<0.8) values.earn = 4]
/ontrialend = [if(trial.choice.response == "30"&&values.win>=0.8) values.earn = 0]
/ontrialend = [if(trial.choice.response == "38") values.earn = 3]
</trial>
In the original study participants weren’t always presented with exactly 4c as the winning amount for the gamble (in the high-probability choices). Instead 5 amounts were used; 3.75, 3.9, 4, 4.1 and 4.25c. Generally if we wanted to use these 5 amounts, we’d create an item list which has the full text for each amount to be displayed during the trial, e.g: <item amount>
/1 = "Win 3.75c with probability .8"
/2 = "Win 3.9c with probability .8"
etc. </item>
Our text element Gamble would then select from this item list (in a random order, as they were randomised in the Experiment). However, the porblem with this implementation is that we need to be able to access the amounts offered separate from the text, so that we can display the appropriate amount on the feedback page. To do this we are going to use a new type of element, called a list element.
A list element is a very flexible type of element that can be used to store any type of items (e.g. expressions, images, text, values etc.). The important point for our purposes is that you can give a list of items to a list element, and specify how these items should be selected. So it is similar to a text or picture element, but more flexible. We are going to create a list element which stores as its items the 5 values that we want to use for winning amounts. We will then specify that these amounts/values should be selected at random, and that if the list is called multiple times during a trial, the selection should only occur once per trial.
First we’ll create a new list element. We’ll call this element amount and we’ll start by listing our 5 values for its items attribute. This is similar to if we defined our item list within a text element.
<list amount>
/items=(3.75, 3.9, 4, 4.1, 4.25)
</list>
Now we want to specify that these items should be sampled randomly when the list is called. We can do this using the selectionmode attribute. This is similar to the select attribute of a text or picture element, but has different/less options. It accepts 3 inputs sequence (i.e. sequential order), random (i.e. randomly) or an expression (for instance you can tell it to match the item number of another element.)
<list amount>
/items=(3.75, 3.9, 4, 4.1, 4.25)
/selectionmode=random
</list>
The third attribute of interest to use is selectionrate. This attribute specifies how frequently a new item should be sampled when list is called. For instance if we set it to always, if we call the list multiple times in a trial each time a different item will be chosen. If we set it to block we would get the same item selected everytime within that block. we want this value to stay stable within a trial, so we will use trial.
<list amount>
/items=(3.75, 3.9, 4, 4.1, 4.25)
/selectionmode=random
/selectionrate=trial
</list>
Now that we have our list you need to learn how to actually use it during a trial. We have defined the items of our list as a list of values. We can call these values within a line of text just like we would one of our custom values/variables (i.e. earn) by using <% %>, as long as we know the name of the value/variables we are trying to call. If you look through the list of Properties of a list on the help page you will see that there is one called nextvalue. This gives the next value selected from the list, which is exactly what we want. Therefore we can just insert this named property into our Gamble text element.
<text Gamble>
/ items = ("Win <%list.amount.nextvalue%>c with probability 0.8,
win 0c otherwise")
/ position = (20%, 50%)
</text>
This is the only change we need to make to have the amount vary on the choice trial each time. We don’t need to make any changes at the trial or block level. If you run your code you will see that it now displays each amount once.
However it still always uses 4c as the winning amount on the feedback trials. So we need to change what is displayed on the feedback trial.
To do this we don’t actually need to make any changes to our feedback trial code. Why?
Because the amount of money won is actually calculated at the end of the choice trial, and then it is just passed through the values.earn variable to the feedback trial. So we need to change it at the choice trial.
So we need to change what happens at the end of our choice trial. For the Sure choice, and the Losing Gamble chocie everything stays the same. We only need to update the amount for when the participant picks the Gamble and wins. This amount is defiend in an ontrialend attribute as 4. All we need to do is replace this 4 with the amount actually used that trial. And from above we already know that list.amount.nextvalue will give us the amount of money used on this trial (remember that the selection is only updated once per trial). So you just need to repalce 4, with list.amount.nextvalue.
<trial choice>
/pretrialpause=500
/ontrialbegin = [values.win = rand(0,1)]
/stimulustimes = [0=Gamble; 0=Sure]
/validresponse = ("a", "l")
/ontrialend = [if(trial.choice.response == "30"&&values.win<0.8) values.earn = list.amount.nextvalue]
/ontrialend = [if(trial.choice.response == "30"&&values.win>=0.8) values.earn = 0]
/ontrialend = [if(trial.choice.response == "38") values.earn = 3]
</trial>
Another feature of the Experiment is that participants are shown the total amount they have earnt during the task. This is also fairly easy to implement. My suggestions is to create new value/variable (maybe call it bank) that records the total earning after wach trial. Then you just need to add the current amount earnt at the end of this trial, to this stored amount. Finally Create a trial that displays this amount to the participant at the end of the Experiment.
<text total>
/ items = ("You won <%values.bank%> c in this experiment")
/ position = (50%, 50%)
</text>
<trial choice>
/ontrialbegin = [values.win = rand(0,1)]
/pretrialpause=500
/stimulustimes = [0=Gamble; 0=Sure]
/validresponse = ("a", "l")
/ontrialend = [if(trial.choice.response == "30"&&0.8<values.win) values.earn = list.amount.nextvalue]
/ontrialend = [if(trial.choice.response == "30"&&0.8>=values.win) values.earn = 0]
/ontrialend = [if(trial.choice.response == "38") values.earn = 3]
</trial>
<trial feedback>
/ontrialbegin = [values.bank = values.bank + values.earn]
/pretrialpause=500
/stimulustimes = [0=money]
/timeout=2000
</trial>
<trial total>
/pretrialpause=500
/stimulustimes = [0=total]
/timeout=2000
</trial>
<block>
/trials = [1-10=sequence(choice, feedback); 11=total]
</block>
Finally they also had a condition with no feedback. You should know lots of ways to implement this now. There is a way to do this usingthe groupid variable and skip attribute that we introduced in WPA 8, that will not require any new elements to be created.
<trial feedback>
/pretrialpause=500
/stimulustimes = [0=money]
/timeout=2000
/skip = [script.groupid==2]
</trial>
<trial choice>
/ontrialbegin = [values.bank = values.bank + values.earn]
/ontrialbegin = [values.win = rand(0,1)]
/pretrialpause=500
/stimulustimes = [0=Gamble; 0=Sure]
/validresponse = ("a", "l")
/ontrialend = [if(trial.choice.response == "30"&&0.8<values.win) values.earn = list.amount.nextvalue]
/ontrialend = [if(trial.choice.response == "30"&&0.8>=values.win) values.earn = 0]
/ontrialend = [if(trial.choice.response == "38") values.earn = 3]
</trial>
<trial total>
/ontrialbegin = [values.bank = values.bank + values.earn]
/pretrialpause=500
/stimulustimes = [0=total]
/timeout=2000
</trial>
<block>
/trials = [1-10=sequence(choice, feedback); 11=total]
</block>
script.groupid stores the groupid of the participant. This code skips the feedback trial whenever groupid is 2 (so people in gorup 2 get no feedback, people in group 1 do). The only other changes to this code (in the choice and total trials) are to make sure that the bank value is calculated correctly for both conditions as the previous implementation calculates it on the feedback trial, which is no longer run for half of participants. You can see that the block element is unchanged and their is still no need for an expt element.