# [FieldTrip] What is the data present in the covariance matrix after using ft_timelockanalysis

Soujata Borbaruah s.borbaruah at student.utwente.nl
Fri Jun 17 10:11:15 CEST 2016

```Hello Alexander,

Thank you for your feedback. So is it safe to say that the final data
present in the covariance matrix (MxM where M is the number of channels) is
the average of the covariance matrices over multiple trials?

Regards,

Soujata.

Sent with MailTrack
<https://mailtrack.io/install?source=signature&lang=en&referral=s.borbaruah@student.utwente.nl&idSignature=22>

On Thu, Jun 16, 2016 at 5:00 PM, Nakhnikian, Alexander <
Alexander_Nakhnikian at hms.harvard.edu> wrote:

> Hi Soujatta,
>
>
> I hope I understand your question.
>
>
> For demeaned data, the covariance is the expected value of sum(xy).  For
> data with finite mean, we have to get the expected value of
> sum(x-mu(x))*sum(y-mu(y)).  Removing the mean and trend doesn't have any
> impact on the denominators used to compute the unbiased estimate of
> E{sum(xy)}.  The unbiased covariance estimated between x and y for a given
> trial is sum(xy)/(N_times-1), where N _times is the number of time points
> in an epoch.  When averaging covariance matrices over multiple trials the
> denominator becomes N_trs-1.  I hope that helps.
>
>
> Best,
>
>
> Alexander
> ------------------------------
> *From:* fieldtrip-bounces at science.ru.nl <fieldtrip-bounces at science.ru.nl>
> on behalf of Soujata Borbaruah <s.borbaruah at student.utwente.nl>
> *Sent:* Thursday, June 16, 2016 10:19:12 AM
> *To:* fieldtrip, donders
> *Subject:* [FieldTrip] What is the data present in the covariance matrix
> after using ft_timelockanalysis
>
> Hello,
>
> I want to calculate the covariance of the data I provide. In the function
> ft_timelockanalysis there is a portion where the covariance is being
> normalised over all trials by the total number of samples in all trials.
>
>
> % normalize the covariance over all trials by the total number of samples
> in all trials
> if strcmp(cfg.covariance, 'yes')
>   if strcmp(cfg.keeptrials,'yes')
>     for i=1:ntrial
>       if strcmp(cfg.removemean, 'yes')
>         covsig(i,:,:) = covsig(i,:,:) / (numcovsigsamples(i)-1);
>       else
>         covsig(i,:,:) = covsig(i,:,:) / numcovsigsamples(i);
>       end
>     end
>   else
>     if strcmp(cfg.removemean, 'yes')
>       covsig = squeeze(nansum(covsig, 1)) / (sum(numcovsigsamples)-ntrial);
>     else
>       covsig = squeeze(nansum(covsig, 1)) / sum(numcovsigsamples);
>
>     end
>   end
> end
>
> Please note that the cfg.removemean was selected as yes.
>
> Can someone please explain what is the final data present in my covariance
> matrix?
>
>
>
> Sent with MailTrack
> <https://mailtrack.io/install?source=signature&lang=en&referral=s.borbaruah@student.utwente.nl&idSignature=22>
>
> _______________________________________________
> fieldtrip mailing list
> fieldtrip at donders.ru.nl
> https://mailman.science.ru.nl/mailman/listinfo/fieldtrip
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.science.ru.nl/pipermail/fieldtrip/attachments/20160617/0192f77c/attachment-0002.html>
```