lfband.m 958 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. function lfband(fit,varargin)
  2. % adds confidence bands around the plot of a locfit() fit.
  3. %
  4. % for 2-d fits, produces separate surface plots of upper and
  5. % lower confidence limits.
  6. %
  7. % Bands are based on 95% pointwise coverage, using a single
  8. % (i.e. global) estimate of sigma^2.
  9. xfit = lfmarg(fit);
  10. % placing 'band','g' before varargin{:} ensures that
  11. % user-provided 'band' has precedence.
  12. ypp = predict(fit,xfit,'band','g',varargin{:});
  13. yfit = ypp{1};
  14. se = ypp{2};
  15. bands = ypp{3};
  16. data = fit.data;
  17. xdata = data.x;
  18. p = size(xdata,2);
  19. cv = 1.96;
  20. fali = fit.fit_points.family_link;
  21. cl = invlink(bands(:,1),fali);
  22. cu = invlink(bands(:,2),fali);
  23. if (p==1)
  24. hold on;
  25. plot(xfit{1},cu,':');
  26. plot(xfit{1},cl,':');
  27. hold off;
  28. end;
  29. if (p==2)
  30. x1 = xfit{1};
  31. x2 = xfit{2};
  32. figure(1);
  33. surf(x1,x2,reshape(cl,length(x1),length(x2))');
  34. figure(2);
  35. surf(x1,x2,reshape(cu,length(x1),length(x2))');
  36. end;
  37. return;