-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCalcFAmiss.m
executable file
·69 lines (66 loc) · 2.35 KB
/
CalcFAmiss.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
function [famiss, details] = CalcFAmiss(Expt)
exa = Expt.Stimvals.et;
exb = Expt.Stimvals.e2;
id = find(abs([Expt.Trials.RespDir]) ==1);
Trials = Expt.Trials(id);
avals = [Trials.(exa)];
bvals = [Trials.(exb)];
choices = [Trials.RespDir];
if isfield(Trials,'count')
counts = [Trials.count];
elseif isfield(Trials,'Count')
counts = [Trials.Count];
end
av = unique(avals);
bv = unique(bvals);
nmin = 4;
nx = 0;
for j = 1:length(av)
for k = 1:length(bv)
if abs(av(j)) > 0.0001
if k == 1
id = find(avals ==av(j));
rates(j) = mean(counts(id));
choicerate(j) = mean(choices(id));
else
id = [];
end
else
id = find(avals ==av(j) & bvals == bv(k));
id = []; %only use signal trials for now
end
if sum(choices(id) == -1) > nmin && sum(choices(id) == 1) > nmin;
nx = nx+1;
idxs{nx} = id;
zscores{nx} = (counts(id)-mean(counts(id)))./std(counts(id));
zchoices{nx} = (choices(id) ==1); %0 or 1
details.zcp(nx) = CalcCP(counts(id(choices(id) ==1)),counts(id(choices(id) ==-1)));
pp(nx) = sum(zchoices{nx})./length(zchoices{nx});
stimval(nx) = av(j);
end
ns(j,k) = length(id);
end
end
if nx < 2
famiss = NaN;
details.percentcorrect = 0;
details.famiss = 0;
return;
end
details.ti = (mean(rates(av > 0))-mean(rates(av < 0)))./(mean(rates(av < 0))+mean(rates(av > 0)));
details.pi = (mean(choicerate(av < 0))-mean(choicerate(av > 0)));
%pi > 0 means + stim values are associated with choice -1, so percentcorrect
%will be < 0.5. If ti is -v, this will be correct = p (detecting) rate
%increase is lower
for j = 2:nx
for k = 1:j-1
pc(j,k) = (sum(zchoices{k} ==0) + sum(zchoices{j} ==1))./(length(zchoices{j}) + length(zchoices{k}));
nrates = (counts(idxs{k}) - mean(counts(idxs{k})))./(mean(counts(idxs{j}))-mean(counts(idxs{k})));
prates = (counts(idxs{j}) - mean(counts(idxs{k})))./(mean(counts(idxs{j}))-mean(counts(idxs{k})));
famiss(j,k) = mean(nrates(zchoices{k} == 1))-mean(prates(zchoices{j} ==0));
end
end
id = find(pc > 0);
details.percentcorrect = pc(id);
details.famiss = famiss(id);
famiss = mean(famiss);