An adaptive staircase procedure for Matlab
A frequently used method in psychophysics is to measure threshold. Threshold is usually defined as the stimulus intensity that produces a probability of 50% (for yes-no paradigms) or 75% (for 2AFC paradigms) correct answers on the psychometric function. One much used method to determine threshold is the method of constant stimuli, but if performance is highly variable across observers, it is useful to determine a rough estimate of threshold using a staircase procedure.
With toolboxes like the PsychToolBox (for stimulus presentation) and the psignifit toolbox (to fit the psychometric function), Matlab is an excellent software package to measure threshold and is hence used in many psychophysics labs. There are several adaptive staircase implementations for Matlab, including the well-known QUEST algorithm by Watson and Pelli (which is included with the Psychophysics Toolbox) and Dirk Beer's simple and more complex adaptive procedures.
This article presents a staircase method based on Levitt's original Transformed Up-Down method, in which stimulus intensity decreases after a number of correct answers - depending on the target threshold; see Levitt (1971) for more information - and increases after each incorrect answer. Much of the ideas on how to program the toolbox came from Dirk Beer's simple staircase toolbox and I'd like to credit him for the work he's done.
The toolbox
News
- August 17, 2008: A new version is in the making, which will allow you (1) to run multiple randomly interleave staircases and (2) adjust the stepsizes. Expected late September 2008.
Contents of the toolbox
- do_stair.m - this is the main file in which all the magic takes place.
- init_stair.m - this initializes the staircase for use. You will need to edit variables in this file to make it work.
- get_stair.m - this will get the current stimulus intensity.
- update_stair.m - this will update the staircase variables after each run.
- do_plot.m - this function will plot the results in little plot (always nice to have a visual representation).
- gridxy.m - a very nice little tool to plot reflines in your plot (used in do_plot.m) written by Jos van der Geest.
- nearest.m - calculates error to determine the location of the threshold in your stimulus vector.
Download
Automatic downloads are now disabled. Just drop me a line on lugtigheid@gmail.com if you'd like to use the staircase code and I will e-mail it to you. Thanks in advance!
License
The toolbox is licensed under a MIT license.
Changelog
- May 31st, 2008 - Added a missing function to the toolbox (oops).
- July 23rd, 2007 - Fixed a little bug causing the starting value of the staircase to be equal to the index of that value.
- July 22nd, 2007 - First version online
Frequently Asked Questions
How does your toolbox determine threshold?
For specific questions on how the staircase procedure works, I'd like to refer to the original article written by Levitt in 1971; see reference at the bottom of this page.
The actual threshold in the staircase procedure presented on this page is calculated by first calculating the mean of the stimulus values at the reversal points, discarding a number of the first reversal points (you will see that if you start with a high starting value, the stimulus intensity will first decrease in a steady pace to a value that lies underneath the eventual threshold - incorrect answers in this steady decrease are likely to represent accidental errors). It then calculates the value in your stimulus vector that is nearest to this mean (using the error) and returns that.
So what's a reversal?
The stimulus intensity will increase and decrease constantly during the course of your staircase procedure. A reversal is a point in your staircase where the staircase changes direction. In other words, if your stimulus intensity first decreased because of correct answers but at some point the observer responds incorrectly and stimulus intensity increases, a reversal has occurred.
Is there a picture somewhere, so I can see what it does?
Yep (output from do_plot.m).
How do I use the toolbox?
The staircase procedure will not work out of the box and will require some editing before it will work in your experiment. Please read the information on this page carefully to determine what you will need to edit.
First, unpack the toolbox to the folder you want to run it from (or add it to your path in Matlab, but please note that you'll still need to initialize the staircase from init_stair.m). There are several variables to edit before you start, all of which nested in a struct called 'sc':
- sc.reversals: after how many reversals do you want the staircase to end?
- sc.discard: how many reversals do you want to discard in the calculation of the actual threshold? Please not that the actual number of reversals will be the sum of sc.reversals and sc.discard.
- sc.stimvals: what is the stimulus vector you want to apply the staircase on? In other words - what is your binsize and what are minimum and maximum values for your staircase? Example:
sc.stimvals = 1:0.1:100;for a minimum of 1 and a maximum of 100 with 1000 steps between them (i.e. bin size 0.1).- sc.max.trials: after how many trials do you want to trigger the termination rule?
- sc.startingval: at which value do you want the staircase to start?
- sc.up: after how many incorrect answers do you want to increase stimulus intensity?
- sc.down: after how many correct answers do you want to decrease stimulus value?
Then you will need to edit do_stair.m to include your trial-function. In the current files, there's a procedure called do_trial which outputs two variables: the response (correct or incorrect in a binary response: it can be either 0 or 1) and the key that was pressed by the observer to respond (optional). The response is important because it is needed for the update function - make sure this is all correctly implemented before starting your experiment.
And that's it, really. You're set to go (I hope).
How many trials do you need to get a good estimate of threshold?
"Good" is of course subjective, but in my own experiments, I usually have a max of 24 reversals and discard the first 6. In this case it usually takes about anywhere between 110-150 trials to get a reliable estimate of threshold, depending on the starting value. If you look at the image, you will see that you can make a reasonable estimate based on about 60 trials. Of course, this will also depend on the type of experiment. It can (and will, doh) occur that subjects will not reach a threshold at all.
Alternatively, you can interleave multiple staircases, which is especially useful if you want to prevent your subjects from being able to 'predict' the next stimulus level. A common practice would be to start one at the top and one at the bottom. Integration of this functionality is planned for a next version.
Why would I use your staircase over others?
Well.. it's clean, simple and opposed to the more complex staircase procedures, it doesn't assume a certain statistical distribution (and hence doesn't require you to wrestle through all the technical and mathematical jabber). And it's fully commented..
Anything else I need to know (in other words: the fine print)?
As every method, this is not a fool-proof method. In my experience, when subjects have a lot of "false alarms" in their answers, the threshold is kept artificially high. Also, I tend to visually inspect the staircase "path" (using the provided plot function) to check for irregularities. This is always a wise thing to do. Although you would expect a subject to traverse down the staircase until the threshold value is reached and will then maintain to score so that subsequent reversals are clustered around this threshold values, it also occurs that subjects have a much more variable pattern of scoring (especially with difficult tasks) resulting in an unreliable estimation of threshold.
Not what you are looking for?
If this is not what you are looking for, please see the "further reading" section below, or have a look at the QUEST algorithm included in the psychophysics toolbox. There is also a C++ class to run a staircase procedure.
Contact and questions
Any comments, words of advice or questions are most welcome - just drop me a line on lugtigheid@gmail.com and I'll get back to you asap. I'm not exactly a Matlab expert and all comments on how to improve the code (or the accompanying text) is very much welcome!
Also, please drop me a line if you have successfully used the toolbox in your experiments or if you have any additional comments on its uses.
Further reading
- Stanley Klein - Measuring, estimating, and understanding he psychometric function: A commentary (an excellent review article, published in a special edition of "Perception and Psychophysics").
- Wichmann and Hill: The psychometric function: I. Fitting, sampling and goodness-of-fit. Perception and Psychophysics 63 (8) 1293-1313 (2001)
- Wichmann and Hill: The psychometric function: II. Bootstrap-based confidence intervals and sampling. Perception and Psychophysics 63 (8), 1314-1329 (2001)
- Levitt - Transformed up-down methods in psychoacoustics