Commit 46f4451e authored by Jesse Heckman's avatar Jesse Heckman

major update PB_DRAFT, also: moving sound vPrime

parent f5911223
......@@ -7,7 +7,8 @@ function draft(obj)
% PBToolbox (2018): JJH: j.heckman@donders.ru.nl
%% Create figure
%% Initialize Draft
% Make figure, select parents, and set layouts
% Select parent/make figure
if isempty(obj(1).parent)
......@@ -19,47 +20,47 @@ function draft(obj)
% Set figure settings
set(obj(1).parent,'color','w');
t = sgtitle(obj(1).parent,obj(1).title);
set(t,'FontSize',20);
set(t,'FontSize',18);
ax = gobjects(0);
objsz = size(obj);
%% Super labels
% Check if labels are the same, and prep super labels
% Check and prepare superlabels
lab_x = true; lab_y = true;
% Check labels
bool = true; if numel(obj) == 1; bool = false; end
lab_x = bool; lab_y = bool;
for iObj = 1:numel(obj)
if ~strcmp(obj(1).labels.xlab, obj(iObj).labels.xlab); lab_x = false; end
if ~strcmp(obj(1).labels.ylab, obj(iObj).labels.ylab); lab_y = false; end
end
% Set superlabels
obj(1).labels.supx = lab_x;
obj(1).labels.supy = lab_y;
%% Set Compare axis
cmp = length(unique(obj(1).pva.axcomp.feature));
cmpsz = [1 1];
nObj = numel(obj)*cmp;
%% Set Compare Axis
% Check and set comparing axis
if min(objsz)>1
cmp = 1;
else
if objsz(1)<objsz(2)
% horizontal direction
cmpsz(1) = cmp;
else
% vertical direction
cmpsz(2) = cmp;
end
end
nCmp = length(unique(obj(1).pva.axcomp.feature));
if min(objsz) > 1; nCmp = 1; end
%% Create (sub)plots
cmpsz = [1 1];
nObj = numel(obj) * nCmp;
[~,cmpInd] = max(cmpsz);
cmpsz(cmpInd) = nCmp;
cmpsz = fliplr(cmpsz);
%% Create Plots
% Draft each subplot
for iObj = 1:numel(obj)
% Repeat for comparing axis
for iCmp = 1:cmp
cObj = (iObj-1)*cmp + iCmp;
for iCmp = 1:nCmp
cObj = (iObj-1)*nCmp + iCmp;
% Make Axes
Ax = pb_invidx([objsz(1)*cmpsz(1), objsz(2)*cmpsz(2)],cObj); % reverse get axes index
......@@ -70,19 +71,15 @@ function draft(obj)
axis(obj(Ax2Obj).pva.axis);
hold on;
% Select data
uFeat = unique(obj(1).pva.axcomp.feature);
sel = obj(1).pva.axcomp.feature == uFeat(iCmp);
% Select data
features = unique(obj(1).pva.axcomp.feature);
sel = obj(1).pva.axcomp.feature == features(iCmp);
D = obj(Ax2Obj).pva;
D.x = D.x(sel);
D.y = D.y(sel);
D.color = D.color(sel);
% Set colors
nCol = 1;
if ~obj(iObj).pva.continious
nCol = length(unique(obj(iObj).pva.color));
end
% Plot all graphs
for iDP = 1:length(obj(iObj).dplot)
......@@ -99,12 +96,11 @@ function draft(obj)
end
end
%% Adjust axis handles
%% Adjust Axis Handles
% Set super labels
% TO DO:
% 1. Optionalize subplots to have squared/linked/fixed axis
% 2. Scale and move axis to make graph nice, pleasing and non-overlapping
% 1. Scale and move axis to make graph nice, pleasing and non-overlapping
obj.make_axes(ax);
obj.make_suplabel;
end
......
function draft(obj)
% PB_DRAFT>DRAFT
%
% OBJ.DRAFT will draw a figure from a pb_draft-object.
%
% See also PB_DRAFT, SET_LABELS, SET_TITLE, SET_GRID, PRINT
% PBToolbox (2018): JJH: j.heckman@donders.ru.nl
%% Create figure
% Select parent/make figure
if isempty(obj(1).parent)
for iObj = 1:numel(obj)
obj(iObj).parent = gcf;
end
end
% Set figure settings
set(obj(1).parent,'color','w');
t = sgtitle(obj(1).parent,obj(1).title);
set(t,'FontSize',20);
ax = gobjects(0);
dsz = size(obj);
%% Super labels
% Check if labels are the same, and prep super labels
lab_x = true; lab_y = true;
for iObj = 1:numel(obj)
if ~strcmp(obj(1).labels.xlab, obj(iObj).labels.xlab); lab_x = false; end
if ~strcmp(obj(1).labels.ylab, obj(iObj).labels.ylab); lab_y = false; end
end
obj(1).labels.supx = lab_x;
obj(1).labels.supy = lab_y;
%% Create (sub)plots
% Draft each subplot
% Create comparing axis
cmp = length(unique(obj(1).pva.axcomp.feature));
if min(dsz)>1
cmp = 1;
if dsz(1)>dsz(2)
obj(1).pva.axcomp.orientation = 'vertical';
else
obj(1).pva.axcomp.orientation = 'horizontal';
end
end
nObj = numel(obj)*cmp;
for iObj = 1:numel(obj)
% Repeat for comparing axis
for iCmp = 1:cmp
% Make Axes
iAx = pb_invidx([dsz(1), dsz(2)],iObj);
ax(iAx) = subplot(dsz(1),dsz(2),iObj);
if obj(iAx).pva.subtitle; title(obj(iAx).pva.subtitle); end
axis(obj(iAx).pva.axis);
hold on;
% Set colors
nCol = 1;
if ~obj(iObj).pva.continious
nCol = length(unique(obj(iObj).pva.color));
end
% Plot all graphs
for iDP = 1:length(obj(iObj).dplot)
d = obj(iAx).pva;
obj(iObj).dplot{iDP}(obj,d);
end
% Set labels
if ~obj(1).labels.supx; xlabel(obj(iAx).labels.xlab); end
if ~obj(1).labels.supy; ylabel(obj(iAx).labels.ylab); end
% Make scientific notations on the axes.
ax(iAx).YAxis.Exponent = length(num2str(max(abs(round(ax(iAx).YLim)))))-1;
ax(iAx).XAxis.Exponent = length(num2str(max(abs(round(ax(iAx).XLim)))))-1;
end
end
%% Adjust axis handles
% Set super labels
% TO DO:
% 1. Optionalize subplots to have squared/linked/fixed axis
% 2. Scale and move axis to make graph nice, pleasing and non-overlapping
make_axes(obj,ax);
make_suplabel(obj);
end
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
% %
% Part of Programmeer Beer Toolbox (PBToolbox) %
% Written by: Jesse J. Heckman (2019) %
% %
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
\ No newline at end of file
......@@ -50,21 +50,21 @@ classdef pb_draft < matlab.mixin.Copyable
% Set functions
set_title(obj,title,varargin); % set title
set_legend(obj,varargin); % set legend /// NOT YET DONE
set_legend(obj,varargin); % set legend
set_labels(obj,varargin); % set labels
set_grid(obj,varargin); % set grid
set_axcomp(obj,feature,varargin); % set comparision axe /// WORKING ON IT
set_axcomp(obj,feature,varargin); % set comparision axe
% Plot functions
plot_rawdata(obj,varargin); % plot the rawdata
plot_bubble(obj,varargin); % plot bubble histoplot
plot_hline(obj,varargin); % plot horizontal lines
plot_vline(obj,varargin); % plot vertical lines
plot_dline(obj,varargin); % plot diagonal lines
plot_bubble(obj,varargin); % plot bubble histoplot
plot_dline(obj,varargin); % plot diagonal lines
% Statistical functions
stat_regres(obj,varargin); % transform regression // NOT YET DONE
stat_probit(obj,varargin); % transform probit
stat_probit(obj,varargin); % transform probit // MADE NOT FINISHED
% Fitting functions
fit_ellipse(obj,varargin); % make ellipse fit
......
......@@ -27,8 +27,6 @@ end
function h = rawdata(~,data,p,colorindex)
% Plots rawdata
%% MAKE SELECTION FOR COLOR!
sel = data.color == colorindex;
x = data.x(sel);
y = data.y(sel);
......
......@@ -8,19 +8,20 @@ function make_axes(obj,ax,varargin)
% PBToolbox (2019): JJH: j.heckman@donders.ru.nl
linkaxes(ax,'xy');
positions = zeros(length(ax),4);
for iAx = 1:length(ax)
axis(ax(iAx));
xt = xticks;
yt = yticks;
% Set Limits
if obj(1).pva.setAxes
xlim(obj(1).pva.limits.x);
ylim(obj(1).pva.limits.y);
end
% Set Grids
setAx = ax(iAx);
xlim(ax(iAx),[xt(1) xt(end)]);
ylim(ax(iAx),[yt(1) yt(end)]);
positions(iAx,:) = ax(iAx).Position(:);
if obj(1).grid.bool
f = obj(1).grid.features;
setAx.Box = f.Box;
......@@ -36,12 +37,15 @@ function make_axes(obj,ax,varargin)
setAx.YDir = f.YDir;
setAx.LineWidth = f.LineWidth;
end
positions(iAx,:) = ax(iAx).Position(:);
end
% Set Label Positions
% TODO: THIS MUST BE DONE WAY BETTER!!
obj(1).labels.ypos = min(positions(:,2));
obj(1).labels.xpos = min(positions(:,1));
obj(1).labels.pos = [min(positions(:,1))/1.33 min(positions(:,2))/1.33 max(positions(:,1)+positions(:,3)) max(positions(:,2)+positions(:,4))];
obj(1).h_ax_plot = ax;
obj(1).h_ax_plot = ax;
end
......
......@@ -7,29 +7,38 @@ function parse_va(obj,varargin)
% See also PB_DRAFT
% PBToolbox (2018): JJH: j.heckman@donders.ru.nl
%% READ DATA
% Read Data, and set keyvals
%% Initialize
% Read keyvals
v = varargin;
pva.x = pb_keyval('x',v,[]);
pva.y = pb_keyval('y',v,[]);
pva.z = pb_keyval('z',v,[]);
pva.def = pb_keyval('def',v,1);
pva.color = pb_keyval('color',v,ones(length(pva.x),1));
pva.color = pb_keyval('color',v,ones(length(pva.y),1));
pva.axis = pb_keyval('axis',v);
pva.subtitle = pb_keyval('subtitle',v);
pva.linkax = pb_keyval('link',v,true);
pva.setAxes = pb_keyval('setaxes',v,true);
%% Set Core
% Read, check and set data.
% Check data limits
[x,y] = setlim(pva);
if isempty(pva.x); s = size(pva.y); pva.x = zeros(s(1),s(2)); end
[x,y] = setlim(pva);
if strcmp(pva.axis,'square') && x ~= y
x = [min([x y]) max([x y])];
y = x;
end
pva.limits.x = x;
pva.limits.y = y;
% Check square axis
if isempty(pva.axis)
if abs(max(x)-max(y)) / max([x,y])<.5
if abs(max(x)-max(y)) / max([x,y]) < 0.5
pva.axis = 'square';
end
end
......@@ -38,28 +47,33 @@ function parse_va(obj,varargin)
pva.colscheme = pb_selectcolor(length(unique(pva.color)),pva.def);
pva.axcomp = axcmp(pva.x);
% Set Labels
obj.labels.xlab = pb_keyval('xlab',v,'');
obj.labels.ylab = pb_keyval('ylab',v,'');
obj.grid.bool = false;
% Check data continuity for colouring
pva.continious = false;
if length(unique(pva.color))>5 && ~prod(floor(pva.color) == pva.color)
if length(unique(pva.color)) > 5 && ~prod(floor(pva.color) == pva.color)
pva.continious = true;
end
obj.pva = pva;
end
function ac = axcmp(data)
function axc = axcmp(data)
% Writes empty axcomp data struct
ac.prefix = '';
ac.feature = ones(1,length(data));
ac.n = length(unique(ac.feature));
axc.prefix = '';
axc.feature = ones(1,length(data));
axc.n = length(unique(axc.feature));
end
function [x,y] = setlim(data)
% Sets the limits for axes
x = []; y = [];
x = [min(data.x) max(data.x)];
y = [min(data.y) max(data.y)];
......@@ -71,19 +85,19 @@ function [x,y] = setlim(data)
if abs(min(y))/yr < .1; y(1) = 0; end
% maximum
tmp = max([x,y]);
maxD = max([x,y]);
order = 0;
scale = .1;
if tmp<1; scale = 10; end
if maxD < 1; scale = 10; end
while tmp < .1 || tmp > 1
tmp = tmp*scale;
while maxD < .1 || maxD > 1
maxD = maxD*scale;
order = order+1;
end
tmp = round(tmp*100)/100;
x(2) = tmp * inv(scale)^order;
y(2) = tmp * inv(scale)^order;
maxD = round(maxD*100)/100;
x(2) = maxD * inv(scale)^order;
y(2) = maxD * inv(scale)^order;
end
......
function stat_probit(obj,varargin)
% PB_DRAFT>PB_PROBIT
%
% Creates a probit plot.
%
% OBJ.STAT_PROBIT(varargin) plots RT data and transforms axes to the classic
% probit display, i.e. cum. prob. vs promptness.
%
% See also PB_DRAFT, DRAFT, PB_PROBIT
% PBToolbox (2019): JJH: j.heckman@donders.ru.nl
v = varargin;
p.ncol = pb_keyval('ncol',v,unique(obj.pva.color));
p.visibility = pb_keyval('visibility',v,'off');
obj.plot_hline;
for iCol = 1:length(p.ncol)
obj.dplot = vertcat(obj.dplot,{@(dobj,data)probit_stat(dobj,data,p,p.ncol(iCol))});
end
obj.results.rawdata_handle = {};
obj.pva.setAxes = false;
end
function h = probit_stat(~,data,p,colorindex)
%% Initialize
% Read and select data.
sel = data.color == colorindex;
y = data.y(sel);
if isempty(y); disp('No entry for y-data found!'); return; end
gcol = pb_selectcolor(length(p.ncol),5);
color = pb_selectcolor(length(p.ncol),data.def);
color = color(colorindex,:);
%% Rawdata
% Plot rawdata
iRT = 1/(y);
x = -1./sort(y);
n = numel(iRT);
y = probitscale((1:n)./n);
%h(1) = plot(x,y,'Color',gcol(colorindex,:),'Marker','o','MarkerFaceColor',gcol(colorindex,:),'LineStyle','None');
%% Quantiles & regression
p = [1,2,5,10,25,50,75,90 95 98 99]/100;
xtick = sort(-1./(150+[0 pb_oct2bw(50,-1:5)]));
prob = sqrt(2) * erfinv(2*p - 1);
q = -1./quantile(y,p);
b = regstats(prob,q);
rl = regline(b.beta,'k--');
h = plot(q,prob,'Color',color,'Marker','o','MarkerFaceColor',color,'LineStyle','None');
%set(h(1),'Tag','Rawdata');
set(h,'Tag','Probit model');
set(rl,'Tag','Graphical aid: regline');
%% Design
% Set Axis for probit
% TODO: --> FIGURE OUT WHY THE FUCK THERE IS NO VISUAL PROBIT MODEL?
%
% set(gca,'XTick',xtick,'XTickLabel',-1./xtick);
% set(gca,'YTick',prob,'YTickLabel',p*100);
% xlim([min(xtick) max(xtick)]);
% ylim([probit(0.1/100) probit(99.9/100)]);
% xlabel('Reaction time (ms)');
% ylabel('Cumulative probability');
% axis square;
% box off
end
function chi = probitscale(cdf)
% creates a probitscale
chi = sqrt(2) * erfinv(2*cdf - 1);
end
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
% %
% Part of Programmeer Beer Toolbox (PBToolbox) %
% Written by: Jesse J. Heckman (2019) %
% %
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
......@@ -4,48 +4,79 @@
pb_clean; % Empty
load('exD_saccade'); % load example data
cfn = 0; % Initialize current figure number
run = 2; % Set # of blocks to run
run = 3; % Set # of blocks to run
%% Block1:
% Make figure 1: Plot rawdata + bubbleplot
%% Block 1:
% Make figure 1: Plot data
if run>cfn
cfn = pb_newfig(cfn,'size',[0 0 17 12],'resize','off');
for i = 1:1
for j = 1:2
d(j,i) = pb_draft('x',Saccades.GazeLatency,'y',Saccades.HeadLatency,'color',Saccades.Modality);
d(j,i).set_labels('x','Gaze Latency (ms)','y','Head Latency (ms)');
if ~iseven(i*j)
d(j,i).plot_rawdata;
else
d(j,i).plot_bubble;
d(j,i).fit_ellipse;
end
d(j,i).plot_dline;
d(j,i).plot_vline('type','mode');
d(j,i).plot_hline('type','mode');
% Make figure & draft-obj
cfn = pb_newfig(cfn,'size',[0 0 17 17],'ws','Docked');
d = pb_draft('x',Saccades.GazeLatency,'y',Saccades.HeadLatency,'color',Saccades.Modality);
% Plots
d.plot_rawdata
d.plot_vline('type','mode');
d.plot_hline('type','mode');
% Layout
d.set_title('Saccade Latencies');
d.set_labels('x','Gaze Latency (ms)','y','Head Latency (ms)');
d.set_grid;
% Build
d.draft
%d.print
end
%% Block 2:
% Make figure 2: Plot rawdata + bubbleplot
if run>cfn
% Make figure
cfn = pb_newfig(cfn,'size',[0 0 17 12],'ws','Docked');
for iR = 1:2
% Build draft-objs
d(iR,1) = pb_draft('x',Saccades.GazeLatency,'y',Saccades.HeadLatency,'color',Saccades.Modality);
% Plots
if ~iseven(iR)
d(iR,1).plot_rawdata;
else
d(iR,1).plot_bubble;
d(iR,1).fit_ellipse;
end
d(iR,1).plot_dline;
% Axis Layout
d(iR,1).set_labels('x','Gaze Latency (ms)','y','Head Latency (ms)');
end
% Figure Layout
d.set_title('Saccade Latencies');
d.set_axcomp(Saccades.Subject);
d.set_grid;
% Build
d.draft;
d.print('disp',true);
%d.print
end
%% Block2:
% Make figure 2: Plot rawdata + bubbleplot
%% Block 3:
if run>cfn
cfn = pb_newfig(cfn,'size',[0 0 17 17],'resize','off');
d = pb_draft('x',Saccades.GazeLatency,'y',Saccades.HeadLatency,'color',Saccades.Modality);
% Make figure & draft-obj
cfn = pb_newfig(cfn,'size',[0 0 17 17],'ws','Docked');
d = pb_draft('y',Saccades.HeadLatency); %,'color',Saccades.Modality);
d.stat_probit;
d.set_title('Probit plot');
d.set_labels('x','Reaction Times (ms)','y','Cumulative Probability');
d.set_grid;
% Build
d.draft;
%d.print
end
%% Block3:
if run>cfn
cfn = pb_newfig(cfn,'size',[0 0 17 17],'resize','off');
d = pb_draft('x',Saccades.GazeLatency,'y',Saccades.HeadLatency,'color',Saccades.Modality);
end
\ No newline at end of file
......@@ -22,7 +22,7 @@ function [h,D] = pb_probit(D, varargin)
pb_selectaxis(ax);
hold on;
D = fixArgIn(D); len = length(D);
len = length(D);
rd = gobjects(len); rl = gobjects(len); h = gobjects(len);
%% Rawdata
......@@ -32,10 +32,10 @@ function [h,D] = pb_probit(D, varargin)
x = -1./sort(D(i).rt);
n = numel(iRT);
y = probitscale((1:n)./n);
rd(i) = scatter(x,y);
rd(i) = plot(x,y,'Marker','o','Color',[.66 .66 .66],'MarkerFaceColor',[.66 .66 .66]);
end
set(rd,'Tag','rawdata');
%set(rd,'Tag','rawdata');
%% Quantiles & regression
......@@ -73,27 +73,13 @@ function [h,D] = pb_probit(D, varargin)
end
function chi = probitscale(cdf)
% creates a probitscale
% Creates a probitscale
myerf = 2*cdf - 1;
myerfinv = sqrt(2)*erfinv(myerf);
chi = myerfinv;
end
function D = fixArgIn(tmp)
% checks /correct datatype and orientation of input data
D = struct;
if isnumeric(tmp)
D.rt = tmp;
end
s = size(D.rt);
if s(1) < s(2)
D.rt = D.rt';
end
end
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
% %
% Part of Programmeer Beer Toolbox (PBToolbox) %
......
function [h,b,r] = pb_regplot(X,Y,varargin)
% PB_REGPLOT()
% PB_REGPLOT
%
% plots data, and linear regression.
%
% PA_REGPLOT(,Y) plots X vs Y, and performs linear regression on X and Y.
% PA_REGPLOT(X,Y,varargin) plots X vs Y, and performs linear regression on X and Y.
% PBToolbox (2018): JJH: j.heckman@donders.ru.nl
......@@ -36,6 +36,7 @@ function [h,b,r] = pb_regplot(X,Y,varargin)
if data; h(1) = plot(X, Y, ['k' marker]); end
axxes = axis;
h(end+1) = plot(axxes([1 2]),gain*axxes([1 2])+bias,'Color',color,'LineStyle',linestyle,'LineWidth',linewidth);
if ~hs; hold off; end
end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment