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,
          phierr - standard deviation for phi
          Cerr (Jacknife error bars-only for Jackknife)

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,
0017 %          phierr - standard deviation for phi
0018 %          Cerr (Jacknife error bars-only for Jackknife)
0019 if nargin < 5; error('Need at least 5 input arguments'); end;
0020 if err(1)==0; error('Need err=[1 p] or [2 p] for error bar calculation'); end;
0021 if nargout==3  & err(1)==1; error('Cerr contains Jackknife errors: check input arguments'); end;
0022 [nf,K,Ch]=size(J1);
0023 errchk=err(1);
0024 p=err(2);
0025 pp=1-p/2;
0026 qq=1-p;
0027 %
0028 % Find the number of degrees of freedom
0029 %
0030 if trialave;
0031    dim=K*Ch;
0032    dof=dim;
0033    dof1=dof;
0034    dof2=dof;
0035    Ch=1;
0036    if nargin>=6 & ~isempty(numsp1) 
0037       totspikes1=sum(numsp1);
0038       dof1=fix(2*totspikes1*dof/(2*totspikes1+dof));
0039    end
0040    if nargin==7 & ~isempty(numsp2); 
0041       totspikes2=sum(numsp2);
0042       dof2=fix(2*totspikes2*dof/(2*totspikes2+dof));
0043    end;
0044    dof=min(dof1,dof2);
0045    J1=reshape(J1,nf,dim);
0046    J2=reshape(J2,nf,dim);
0047 else;
0048    dim=K;
0049    dof=dim;
0050    dof1=dof;
0051    dof2=dof;
0052    for ch=1:Ch;
0053       if nargin>=6 & ~isempty(numsp1);
0054          totspikes1=numsp1(ch); 
0055         dof1=fix(2*totspikes1*dof/(2*totspikes1+dof));
0056       end;
0057       if nargin==7 & ~isempty(numsp2);
0058          totspikes2=numsp2(ch);
0059         dof2=fix(2*totspikes2*dof/(2*totspikes2+dof));
0060       end;
0061       dof(ch)=min(dof1,dof2);
0062    end;
0063 end;
0064 %
0065 % variance of the phase
0066 %
0067 if isempty(find((C-1).^2 < 10^-5));
0068    phierr = sqrt((2./dof(ones(nf,1),:)).*(1./(C.^2) - 1));  
0069 else
0070    phierr = zeros(nf,Ch);
0071 end  
0072 %
0073 % theoretical, asymptotic confidence level
0074 %
0075 if dof <= 2
0076    confC = 1;
0077 else     
0078    df = 1./((dof/2)-1);
0079    confC = sqrt(1 - p.^df);
0080 end;
0081 if errchk==2;
0082     tcrit=tinv(pp,dof-1);
0083     for k=1:dim;
0084         indxk=setdiff([1:dim],k);
0085         J1jk=J1(:,indxk,:);
0086         J2jk=J2(:,indxk,:);
0087         eJ1jk=squeeze(sum(J1jk.*conj(J1jk),2));
0088         eJ2jk=squeeze(sum(J2jk.*conj(J2jk),2));
0089         eJ12jk=squeeze(sum(conj(J1jk).*J2jk,2)); 
0090         atanhCxyjk(k,:,:)=sqrt(2*dim-2)*atanh(abs(eJ12jk)./sqrt(eJ1jk.*eJ2jk));
0091     end; 
0092     atanhC=sqrt(2*dim-2)*atanh(C);
0093     sigma12=sqrt(dim-1)*squeeze(std(atanhCxyjk,1,1));
0094      if Ch==1; sigma12=sigma12'; end;
0095     Cu=atanhC+tcrit(ones(nf,1),:).*sigma12;
0096     Cl=atanhC-tcrit(ones(nf,1),:).*sigma12;
0097     Cerr(1,:,:) = tanh(Cl/sqrt(2*dim-2));
0098     Cerr(2,:,:) = tanh(Cu/sqrt(2*dim-2));
0099 end;

Generated on Tue 24-Aug-2004 15:55:33 by m2html © 2003