Given the new version of our experiment, it is possible that people can make mistakes. For example, some people might push "a" for a right square or "a" for a central square. Indeed, in a lot of experimental paradigms determining right or wrong is of equal if not more interest than reaction time or another variable.
The logic we will use here is simple. Let's think it through. We know what the stimulus location is. Indeed, in our previous code we have the variable stimulus_side which is assigned to be 1 for a left stimulus, 2 for a right stimulus, and 0 for a central stimulus. And, we also know what the block_type is - 1 for simple reaction time (i.e., a central stimulus) and 2 for choice reaction time (i.e., a left or right stimulus). Thus, if block_type == 1 and stimulus_type == 0 then we know that the correct response has to be the space bar. So, we can create a new variable response_type and assign it a 0 if the space bar is pressed, a 1 if the "a" key is pressed, and a 2 if the "l" key is pressed.
To implement this to evaluate what is happening we need to change two things.
First, when someone presses a response we need to not just compute reaction time, we also need to assign a response_type. This is easy, we can tweak the code to not care about block_type when someone responds and just assign a reaction time value and a value to response_type as outlined above.
Second, we need to evaluate whether someone is right or wrong using some if statements like this:
response_correct = 0;
if block_type == 1 & stimulus_side == 0 & response_type == 0
response_correct = 1;
end
You will note I made a default assumption that people were wrong. This makes life a whole lot easier as we will not need if statements for all possible combinations, just when they are correct and all three of our if criteria are met.
I have implemented this code HERE. Take a look, then move onto the Things To Do. You will note that any response key is valid in any block, not just the block where the different responses are appropriate.
Things To Do
1. Use your MATLAB skills to see if you can generate some results from this data. For example, mean response time and mean accuracy.
2. Use a strategy similar to that for the way we specified blocks here to specify trials to guarantee there is an equivalent number of left and right trials in each block. You will have to change the number_of_trials to 6 of course but you will need to specify in advance a trial type and then shuffle it each block.
3. Change the number of responses needed by adding a third block_type where the square can be in any one of three positions (left, middle, right).
The logic we will use here is simple. Let's think it through. We know what the stimulus location is. Indeed, in our previous code we have the variable stimulus_side which is assigned to be 1 for a left stimulus, 2 for a right stimulus, and 0 for a central stimulus. And, we also know what the block_type is - 1 for simple reaction time (i.e., a central stimulus) and 2 for choice reaction time (i.e., a left or right stimulus). Thus, if block_type == 1 and stimulus_type == 0 then we know that the correct response has to be the space bar. So, we can create a new variable response_type and assign it a 0 if the space bar is pressed, a 1 if the "a" key is pressed, and a 2 if the "l" key is pressed.
To implement this to evaluate what is happening we need to change two things.
First, when someone presses a response we need to not just compute reaction time, we also need to assign a response_type. This is easy, we can tweak the code to not care about block_type when someone responds and just assign a reaction time value and a value to response_type as outlined above.
Second, we need to evaluate whether someone is right or wrong using some if statements like this:
response_correct = 0;
if block_type == 1 & stimulus_side == 0 & response_type == 0
response_correct = 1;
end
You will note I made a default assumption that people were wrong. This makes life a whole lot easier as we will not need if statements for all possible combinations, just when they are correct and all three of our if criteria are met.
I have implemented this code HERE. Take a look, then move onto the Things To Do. You will note that any response key is valid in any block, not just the block where the different responses are appropriate.
Things To Do
1. Use your MATLAB skills to see if you can generate some results from this data. For example, mean response time and mean accuracy.
2. Use a strategy similar to that for the way we specified blocks here to specify trials to guarantee there is an equivalent number of left and right trials in each block. You will have to change the number_of_trials to 6 of course but you will need to specify in advance a trial type and then shuffle it each block.
3. Change the number of responses needed by adding a third block_type where the square can be in any one of three positions (left, middle, right).