

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

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

<p>Generally, for any chance level:</p>

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

CC BY-SA 3.0
2016-02-17T13:09:53.150Z
2016-02-17T13:09:53.150Z
Jonas Lindeløv
<p>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.</p>
<p>Below is an example of data from one subject:</p>
<p><a href="https://i.sstatic.net/G2Y7c.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/G2Y7c.png" alt="enter image description here" /></a></p>
<p>Note that I've attempted to fit a psychometric function, using the following procedure (in Python):</p>
<pre><code>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)
pylab.legend(loc='best')
pylab.show()
</code></pre>
<p>Of particular note is the sigmoid formula I'm using:  <code>1 / (1 + exp(-k * (x - x0)))</code>.</p>
<p>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.</p>
<h3>How can I fit a sigmoid function such that the fit spans from .5 to 1.0?</h3>

<psychophysics>
How can I fit a psychometric function such that the minimum is 50% (chance level)?
Louis Thibault
# How can I fit a psychometric function such that the minimum is 50% (chance level)?

(Asked by: username_0 on 2016-02-17)

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:

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)
pylab.legend(loc='best')
pylab.show()

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?

**Tags:** psychophysics


---

## 1 answers

### Answer by username_1 on 2016-02-17. Score: 5 | Accepted answer

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)))


---

