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

Generated on Fri 20-May-2005 13:10:28 by m2html © 2003