Function to compute smooth estimates of the mean of x using locfit, the corresponding confidence intervals, and jackknife estimates of the confidence intervals Usage: [m,ll,ul,llj,ulj]=den_jack(x) Inputs: X: data in the form samples x trials family: 'density' or 'reg' for regression If the family is density, the entire input matrix X is considered as data. If the family is regression then the first column of X is taken to be the independent variable and the remaining columns are regressed on this variable (for example, the first column may be the centers of the bins for binned spike count data) varargin is the set of arguments used by locfit to perform the smoothing Outputs: m : smoothed estimate of the mean ll : estimate of the lower confidence level ul : estimate of the upper confidence level llj : jackknife estimate of the lower confidence level (+2\sigma where sigma is the jackknife variance) llu : jackknife estimate of the upper confidence level (-2\sigma where sigma is the jackknife variance)
0001 function [m,ll,ul,llj,ulj]=den_jack(X,family,varargin) 0002 % Function to compute smooth estimates of the mean of x using locfit, 0003 % the corresponding confidence intervals, and jackknife estimates of 0004 % the confidence intervals 0005 % Usage: [m,ll,ul,llj,ulj]=den_jack(x) 0006 % 0007 % Inputs: 0008 % X: data in the form samples x trials 0009 % family: 'density' or 'reg' for regression 0010 % If the family is density, the entire input matrix X is considered 0011 % as data. If the family is regression then the first column of X is 0012 % taken to be the independent variable and the remaining columns are 0013 % regressed on this variable (for example, the first column may be 0014 % the centers of the bins for binned spike count data) 0015 % varargin is the set of arguments used by locfit to perform the smoothing 0016 % 0017 % Outputs: 0018 % m : smoothed estimate of the mean 0019 % ll : estimate of the lower confidence level 0020 % ul : estimate of the upper confidence level 0021 % llj : jackknife estimate of the lower confidence level (+2\sigma 0022 % where sigma is the jackknife variance) 0023 % llu : jackknife estimate of the upper confidence level (-2\sigma 0024 % where sigma is the jackknife variance) 0025 [N,NT]=size(X); 0026 if strcmp(family,'reg'); 0027 yy=X(:,2:end); 0028 y=mean(yy,2); 0029 x=X(:,1); 0030 z=scb(x,y,varargin{:}); 0031 figure; 0032 plot(z(:,1),z(:,2)); 0033 hold on; 0034 plot(z(:,1),z(:,3),'b:'); 0035 plot(z(:,1),z(:,4),'b:'); 0036 title('Smoothed density estimate, all data'); 0037 0038 % fit=locfit(x,y,varargin{:}); 0039 % xfit = lfmarg(fit); 0040 % yfit = predict(fit,xfit); 0041 % z = invlink(yfit,fit{4}{5}); 0042 % 0043 for tr=1:NT-1; 0044 % i=setdiff(1:NT-1,tr); 0045 % y=mean(yy(:,i),2); 0046 y=yy(:,tr); 0047 fit=locfit(x,y,varargin{:}); 0048 xfit = lfmarg(fit); 0049 yfit = predict(fit,xfit); 0050 yfit = invlink(yfit,fit{4}{5}); 0051 zz(:,tr)=yfit; 0052 % theta(:,tr)=NT*z-(NT-1)*yfit; 0053 end; 0054 % thetam=mean(theta,2); 0055 % variance=var(theta,0,2); 0056 % standard_dev=sqrt(variance); 0057 % figure; plot(xfit{1},thetam,'b'); 0058 % hold on; plot(xfit{1},thetam+2*standard_dev,'r'); 0059 % plot(xfit{1},thetam-2*standard_dev,'r'); 0060 % pause; 0061 [m,jsd]=jackknife(zz); 0062 % plot(xfit{1},m,'r'); 0063 hold on; 0064 plot(xfit{1},m+2*jsd,'r:'); 0065 plot(xfit{1},m-2*jsd,'r:'); 0066 figure; 0067 plot(xfit{1},zz); 0068 title('All trials'); 0069 else 0070 x=mean(X,2); 0071 fit=locfit(x,varargin{:}); 0072 figure;lfplot(fit); 0073 lfband(fit); 0074 end; 0075 0076 0077