%% Confidence as a diagnostic tool for perceptual aftereffects
% Regan M. Gallagher, Thomas Suddendorf, & Derek H. Arnold*
%
%
% *for correspondence regarding this program email d.arnold@psy.uq.edu.au


%% Code to create Figure 1

x = -100:.1:100; % Create the x-axis array

% Now create 3 normal cumulative curves, each with a SD of 50, with mean
% values of 0 (unbiased) -25 (left shifted) and +25 (right shifted)
p = normcdf(x,0,50);
p2 = normcdf(x,-25,50);
p3 = normcdf(x,25,50);

% Now create 3 raised Gaussian functions, then invert them to describe
% certainty. Each has a SD of 30, with mean values of 0 (unbiased) -25 
% (left shifted) and +25 (right shifted)
Raised_G = normpdf(x,0,30);
Raised_G = 1 - (Raised_G/max(Raised_G));

Raised_G2 = normpdf(x,-25,30);
Raised_G2 = 1 - (Raised_G2/max(Raised_G2));

Raised_G3 = normpdf(x,25,30);
Raised_G3 = 1 - (Raised_G3/max(Raised_G3));

% Now we create 2 biased decisional functions, by taking the unbiased
% decisional function, and adding (or subtracting) a bias factor (0.25)
% multipled by uncertainty at each point of the function. Uncertainty is
% simply given as the inverse of confidence
for n = 1 : size(p,2)
    uncertainty(n) = 1-Raised_G(n);
    pPlus(n) = p(n) + 0.25*uncertainty(n);
    pMinus(n) = p(n) - 0.25*uncertainty(n);
end

% Plot the 3 cumulative 'decision' curves (unbiased & Left & Right
% shifted)
subplot(2,2,1)
plot(x,p,'k--','LineWidth',2)
hold on;
plot(x,p2,'r-','LineWidth',3)
plot(x,p3,'b-','LineWidth',3)

ylabel('Pr. Rightward') % x-axis label


% Plot the unbiased decision curve, and the 2 biased decision curves...
subplot(2,2,2)
plot(x,p,'k--','LineWidth',2)
hold on;
plot(x,pPlus,'r-','LineWidth',3)
plot(x,pMinus,'b-','LineWidth',3)

% Plot the 3 confidence functions (unbiased & Left & Right shifted)
subplot(2,2,3)
plot(x,Raised_G,'k--','LineWidth',2)
hold on;
plot(x,Raised_G2,'r-','LineWidth',3)
plot(x,Raised_G3,'b-','LineWidth',3)

xlabel('Perceptual change') % x-axis label
ylabel('Confidence') % x-axis label


% Plot a single (unbiased) confidence function...
subplot(2,2,4)
plot(x,Raised_G,'k--','LineWidth',2)

xlabel('Biased Decisions') % x-axis label

