den_jack.m 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. function [m,ll,ul,llj,ulj]=den_jack(X,family,varargin)
  2. % Function to compute smooth estimates of the mean of x using locfit,
  3. % the corresponding confidence intervals, and jackknife estimates of
  4. % the confidence intervals
  5. % Usage: [m,ll,ul,llj,ulj]=den_jack(x)
  6. %
  7. % Inputs:
  8. % X: data in the form samples x trials
  9. % family: 'density' or 'reg' for regression
  10. % If the family is density, the entire input matrix X is considered
  11. % as data. If the family is regression then the first column of X is
  12. % taken to be the independent variable and the remaining columns are
  13. % regressed on this variable (for example, the first column may be
  14. % the centers of the bins for binned spike count data)
  15. % varargin is the set of arguments used by locfit to perform the smoothing
  16. %
  17. % Outputs:
  18. % m : smoothed estimate of the mean
  19. % ll : estimate of the lower confidence level
  20. % ul : estimate of the upper confidence level
  21. % llj : jackknife estimate of the lower confidence level (+2\sigma
  22. % where sigma is the jackknife variance)
  23. % llu : jackknife estimate of the upper confidence level (-2\sigma
  24. % where sigma is the jackknife variance)
  25. [N,NT]=size(X);
  26. if strcmp(family,'reg');
  27. yy=X(:,2:end);
  28. y=mean(yy,2);
  29. x=X(:,1);
  30. z=scb(x,y,varargin{:});
  31. figure;
  32. plot(z(:,1),z(:,2));
  33. hold on;
  34. plot(z(:,1),z(:,3),'b:');
  35. plot(z(:,1),z(:,4),'b:');
  36. title('Smoothed density estimate, all data');
  37. % fit=locfit(x,y,varargin{:});
  38. % xfit = lfmarg(fit);
  39. % yfit = predict(fit,xfit);
  40. % z = invlink(yfit,fit{4}{5});
  41. %
  42. for tr=1:NT-1;
  43. % i=setdiff(1:NT-1,tr);
  44. % y=mean(yy(:,i),2);
  45. y=yy(:,tr);
  46. fit=locfit(x,y,varargin{:});
  47. xfit = lfmarg(fit);
  48. yfit = predict(fit,xfit);
  49. yfit = invlink(yfit,fit{4}{5});
  50. zz(:,tr)=yfit;
  51. % theta(:,tr)=NT*z-(NT-1)*yfit;
  52. end;
  53. % thetam=mean(theta,2);
  54. % variance=var(theta,0,2);
  55. % standard_dev=sqrt(variance);
  56. % figure; plot(xfit{1},thetam,'b');
  57. % hold on; plot(xfit{1},thetam+2*standard_dev,'r');
  58. % plot(xfit{1},thetam-2*standard_dev,'r');
  59. % pause;
  60. [m,jsd]=jackknife(zz);
  61. % plot(xfit{1},m,'r');
  62. hold on;
  63. plot(xfit{1},m+2*jsd,'r:');
  64. plot(xfit{1},m-2*jsd,'r:');
  65. figure;
  66. plot(xfit{1},zz);
  67. title('All trials');
  68. else
  69. x=mean(X,2);
  70. fit=locfit(x,varargin{:});
  71. figure;lfplot(fit);
  72. lfband(fit);
  73. end;