# The psychometric function

The psychometric function is used to explore the threshold region in stimulus detection where detection of a stimuli becomes probabilistic. The function needs to model the range of probabilities of detection between 0 (certainty of failure) to 1 (certainty of success) is a manner that approximates actual human detection rates. A crucial role of the psychometric function is the determination of threshold, i.e. the point (e.g. intensity) where detection of a stimuli is equally likely as failure to detect the stimuli.

## Contents

- Defining the Psychometric function
- A Plot of the Sigmoid function
- Varying alpha
- Varying beta
- Calculating the detection threshold using the Sigmoid
- Extending the sigmoid
- Method 1 – Using Matlab’s Curve Fitting Toolbox (version 3.3.1)
- Using the Curve Fitting Tool
- Example data
- Coding the fitting function
- Fit model to data.
- Plot fit with data.
- Results

## Defining the Psychometric function

The first task is to define the psychometric function. If we are using the Curve Fitting Toolbox this is performed by re-writing the psychometric function equation as a short code fragment. Unlike normal Matlab code this little fragment is stored as a string to be run later by the *fit* command.

For the psychometric function we are using the Sigmoid function (http://en.wikipedia.org/wiki/Sigmoid_function)

This function ranges from 0 to 1 and looks like this:

## A Plot of the Sigmoid function

```
x = -6:0.1:6;
alpha = 0;
beta = 1;
plot(x,1./(1+exp(-(x-alpha)./beta)), 'k-')
title('The sigmoid function');
xlabel('Stimulus value (e.g. intensity)');
ylabel('Probability of stimulus detection');
% Varying the alpha variable shifts the Sigmoid left and right. Varying the
% beta variable scales the steepness of the slope.
```

## Varying alpha

```
clf
alpha = -3:3;
for a = alpha
plot(x,1./(1+exp(-(x-a)./beta)));
hold all
end
legend(num2str(alpha'));
title('The sigmoid function with varying alpha');
xlabel('Stimulus value (e.g. intensity)');
ylabel('Propability of stimulus detection');
```

## Varying beta

```
clf
alpha = 0;
beta = exp(-2:0.5:1);
for b = beta
plot(x,1./(1+exp(-(x-alpha)./b)));
hold all
end
legend(num2str(beta'));
title('The sigmoid function with varying beta');
xlabel('Stimulus value (e.g. intensity)');
ylabel('Propability of stimulus detection');
```

## Calculating the detection threshold using the Sigmoid

A key property of the Sigmoid is that alpha is equal to the 50% detection threshold, i.e. the point at which an observer is equally likely to observe the stimuli as fail to.

- Detection threshold = alpha

## Extending the Sigmoid

The sigmoid function as defined is only applicable to a simple experiment where a single stimulus is detected (nor not) and where the participant makes no errors.

We need two new values; a ‘guessing’ value, that is the probability that the participant with get correct if they simply guess, and a ‘lapsing’ probability, that is the estimated number of trails in which the participant will make a mistake.

As an example, a 2AFC (two alternative forced choice) task forces the participant to choose between two stimuli, the probability of getting the correct stimuli by chance is 0.5 so we set the value of the guess variable to 0.5. The lapse variable can be found from the data.

These two variables need to shift and scale the Sigmoid function. Instead of having a minima at 0 we need the minima of our sigmoid to match the guessing rate (0.5) in our example so we add 0.5. We then need to scale the sigmoid to fit (adding 0.5 to 1 is 1.5 so we need to rescale back to 1), this is achieved by dividing by (1-guessing rate) that is the bit left over between 0 and 1 when the guess it taken out. Finally we can account for the lapse rate by taking a ‘bit off the top’

Here g is simply the guessing rate (between 0 and 1) and l is the lapse rate (also between 0 and 1).

## Method 1 – Using Matlab’s Curve Fitting Toolbox (version 3.3.1)

Advantages:

- One of the simplest methods.
- Comes with a convenient GUI.

Disadvantages

- Limited to least squares estimation of function fitting.

## Using the Curve Fitting Tool

The Curve Fitting Tool is an app supplied with the curve fitting toolbox Matlab extension. As such it is not automatically supplied with Matlab, however many site licences (including St Andrews) include this toolbox as an option.

If you have the curve fitting app installed you will find it on the app toolbar.

## Example data

Here we have an example using real world data. The experiment is a simple 2AFC task detecting line orientation against a noisy background (tilt forwards vs. tilt backwards). The intensity of line stimuli a varied while the noise intensity is constant.

Data for the psychometric function is gathered using the Method of Constant Stimuli http://psychology.wikia.com/wiki/Method_of_constant_stimuli. The data consists of two variables; samples, the intensity of the stimuli and responses, the actual response (1 if tilted forwards and 0 is tilted backwards). The guessing rating is 0.5, the lapse rate unknown.

clear memory and load example data

```
clear
load('psychometric.mat');
% prepares the data i.e. converts to columns removes NaN and Inf values
% (gives a warning if it does this) and checks that the columns are of
% equal lengths (throws an error if they are not).
[xData, yData] = prepareCurveData( samples, responses );
```

## Coding the fitting function

There are a number of ways of entering a fitting function in the curve fitting toolbox (including using the GUI) as this document is generated from code we are using a coding example.

A function to be fitting is defined using standard Matlab code as normal, however this code is supplied to the toolbox as a string using the *fittype* command. Using the fit command we can supply any valid Matlab expression (i.e. anything that can be validly placed on the right hand side of the assignment operator ‘=’) including function calls and variable names. The Curve Fitting Toolbox expects to see three types of varaible, one or more ‘independent’ variables, a single ‘dependent’ variable and a set of coefficients. The coefficients are ‘constants’ in the equation the value of which we seek to find.

For the Sigmoid we can write, x and y are the independent and dependent variables respectively, note that y doesn’t appear in the equation.

`ft = fittype( '0.5+(1-0.5-l)./(1+exp(-(x-alpha)/beta))', 'independent', 'x', 'dependent', 'y' );`

Next we define the fitting options including the starting point and values ranges. The number of values in the vectors must equal the number of variables in the equation you supplied to fittype (minus the x and y)

```
opts = fitoptions( ft );
opts.Display = 'Off';
opts.Lower = [-Inf 0 0];
opts.StartPoint = [0.132903481469417 0.762038603323984 0];
opts.Upper = [Inf 1 1];
```

## Fit model to data.

The fit command performs the actual fitting. It takes four values, the last two are the fitting type variable we defined above and the options we have just defined.

The first two variables are the data we need to fit. The xData variable (defined above) is the sample intensity, the yData is the participant response.

`[fitresult, gof] = fit( xData, yData, ft, opts );`

## Plot fit with data.

```
figure( 'Name', 'Example Psychophysical function fitting' );
h = plot( fitresult, xData, yData );
legend( h, 'responses vs. sample positions', 'fit', 'Location', 'NorthEast' );
% Label axes
xlabel( 'stimulus intensity' );
ylabel( 'Probability of correct response' );
grid on
```

## Results

for a threshold of the mid point of the function we only need the alpha

```
threshold = fitresult.alpha
beta = fitresult.beta
lapse = fitresult.l
```

threshold = 0.0639

beta = 0.0179

lapse = 0.1111

Published with MATLAB® R2013a