Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision Both sides next revision
example:stratify [2018/10/21 15:00]
42.49.180.224 [Stratify the distribution of one variable that differs in two conditions]
example:stratify [2017/08/17 11:21] (current)
127.0.0.1 external edit
Line 7: Line 7:
 Finally, this example page shows how you can very simply stratify with the FieldTrip **[[:​reference:​ft_stratify]]** function. Although the example here only looks at a single channel, quite often you'll want to stratify the power in two channels simultaneously (e.g. for coherence computation). The **[[:​reference:​ft_stratify]]** function allows you to do that, and also solves the within-bin bias problem (cfg.equalbinavg='​yes'​). Finally, this example page shows how you can very simply stratify with the FieldTrip **[[:​reference:​ft_stratify]]** function. Although the example here only looks at a single channel, quite often you'll want to stratify the power in two channels simultaneously (e.g. for coherence computation). The **[[:​reference:​ft_stratify]]** function allows you to do that, and also solves the within-bin bias problem (cfg.equalbinavg='​yes'​).
  
-&lt;code&gt;+<code>
  
 s1_orig = randn(1,​10000);​ s1_orig = randn(1,​10000);​
Line 22: Line 22:
 figure; hist(s, 100) figure; hist(s, 100)
  
-&lt;/code&gt;+</code>
  
 {{:​example:​twodistributions.png?​500|}} {{:​example:​twodistributions.png?​500|}}
Line 28: Line 28:
 **Figure 1** Two distributions with different means **Figure 1** Two distributions with different means
  
-&lt;code&gt;+<code>
 % trim the extremes % trim the extremes
 s1 = sort(s1); s1 = sort(s1);
Line 36: Line 36:
 m2 = mean(s2); m2 = mean(s2);
  
-while (m2&gt;m1)+while (m2>m1)
  s1 = s1(2:end);  s1 = s1(2:end);
  s2 = s2(1:​end-1);​  s2 = s2(1:​end-1);​
Line 48: Line 48:
 figure; hist(s, 100) figure; hist(s, 100)
  
-&lt;/code&gt;+</code>
  
 {{:​example:​rmextremes.png?​500|}} {{:​example:​rmextremes.png?​500|}}
Line 54: Line 54:
 **Figure 2** Here we have made the means of the two distributions approximately the same by removing the extreme values of the tails of the two distributions **Figure 2** Here we have made the means of the two distributions approximately the same by removing the extreme values of the tails of the two distributions
  
-&lt;code&gt;+<code>
  
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Line 77: Line 77:
  ​binbeg = binval(i);  ​binbeg = binval(i);
  ​binend = binval(i+1);​  ​binend = binval(i+1);​
- sel1 = find(s1&gt;binbeg &amp; s1&lt;binend); + sel1 = find(s1>binbeg & s1<binend); 
- sel2 = find(s2&gt;binbeg &amp; s2&lt;binend); + sel2 = find(s2>binbeg & s2<binend); 
- if length(sel1)&gt;length(sel2)+ if length(sel1)>length(sel2)
    % remove some of the trials in s1    % remove some of the trials in s1
    sel1 = sel1(randperm(length(sel1)));​    sel1 = sel1(randperm(length(sel1)));​
Line 85: Line 85:
    ​keep1(sel1) = true;    ​keep1(sel1) = true;
    ​keep2(sel2) = true;    ​keep2(sel2) = true;
- ​elseif length(sel1)&lt;length(sel2)+ ​elseif length(sel1)<length(sel2)
    % remove some of the trials in s2    % remove some of the trials in s2
    sel2 = sel2(randperm(length(sel2)));​    sel2 = sel2(randperm(length(sel2)));​
Line 101: Line 101:
 figure; hist(s, 100) figure; hist(s, 100)
  
-&lt;/code&gt;+</code>
  
 {{:​example:​align_distib.png?​500|}} {{:​example:​align_distib.png?​500|}}
Line 110: Line 110:
 Note that this easily can be achieved with the FieldTrip **[[:​reference:​ft_stratify]]** function like this Note that this easily can be achieved with the FieldTrip **[[:​reference:​ft_stratify]]** function like this
  
-&lt;code&gt;+<code>
 cfg = []; cfg = [];
 cfg.method ​     = '​histogram'​ cfg.method ​     = '​histogram'​
Line 128: Line 128:
 s = [s1(:) s2(:)]; s = [s1(:) s2(:)];
 figure; hist(s, 100) figure; hist(s, 100)
-&lt;/code&gt;+</code