fixed FBS basedir fixed confidece interval plot
Christoph Budziszewski

Christoph Budziszewski commited on 2009-08-06 18:02:56
Zeige 5 geänderte Dateien mit 67 Einfügungen und 15 Löschungen.


git-svn-id: https://svn.discofish.de/MATLAB/spmtoolbox/SVMCrossVal@205 83ab2cfd-5345-466c-8aeb-2b2739fb922d
... ...
@@ -0,0 +1,18 @@
1
+function [KI_u,KI_o,PROZ]=ki_bin(Z,N,alpha)
2
+% Berechnet Konfidenzintervall f�r Binomialverteilte Zufallsvariable
3
+% Aufruf: [KI_u,KI_o,PROZ]=ki_bin(Z,N,alpha);
4
+% Z (zB 5) von insgesamt N (zB 20) Beobachtungen mit Merkmalsauspr�gung x,
5
+% und damit N-Z Beobachtungen des Alternativmerkmals y.
6
+% alpha: Schranken des Konfidenzintervalls (z.B. 0.05 entspricht 95% Vertrauensbereich).
7
+% �bergibt in KI_u die untere in KI_o die obere Vertrauensgrenze,
8
+% PROZ ist der Anteil des Merkmals x bezogen auf alle Beobachtungen in Prozent.
9
+
10
+
11
+PROZ=Z/N;
12
+alpha=alpha/2;
13
+KI_u=(Z+1)*finv(alpha,2*(Z+1),2*(N-Z))/(N-Z+(Z+1)*finv(alpha,2*(Z+1),2*(N-Z)));
14
+KI_o=Z/(Z+(N-Z+1)*finv(alpha,2*(N-Z+1),2*Z));
15
+
16
+end
17
+
18
+
... ...
@@ -81,7 +81,7 @@ switch task
81 81
         out.header.classDef = classDef;
82 82
         
83 83
 
84
-        out.subjectdata  = fbs_load_mask(model.baseDir,subjects);
84
+        out.subjectdata  = fbs_load_mask(getBaseDir(model),subjects);
85 85
         
86 86
 %         if(size(subjects,2)>1)
87 87
 %             display(sprintf('No BATCH Support for Searchlight!'));
... ...
@@ -92,7 +92,7 @@ switch task
92 92
         fbsargs.timeline        = timeLine;
93 93
         fbsargs.classes         = classDef;
94 94
         fbsargs.mask            = mask;
95
-        fbsargs.basedir         = model.baseDir;
95
+        fbsargs.basedir         = getBaseDir(model);
96 96
         fbsargs.sessionList     = 1:3;
97 97
         fbsargs.eventList       = classDef.eventMatrix;
98 98
         fbsargs.psthOpts        = psthOpts;
... ...
@@ -26,52 +26,64 @@ nTrials           = getNTrials(psth);
26 26
     axis([psthStart psthEnd 0 100])
27 27
     xlabel('time [sec]');
28 28
     ylabel('decode performance [%]');
29
-
29
+plottime= tic;
30 30
     switch type
31 31
         case 'psth'
32 32
             plotPSTH(psth,psthStart,psthEnd);  
33
+
33 34
         case 'simple'
34 35
             plotDecodePerformanceWithSE(frameStart,frameEnd,decodePerformance)
36
+
37
+            plot([psthStart psthEnd],[chanceLevel chanceLevel],'k:');
38
+            plotBinConfidenceIntervall(psthStart,psthEnd,nTrials,0.05,chanceLevel/100,'--');
39
+            plotBinConfidenceIntervall(psthStart,psthEnd,nTrials,0.01,chanceLevel/100,'-.');
40
+            plotBinConfidenceIntervall(psthStart,psthEnd,nTrials,0.001,chanceLevel/100,':');
41
+
35 42
         case 'class performance'
36 43
             plotClassPerformance(frameStart,frameEnd,decodePerformance,nClasses)
44
+
45
+            plot([psthStart psthEnd],[chanceLevel chanceLevel],'k:');
46
+            plotBinConfidenceIntervall(psthStart,psthEnd,nTrials,0.05,chanceLevel/100,'--');
47
+            plotBinConfidenceIntervall(psthStart,psthEnd,nTrials,0.01,chanceLevel/100,'-.');
48
+            plotBinConfidenceIntervall(psthStart,psthEnd,nTrials,0.001,chanceLevel/100,':');
37 49
         case 'x-subject-val'
38 50
             for c = 1:nSubjects
