README 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. Locfit, Matlab 2.01
  2. http://locfit.herine.net/
  3. April 2, 2007
  4. Attaching:
  5. Make sure that you've added this directory recursively (i.e. with
  6. all subdirectories) to your matlab search path.
  7. Basic usage:
  8. (1) To plot of a smooth curve:
  9. load ethanol; % load the dataset.
  10. fit = locfit(E,NOx) % local regression, with x,y vectors.
  11. lfplot(fit) % plot the fitted curve.
  12. (2a) To evaluate smooth at a specified set of points:
  13. load ethanol;
  14. xev = [0.6 0.7 0.8 0.9]'; % note column vector.
  15. fit = locfit(E,NOx,'ev',xev);
  16. yhat = predict(fit)
  17. (2b) Fit and interpolate approximation; may be faster for large datasets.
  18. load ethanol;
  19. xev = [0.6 0.7 0.8 0.9]'; % note column vector.
  20. fit = locfit(E,NOx);
  21. yhat = predict(fit,xev)
  22. (3) Surface smoothing - give matrix as first input.
  23. load ethanol; % load the dataset.
  24. fit = locfit([E C],NOx) % local regression.
  25. lfplot(fit)
  26. Most of the arguments to the S (and R) locfit() function, described
  27. in my book, will also work in the Matlab version. E.g,
  28. fit = locfit(E,NOx,'deg',1,'kern','gauss')
  29. % local linear fit with the gaussian kernel.
  30. Smoothing parameters can be set with 'nn' and 'h', instead of the
  31. alpha vector used in my book. So
  32. fit = locfit(E,NOx,'alpha',[0 0.2])
  33. fit = locfit(E,NOx,'h',0.2)
  34. are equivalent ways to specify a constant bandwidth h=0.2.
  35. The Book subdirectory contains functions to reproduce most of the book
  36. figures. Run them, and look at the source code (many around 5 lines or less)
  37. for more examples.
  38. Some differences with the S/R version (and book documentation).
  39. (1) Minor renaming of functions, mainly because matlab doesn't have
  40. S-style methods. e.g. lfplot() instead of plot() or plot.locfit().
  41. (2) Use lfband() to add confidence bands to a plot.
  42. (3) Functions such as aicplot(), gcvplot() sensitive to order of
  43. arguments. Smoothing parameter matrix must be given first.
  44. (4) For 2-d predictors, lfplot() defaults to producing a surface, rather
  45. than contour, plot.
  46. (5) The predict() function has an optional 'direct' argument, which
  47. causes the fit to be recomputed at each evaluation point, rather
  48. than interpolation of existing points.
  49. (6) A few things aren't implemented yet...
  50. Technical stuff. Here's the layout of the structure returned by
  51. the locfit() function. The first three components (data, evaluation
  52. structure and smoothing parameters) are what you provide, or default
  53. values. The last two (fit points, parametric component) are what
  54. locfit computes. The expected size or format of the entry is
  55. given in parentheses.
  56. fit.data.x (n*d)
  57. fit.data.y (n*1)
  58. fit.data.weights (n*1 or 1*1)
  59. fit.data.censor (n*1 or 1*1)
  60. fit.data.baseline (n*1 or 1*1)
  61. fit.data.style (string length d)
  62. fit.data.scales (1*d)
  63. fit.data.xlim (2*d)
  64. fit.evaluation_structure.type (string)
  65. fit.evaluation_structure.module (string)
  66. fit.evaluation_structure.lower_left (numeric 1*d)
  67. fit.evaluation_structure.upper_right (numeric 1*d)
  68. fit.evaluation_structure.grid (numeric 1*d)
  69. fit.evaluation_structure.cut (numeric 1*d)
  70. fit.evaluation_structure.maxk
  71. fit.evaluation_structure.derivative
  72. fit.smoothing_parameters.alpha = (nn h pen) vector
  73. fit.smoothing_parameters.adaptive_criterion (string)
  74. fit.smoothing_parameters.degree (numeric)
  75. fit.smoothing_parameters.family (string)
  76. fit.smoothing_parameters.link (string)
  77. fit.smoothing_parameters.kernel (string)
  78. fit.smoothing_parameters.kernel_type (string)
  79. fit.smoothing_parameters.deren
  80. fit.smoothing_parameters.deit
  81. fit.smoothing_parameters.demint
  82. fit.smoothing_parameters.debug
  83. fit.fit_points.evaluation_points (d*nv matrix)
  84. fit.fit_points.fitted_values (matrix, nv rows, many columns)
  85. fit.fit_points.evaluation_vectors
  86. fit.fit_points.fit_limits (d*2 matrix)
  87. fit.fit_points.family_link (numeric values)
  88. fit.fit_points.kappa (likelihood, degrees of freedom, etc)
  89. fit.parametric_component
  90. This was the OLD format:
  91. +-{1} data
  92. | +-{1} xdata matrix (n*d)
  93. | +-{2} ydata column vector (n*1)
  94. | +-{3} wdata weight vector (n*1 or 1*1)
  95. | +-{4} cdata censoring vector (n*1 or 1*1)
  96. | +-{5} base baseline vector (n*1 or 1*1)
  97. | +-{6} style vector (string length d)
  98. | +-{7} scales vector (1*d)
  99. | +-{8} xl xlim vector (2*d)
  100. |
  101. +-{2} evaluation structure
  102. | +-{1} structure type (string)
  103. | +-{2} module (string)
  104. | +-{3} ll corner of bounding box (numeric 1*d)
  105. | +-{4} ur corner of bounding box (numeric 1*d)
  106. | +-{5} mg vector for grid (numeric 1*d)
  107. | +-{6} cut parameter for adaptive structures (numeric 1*d)
  108. | +-{7} maxk memory control parameter
  109. | +-{8} derivative vector
  110. |
  111. +-{3} sp smoothing parameters
  112. | +-{1} alpha = (nn h pen) vector
  113. | +-{2} adaptive criterion (string)
  114. | +-{3} local polynomial degree (numeric)
  115. | +-{4} fitting family (string)
  116. | +-{5} link (string)
  117. | +-{6} kernel (string)
  118. | +-{7} kernel type - product, spherical (string)
  119. |
  120. +-{4} fpc fit points
  121. | +-{1} evaluation points, d*nv matrix.
  122. | +-{2} fitted values etc, (matrix, nv rows, many columns)
  123. | +-{3} cell of vectors generated by evaluation structure.
  124. | | +-{1} ce integer vector.
  125. | | +-{2} s integer vector.
  126. | | +-{3} lo integer vector.
  127. | | +-{4} hi integer vector.
  128. | |
  129. | +-{4} fit limits (d*2 matrix)
  130. | +-{5} [family link] (numeric values)
  131. | +-{6} 'kappa' vector. (likelihood, degrees of freedom, etc)
  132. |
  133. +-{5} parametric component vector.