I am using xcorr
to calculate the cross-correlation between two time series. In order to assess statistical significance, I need to perform bootstrapping and create random correlations between the two time series to create a null distribution. So for instance timeseries1
is of size 16x11 (which is 16 time points and 11 subjects) and timeseries2
is also sized 16x11. Here the subjects are matched pairs so, for example,
timeseries1(:,1)
is matched to timeseries2(:,1)
; i.e. timeseries1 is one type of data from subject one and timeseries2(:,1)
is a different type of data from subject one.
I need to scramble them such that I create new random correlations such as timeseries1(:,1)
with timeseries2(:,5)
etc.
I was trying to use boostrp
as follows
scorr = @(timseries1,timeseries2)(xcorr(timseries1,timeseries2,'coeff'));
bootstat = bootstrp(1000,scorr,a,b);
However, I'm getting an error because bootstrap only accepts vectors and not matrices. In the documentation of the function, all the examples that are provided have data that is 1 value per subject so for example LSAT score from 15 subjects correlated with other test score from 15 subjects. But I have 16 samples per subject and I won't be able to do a cross-correlation if I reduce the time series to one time point.
Does anyone have any advice on how this can be done?
you could use randperm to sample without replacement, which will return two different random intergers between 1:n_subjects:
n_boot = 100;
n_subj = 11;
n_samples = 16;
timeseries1 = randn(n_samples, n_subj);
timeseries2 = randn(n_samples, n_subj);
null_dist = nan(n_boot, ...
n_samples*2-1);
for i = 1:n_boot
subjs_to_corr = randperm(n_subj, 2); % draw 2 random numbers from 1:n_subj without replacement
null_dist(i, :) = xcorr(timeseries1(:, subjs_to_corr(1)), ...
timeseries2(:, subjs_to_corr(2)));
end