# Calculating d-prime

I'm currently working on a research that has to use and calculate D Prime values for a task where subjects are presented an image at different speeds and they have to report if they saw the image or not. I've read different basic articles on D Prime and it's formulas but I still don't quite get it and I'm not sure of which values use for it's formula. For example: sometimes the formula says to use the mean and I'm not sure if I should use the mean of the subject's score or the mean of the entire sample.

• Welcome to cogsci.SE! This could be an interesting question, but can you make it more specific so readers know what information you're looking for? I.e., what articles have you read, what calculations are you unsure of, etc. Feb 12, 2015 at 14:25

To calculate $d'$ you need to know two things: the hit rate and the false alarm rate. The hit rate is the proportion of trials where the stimulus was present and the subject responded that the stimulus was present. The false alarm rate is the proportion of trials where the stimulus was not present, and the subject responded that the stimulus was present. Sometimes it will be shown like this:

• Hit rate is the probability of a yes response given the target is present: $H = P( yes | present)$
• False alarm rate is the probability of a yes response given the target is absent: $FA = P( yes | absent)$

Once you have those two numbers the calculation is $d' = z(H) - z(FA)$.

The z-transform is based on the standard normal distribution, and you can look up the z-value for a given probability in a table, or use a function like NORMSINV in Excel or qnorm in R.

For most applications, you will want to calculate $d'$ for each individual subject, i.e., $H$ and $FA$ are based only on the data from a single subject. Then you can look at how experimental manipulations affect the distribution of $d'$ values.

The index of sensitivity $d'$ is typically defined in terms of two equal variance normally distributed random variables with means $\mu_s$ and $\mu_n$ and standard deviation $\sigma$:

$$d'=\frac{\mu_s-\mu_n}{\sigma}$$

In behavioural experiments, the probability that the subjects responded correctly (either saying 'yes' when the signal was present or saying 'no' when the signal was absent) is often reported. The problem is that probability of responding correctly depends on the bias of the subjects (how often they respond 'yes'). The advantage of using $d'$ is that it is a bias free measure of performance. While we cannot measure $\mu_s$, $\mu_n$, and $\sigma$ directly in typical behavioural experiments, $d'$ can be estimated from the hit rate $H$ (the probability of responding 'yes' given the signal was present) and the false alarm rate $FA$ (the probability of responding 'yes' given the signal was absent):

$$d'=z(H)-z(FA)$$

where $z(\cdot)$ is the z-transform.

Even after reading other answers here, it took me a while to figure out how, so I leave my answer here.

Calculation of d-prime is pretty straight forward:

MATLAB: norminv

d_prime = norminv(hit_rate) - norminv(falsealarm_rate)


Python: scipy.stats.norm.pdf

import scipy.stats as st
d_prime = st.norm.ppf(hit_rate) - st.norm.ppf(falsealarm_rate)


Excel: NORM.S.INV

d_prime = NORM.S.INV(hit_rate) - NORM.S.INV(falsealarm_rate)


My confusion came from the name z-transform. Here we are talking about the conversion of a probability to a z-score, i.e. expressed as a signed multiple of standard deviation (SD, sigma) from the mean value (mu), using a standard normal distribution (mu = 0, sigma = 1).

This is not to be confused with another z-transform for conversion of a discrete-time signal, which is a sequence of real or complex numbers, into a complex frequency-domain (z-domain or z-plane) representation.

## Confirmation

So the hit rate H is 20/25, or .8

the false alarm rate is 10/25, or .4

z(H) = 0.842 and z(F) = -0.253

d' = 0.824-(-0.253) = 1. 095

The MATLAB code below gave the same number.

norminv(0.8) - norminv(0.4)


ans = 1.0950

## Distribution

Using the code above, I plotted the relationshio between Hit rate and False alarm rate.

n = 100;

hit_rate = linspace(0,1,n);
falsealarm_rate = linspace(0,1,n);

d_prime = NaN(n,n);
for i = 1:n
for j = 1:n
d_prime(j,i) = norminv(hit_rate(i)) - norminv(falsealarm_rate(j));
end
end

figure

imagesc(hit_rate, falsealarm_rate, d_prime)
axis square
axis equal
axis tight

ax = gca;
ax.YDir = 'normal';
ax.YTick = 0:0.2:1;

xlabel('Hit rate')
ylabel('False alam rate')
tickdir out # custom function
box off
colormap (redblue)

cb = colorbar
ylabel(cb,'d-prime')
tickdir(cb,'out') # custom function 