predict.m 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. function [y, se] = predict(varargin)
  2. % Interpolate a fit produced by locfit().
  3. %
  4. % predict(fit) produces the fitted values at locfit's selected points.
  5. % predict(fit,x) interpolates the fits to points specified by x.
  6. %
  7. % Input arguments:
  8. % fit The locfit() fit.
  9. % x Points to interpolate at. May be a matrix with d columns,
  10. % or cell with d components (each a vector). In the former
  11. % case, a fitted value is computed for each row of x.
  12. % In the latter, the components of x are interpreted as
  13. % grid margins.
  14. % Can also specify 'data' (evaluate at data points);
  15. % or 'fitp' (extract the fitted points).
  16. % 'band',value
  17. % Type of standard errors to compute. Default is 'band','n', for none.
  18. % Other choices are 'band','g' (use a global s to estimate the resiudal
  19. % standard deviation, so standard errors are s*||l(x)||);
  20. % 'band','l' (use a local s(x), so std. errors are s(x)*||l(x)||);
  21. % 'band','p' (prediction errors, so s*sqrt(1+||l(x)||^2).
  22. % 'direct'
  23. % Compute the local fit directly (rather than using local
  24. % regression, at each point specified by the x argument.
  25. % 'kappa',vector
  26. % Vector of constants for simultaneous confidence bands,
  27. % computed by the kappa0() function.
  28. % 'level',value
  29. % Coverage probability for confidence intervals and bands.
  30. % Default is 0.95.
  31. %
  32. % Output is a vector of fitted values (if 'band','n'), or a cell
  33. % with fitted value, standard error vectors, and matrix of lower
  34. % and upper confidence limits.
  35. %
  36. % Note that for local likelihood fits, back-transformation is
  37. % not performed, so that (e.g.) for Poisson regression with the
  38. % log-link, the output estimates the log-mean, and its standard errors.
  39. % Likewise, for density estimation, the output is log(density).
  40. %
  41. % Author: Catherine Loader.
  42. if (nargin<1)
  43. error('predict requires fit argument');
  44. end;
  45. fit = varargin{1};
  46. if (nargin==1) x = 'fitp'; else x = varargin{2}; end;
  47. band = 'n';
  48. what = 'coef';
  49. rest = 'none';
  50. dir = 0;
  51. level = 0.95;
  52. d = size(fit.data.x,2);
  53. kap = [zeros(1,d) 1];
  54. na = 3;
  55. while na <= nargin
  56. inc = 0;
  57. if strcmp(varargin{na},'band')
  58. band = varargin{na+1};
  59. inc = 2;
  60. end;
  61. if strcmp(varargin{na},'what')
  62. what = varargin{na+1};
  63. inc = 2;
  64. end;
  65. if strcmp(varargin{na},'restyp')
  66. rest = varargin{na+1};
  67. inc = 2;
  68. end;
  69. if strcmp(varargin{na},'direct')
  70. dir = 1;
  71. inc = 1;
  72. end;
  73. if strcmp(varargin{na},'kappa')
  74. kap = varargin{na+1};
  75. inc = 2;
  76. end;
  77. if strcmp(varargin{na},'level')
  78. level = varargin{na+1};
  79. inc = 2;
  80. end;
  81. if (inc == 0)
  82. disp(varargin{na});
  83. error('Unknown argument');
  84. end;
  85. na = na+inc;
  86. end;
  87. [y se cb] = mexpp(x,fit,band,what,rest,dir,kap,level);
  88. if (band=='n')
  89. y = y;
  90. else
  91. y = {y se cb};
  92. end;
  93. return;