I have data from the behavioral component of an fMRI study in which subjects are asked to perform a 2AFC discrimination task with targets at variable contrast. That is, a target will be presented at one of several possible contrasts, and the subject must later identify which of two possible responses has the same orientation as the target stimulus.

Below is an example of data from one subject:

enter image description here

Note that I've attempted to fit a psychometric function, using the following procedure (in Python):

import numpy as np
import pylab
from scipy.optimize import curve_fit

def sigmoid(x, x0, k):
     y = 1 / (1 + np.exp(-k*(x-x0)))
     return y

xdata = np.array([0.0,   1.0,  3.0, 4.3, 7.0,   8.0,   8.5, 10.0, 12.0])
ydata = np.array([0.01, 0.02, 0.04, 0.11, 0.43,  0.7, 0.89, 0.95, 0.99])

popt, pcov = curve_fit(sigmoid, xdata, ydata)
print popt

x = np.linspace(-1, 15, 50)
y = sigmoid(x, *popt)

pylab.plot(xdata, ydata, 'o', label='data')
pylab.plot(x,y, label='fit')
pylab.ylim(0, 1.05)

Of particular note is the sigmoid formula I'm using: 1 / (1 + exp(-k * (x - x0))).

The problem with this approach is that the fit will pass through zero, wheras with 2AFC data, the minimum value is theoretically .5 -- the guessing rate.

How can I fit a sigmoid function such that the fit spans from .5 to 1.0?


1 Answer 1


Add 0.5 to the intercept and multiply the sigmoid by 0.5 since it now only spans a y-range half of before:

y = 0.5 + 0.5 / (1 + np.exp(-k*(x-x0)))

Generally, for any chance level:

chance = 0.5  # between 0 and 1
y = chance + (1-chance) / (1 + np.exp(-k*(x-x0)))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.