Back to the main page.
Bug 3420 - implement Pearson's correlation in ft_statistics_stats
Status | CLOSED FIXED |
Reported | 2018-03-27 16:06:00 +0200 |
Modified | 2019-08-10 12:37:24 +0200 |
Product: | FieldTrip |
Component: | core |
Version: | unspecified |
Hardware: | PC |
Operating System: | Mac OS |
Importance: | P5 normal |
Assigned to: | Robert Oostenveld |
URL: | |
Tags: | |
Depends on: | |
Blocks: | |
See also: |
Robert Oostenveld - 2018-03-27 16:06:12 +0200
It would be nice to have Pearsons and Spearmans correlation in ft_statistics_stats, such that it is accessible with method=stats and statistic=pearson for a quick within subject analysis. Diandra implemented this already (with some help of Robert), Nadine just did it again. This issue in bugzilla serves to follow this up and to make sure it gets added to teh FieldTrip release version.
Robert Oostenveld - 2018-03-27 16:07:13 +0200
On 27 Mar 2018, at 15:41, Nadine wrote: N.a.v. de MEEG meeting afgelopen maandag heb ik de volgende code geschreven als toevoeging voor de ft_statistics_stats functie. Bij mij werkt die, dus ik dacht dat het misschien handig was om te hebben voor andere mensen. De values waarmee de data gecorreleerd wordt moeten in ‘design’ staan. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% case {'Pearson'} % set the defaults cfg.alpha = ft_getopt(cfg, 'alpha', 0.05); switch cfg.tail case 0 cfg.tail = 'both'; case -1 cfg.tail = 'left'; case 1 cfg.tail = 'right'; end if size(design,1)~=1 ft_error('design matrix should only contain one factor (i.e. one row)'); end Ncond = length(unique(design)); if Ncond<2 ft_error('method ''%s'' is only supported for varying values', cfg.statistic); end Nobs = size(dat, 1); h = zeros(Nobs, 1); p = zeros(Nobs, 1); s = zeros(Nobs, 1); fprintf('number of observations %d\n', Nobs); ft_progress('init', cfg.feedback); for chan = 1:Nobs ft_progress(chan/Nobs, 'Processing observation %d/%d\n', chan, Nobs); [s(chan), p(chan)] = corr(dat(chan, :)', design','type','Pearson','tail',cfg.tail); h(chan) = p(chan) <= cfg.alpha; end ft_progress('close');
Robert Oostenveld - 2018-03-27 16:12:13 +0200
we always start with a small test script, which gets added to fieldtrip/test. I have created test_bug3420, which contains %% timelock = []; timelock.time = (1:1000)/1000; timelock.dimord = 'rpt_chan_time'; for i=1:32 timelock.label{i} = num2str(i); end for i=1:100 timelock.trial(i,:,:) = randn(64,1000) + i; end %% cfg = []; cfg.design = 1:100; cfg.ivar = 1; cfg.method = 'stats'; cfg.statistic = 'pearson'; statp = ft_timelockstatistics(cfg, timelock);
Robert Oostenveld - 2018-03-27 16:38:23 +0200
I made a branch in the git repository and added the code mac011> git commit -a [bug3420-pearson 1baf1f2] Implement Pearson's correlation in ft_statistics_stats See http://bugzilla.fieldtriptoolbox.org/show_bug.cgi?id=3420 2 files changed, 496 insertions(+), 380 deletions(-) rewrite ft_statistics_stats.m (70%) create mode 100644 test/test_bug3420.m Then I pushed the code to github, where I will make a pull request (PR). git push --set-upstream origin bug3420-pearson
Robert Oostenveld - 2018-03-27 16:41:22 +0200
The PR is at https://github.com/fieldtrip/fieldtrip/pull/682. You can go there and check out the changes. One large change (accidental) is that I re-indented the other code in ft_statistics_stat. There are actually no content changes, just different whitespace. I have (as project admin) merged the PR (which I sent as normal person), it is now in the release version. The next time you can do this yourself by following the tutorial at http://www.fieldtriptoolbox.org/development/git