39 51
                 plot(frameStart:frameEnd, decodePerformance(:,c) ,[colorChooser(mod(c,nSubjects)+3) '-']);
40 52
             end
41 53
             plotDecodePerformanceWithSE(frameStart,frameEnd,decodePerformance)
42
-    end
43 54
             
44 55
             plot([psthStart psthEnd],[chanceLevel chanceLevel],'k:');
56
+            plotBinConfidenceIntervall(psthStart,psthEnd,nTrials,0.05,chanceLevel/100,'--');
57
+            plotBinConfidenceIntervall(psthStart,psthEnd,nTrials,0.01,chanceLevel/100,'-.');
58
+            plotBinConfidenceIntervall(psthStart,psthEnd,nTrials,0.001,chanceLevel/100,':');
45 59
 
46
-    plotBinConfidenceIntervall(psthStart,psthEnd,nTrials,0.05,chanceLevel/100,'r');
47
-    plotBinConfidenceIntervall(psthStart,psthEnd,nTrials,0.01,chanceLevel/100,'g');
48
-    
60
+    end
61
+toc(plottime);    
49 62
     hold off;
50 63
     
51
-%     setTitle(f,header,decode,subjectData);
52
-    
53 64
 end
54 65
 
55 66
 function plotBinConfidenceIntervall(pStart,pEnd,nTrials,alpha,limit,color)
56 67
     [pLevel Z] = rev_ki_bin(nTrials,alpha,limit);
57 68
     [lower upper proz] = ki_bin(Z,nTrials,alpha);
58 69
 
59
-    plot([pStart pEnd],[pLevel*100 pLevel*100],[color ':']);
60
-
61
-    plot([pStart pEnd],[lower*100 lower*100],[color '-.']);
62
-    plot([pStart pEnd],[upper*100 upper*100],[color '-.']);
70
+    plot([pStart pEnd],[pLevel*100 pLevel*100],[color 'k']);
71
+%     plot([pStart pEnd],[lower*100 lower*100],[color 'k']);
72
+%     plot([pStart pEnd],[upper*100 upper*100],[color 'k']);
63 73
 end
64 74
 
65 75
 function n = getNTrials(psth)
66
-nSubjects = size(psth,2);
76
+nOverallConditions = size(psth,2);
67 77
 
68 78
 n = 0;
69
-for ns = 1:nSubjects
79
+for ns = 1:nOverallConditions
70 80
     nClasses = size(psth{ns},2);
71 81
     for nc = 1:nClasses
72 82
         n = n + size(psth{ns}{nc},1);
73 83
     end
74 84
 end
85
+n=n/(nOverallConditions/nClasses);
86
+
75 87
 end
76 88
 
77 89
 function plotClassPerformance(frameStart,frameEnd,decodePerformance,nClasses)
... ...
@@ -104,7 +116,9 @@ PSTH_AXIS_MAX = 2;
104 116
                   psthData = nanmean(psth{voxel}{label});
105 117
               end
106 118
               PSTH_AXIS_MAX = max(PSTH_AXIS_MAX,nanmax(psthData));
119
+              PSTH_AXIS_MIN = min(PSTH_AXIS_MIN,nanmin(psthData));
107 120
               plot(psthStart:psthEnd,psthData,[colorChooser(voxel), lineStyleChooser(label)]);
121
+%               plot(psthStart:psthEnd,psthData,[lineStyleChooser(voxel), colorChooser(label)]);
108 122
           end
109 123
       end
110 124
     end
... ...
@@ -0,0 +1,20 @@
1
+function [PROZ Z] = rev_ki_bin(N,alpha,KI_u)
2
+% rausbekommen ab wie vielen (hypothetischen) Beobachtungen einer Klasse 
3
+% (f�r ein gegebenes N, dh alle trials/Cross-Validations) das 
4
+% Konfidenzintervall f�r die decode performance f�r diese Klasse den 
5
+% 50%-Wert (also chance) gerade noch umschliesst (dh. KI_u=50%). Der 
6
+% zugeh�rige PROZ wert w�rde dann die Schwelle fetlegen, die geplottet 
7
+% werden soll. Decode werte �ber dieser Schwelle w�ren dann mit 95% 
8
+% Sicherheit signifikant.
9
+
10
+
11
+Z = 0;
12
+KI_low = 0;
13
+% tic
14
+while KI_low < KI_u && (Z+1)< N
15
+    Z = Z + 1;
16
+    KI_low = ki_bin(Z,N,alpha); 
17
+end
18
+% toc
19
+PROZ = Z/N;
20
+end
0 21
\ No newline at end of file