Home > chronux_1_1 > helper > coherr.m

coherr

PURPOSE ^

Function to compute lower and upper confidence intervals on the coherency given the tapered fourier transforms,

SYNOPSIS ^

function [confC,phierr,Cerr]=coherr(C,J1,J2,err,trialave,numsp1,numsp2)

DESCRIPTION ^

 Function to compute lower and upper confidence intervals on the coherency given the tapered fourier transforms, 
 errchk, trialave.
 Usage: [confC,phierr,Cerr]=coherr(C,J1,J2,err,trialave,numsp1,numsp2)
 Inputs:
 C     - coherence
 J1,J2 - tapered fourier transforms 
 err - [errtype p] (errtype=1 - asymptotic estimates; errchk=2 - Jackknife estimates; 
                   p - p value for error estimates)
 trialave - 0: no averaging over trials/channels
            1 : perform trial averaging
 numsp1    - number of spikes for data1. supply only if finite size corrections are required
 numsp2    - number of spikes for data2. supply only if finite size corrections are required

 Outputs: 
          confC - confidence level for C - only for err(1)>=1
          phierr - standard deviation for phi - only for err(1)>=1
          returns zero if coherence is too close to 1
          Cerr (Jacknife error bars-only for Jackknife) - only for
          err(1)=2

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [confC,phierr,Cerr]=coherr(C,J1,J2,err,trialave,numsp1,numsp2)
0002 % Function to compute lower and upper confidence intervals on the coherency given the tapered fourier transforms,
0003 % errchk, trialave.
0004 % Usage: [confC,phierr,Cerr]=coherr(C,J1,J2,err,trialave,numsp1,numsp2)
0005 % Inputs:
0006 % C     - coherence
0007 % J1,J2 - tapered fourier transforms
0008 % err - [errtype p] (errtype=1 - asymptotic estimates; errchk=2 - Jackknife estimates;
0009 %                   p - p value for error estimates)
0010 % trialave - 0: no averaging over trials/channels
0011 %            1 : perform trial averaging
0012 % numsp1    - number of spikes for data1. supply only if finite size corrections are required
0013 % numsp2    - number of spikes for data2. supply only if finite size corrections are required
0014 %
0015 % Outputs:
0016 %          confC - confidence level for C - only for err(1)>=1
0017 %          phierr - standard deviation for phi - only for err(1)>=1
0018 %          returns zero if coherence is too close to 1
0019 %          Cerr (Jacknife error bars-only for Jackknife) - only for
0020 %          err(1)=2
0021 if nargin < 5; error('Need at least 5 input arguments'); end;
0022 if err(1)==0; error('Need err=[1 p] or [2 p] for error bar calculation'); end;
0023 if nargout==3  && err(1)==1; error('Cerr contains Jackknife errors: check input arguments'); end;
0024 [nf,K,Ch]=size(J1);
0025 errchk=err(1);
0026 p=err(2);
0027 pp=1-p/2;
0028 %
0029 % Find the number of degrees of freedom
0030 %
0031 if trialave;
0032    dim=K*Ch;
0033    dof=2*dim;
0034    dof1=dof;
0035    dof2=dof;
0036    Ch=1;
0037    if nargin>=6 && ~isempty(numsp1) 
0038       totspikes1=sum(numsp1);
0039       dof1=fix(2*totspikes1*dof/(2*totspikes1+dof));
0040    end
0041    if nargin==7 && ~isempty(numsp2); 
0042       totspikes2=sum(numsp2);
0043       dof2=fix(2*totspikes2*dof/(2*totspikes2+dof));
0044    end;
0045    dof=min(dof1,dof2);
0046    J1=reshape(J1,nf,dim);
0047    J2=reshape(J2,nf,dim);
0048 else
0049    dim=K;
0050    dof=2*dim;
0051    dof1=dof;
0052    dof2=dof;
0053    for ch=1:Ch;
0054       if nargin>=6 && ~isempty(numsp1);
0055          totspikes1=numsp1(ch); 
0056         dof1=fix(2*totspikes1*dof/(2*totspikes1+dof));
0057       end;
0058       if nargin==7 && ~isempty(numsp2);
0059          totspikes2=numsp2(ch);
0060         dof2=fix(2*totspikes2*dof/(2*totspikes2+dof));
0061       end;
0062       dof(ch)=min(dof1,dof2);
0063    end;
0064 end;
0065 %
0066 % variance of the phase
0067 %
0068 if isempty(find((C-1).^2 < 10^-5));
0069    phierr = sqrt((2./dof(ones(nf,1),:)).*(1./(C.^2) - 1));  
0070 else
0071    phierr = zeros(nf,Ch);
0072 end  
0073 %
0074 % theoretical, asymptotic confidence level
0075 %
0076 if dof <= 2
0077    confC = 1;
0078 else     
0079    df = 1./((dof/2)-1);
0080    confC = sqrt(1 - p.^df);
0081 end;
0082 if errchk==2;
0083     tcrit=tinv(pp,dof-1);
0084     for k=1:dim;
0085         indxk=setdiff(1:dim,k);
0086         J1jk=J1(:,indxk,:);
0087         J2jk=J2(:,indxk,:);
0088         eJ1jk=squeeze(sum(J1jk.*conj(J1jk),2));
0089         eJ2jk=squeeze(sum(J2jk.*conj(J2jk),2));
0090         eJ12jk=squeeze(sum(conj(J1jk).*J2jk,2)); 
0091         atanhCxyjk(k,:,:)=sqrt(2*dim-2)*atanh(abs(eJ12jk)./sqrt(eJ1jk.*eJ2jk));
0092     end; 
0093     atanhC=sqrt(2*dim-2)*atanh(C);
0094     sigma12=sqrt(dim-1)*squeeze(std(atanhCxyjk,1,1));
0095     if Ch==1; sigma12=sigma12'; end;
0096     Cu=atanhC+tcrit(ones(nf,1),:).*sigma12;
0097     Cl=atanhC-tcrit(ones(nf,1),:).*sigma12;
0098     Cerr(1,:,:) = tanh(Cl/sqrt(2*dim-2));
0099     Cerr(2,:,:) = tanh(Cu/sqrt(2*dim-2));
0100 end;

Generated on Sun 13-Aug-2006 11:49:44 by m2html © 2003