-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtune_prop_test.m
118 lines (106 loc) · 4.46 KB
/
tune_prop_test.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
function validOut = tune_prop_test(spkVal)
thresholdCategory = 0.05;
angles = 45:15:135;
anovactype = 'hsd';
multimodal = 0;
unimodalSingle = 0;
unimodalBroad = 0;
categorical = 0;
leaveOneOut = 0;
spkAnovaVal = cell2mat(spkVal);
if ~isempty(find(isnan(spkAnovaVal)))
error('nan values')
end
groupAnova = zeros(size(spkAnovaVal));
angleLengths = [0;cumsum(cellfun(@length, spkVal))];
for ai = 1 : length(angles)
groupAnova(angleLengths(ai)+1:angleLengths(ai+1)) = deal(ai);
end
[spkAnovaP, ~, spkAnovaStat] = anova1(spkAnovaVal, groupAnova, 'off');
spkPairComp = multcompare(spkAnovaStat, 'Ctype', anovactype, 'Display', 'off');
spkMeans = spkAnovaStat.means;
spkStd = cellfun(@std, spkVal);
%%
[~,testInd] = min(spkAnovaStat.means)
tempH = cellfun(@(x) ttest2(x,spkVal{testInd}), spkVal);
%%
tempH = cellfun(@(x) ttest(x), spkVal);
%%
tempH(isnan(tempH)) = deal(0);
sigInd = find(tempH); % significant indices
[~, maxind] = max(abs(spkMeans(sigInd)));
tunedAngleInd = sigInd(maxind);
tunedAngle = angles(tunedAngleInd);
% Categorization
ind__1 = find(spkPairComp(:,1) == tunedAngleInd);
ind__2 = find(spkPairComp(:,2) == tunedAngleInd);
testInd = union(ind__1, ind__2);
insigDiffInd = find(spkPairComp(testInd,6) >= thresholdCategory);
sigDiffInd = find(spkPairComp(testInd,6) < thresholdCategory);
temp = spkPairComp(testInd(insigDiffInd),1:2);
insigDiffIndGroup = unique(temp(:)); % sorted. Include tunedAngleInd, except when there's nothing
if isempty(insigDiffIndGroup)
unimodalSingle = 1;
else
broadInd = intersect(sigInd,insigDiffIndGroup);
if length(broadInd) < 2
unimodalSingle = 1;
else
broadNum = 1;
for tunei = tunedAngleInd-1:-1:1
if ismember(tunei, broadInd)
broadNum = broadNum + 1;
else
break
end
end
for tunei = tunedAngleInd+1:length(angles)
if ismember(tunei, broadInd)
broadNum = broadNum + 1;
else
break
end
end
if broadNum == length(broadInd)
unimodalBroad = 1;
% if broad, then it can be a categorical
center = (length(angles)+1) / 2;
compInd = union(find(spkPairComp(:,1) == tunedAngleInd), find(spkPairComp(:,2) == tunedAngleInd));
indMat = spkPairComp(compInd,1:2);
if tunedAngleInd < center
withinInd = unique(mod( setdiff( find(indMat < center), find(indMat == tunedAngleInd) ) , size(indMat,1)));
withinInd(withinInd==0) = size(indMat,1);
betweenInd = unique(mod( find(indMat > center) , size(indMat,1) ));
betweenInd(betweenInd==0) = size(indMat,1);
else
withinInd = unique(mod( setdiff( find(indMat > center), find(indMat == tunedAngleInd) ) , size(indMat,1)));
withinInd(withinInd==0) = size(indMat,1);
betweenInd = unique(mod( find(indMat < center) , size(indMat,1) ));
betweenInd(betweenInd==0) = size(indMat,1);
end
if isempty(find(spkPairComp(compInd(withinInd),6) < thresholdCategory, 1)) && ... % nothing within the same half is different from the max ind
isempty(find(spkPairComp(compInd(betweenInd),6) >= thresholdCategory, 1)) % nothing between different half is same with the max ind
categorical = 1; % categorical (>= 90 or <= 90)
end
else
multimodal = 1;
end
end
temp = spkPairComp(testInd(sigDiffInd),1:2);
sigIndGroup = setdiff(temp(:), tunedAngleInd); % exclude tunedAngleInd. Any index that is significantly different from the tuned angle index.
if ~isempty(find(diff(insigDiffIndGroup)>1,1))
if sum(tempH(insigDiffIndGroup))>1 % to exclude tuned angle
multimodal = 1; % multimodal. Including bipolar.
end
if length(sigIndGroup) == 1 && ... % only one bin is significantly different from the tuned bin. (can't be larger in response because of the way tuned bin is defined)
all(tempH(insigDiffIndGroup)) % and all insignicant indices are different from 0
leaveOneOut = 1 ; % leave-one-out. Part of multimodal in definition.
end
end
end
validOut.multimodal = multimodal;
validOut.unimodalSingle = unimodalSingle;
validOut.unimodalBroad = unimodalBroad;
validOut.categorical = categorical;
validOut.leaveOneOut = leaveOneOut;
validOut.tunedAngle = tunedAngle;