locfit.html 51 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
  2. "http://www.w3.org/TR/REC-html40/loose.dtd">
  3. <html>
  4. <head>
  5. <title>Description of locfit</title>
  6. <meta name="keywords" content="locfit">
  7. <meta name="description" content="Smoothing noisy data using Local Regression and Likelihood.">
  8. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  9. <meta name="generator" content="m2html &copy; 2005 Guillaume Flandin">
  10. <meta name="robots" content="index, follow">
  11. <link type="text/css" rel="stylesheet" href="../../../m2html.css">
  12. <script type="text/javascript">
  13. if (top.frames.length == 0) { top.location = "../../../index.html"; };
  14. </script>
  15. </head>
  16. <body>
  17. <a name="_top"></a>
  18. <!-- ../../menu.html chronux_2_10 --><!-- # locfit --><!-- menu.html m -->
  19. <h1>locfit
  20. </h1>
  21. <h2><a name="_name"></a>PURPOSE <a href="#_top"><img alt="^" border="0" src="../../../up.png"></a></h2>
  22. <div class="box"><strong>Smoothing noisy data using Local Regression and Likelihood.</strong></div>
  23. <h2><a name="_synopsis"></a>SYNOPSIS <a href="#_top"><img alt="^" border="0" src="../../../up.png"></a></h2>
  24. <div class="box"><strong>function fit=locfit(varargin) </strong></div>
  25. <h2><a name="_description"></a>DESCRIPTION <a href="#_top"><img alt="^" border="0" src="../../../up.png"></a></h2>
  26. <div class="fragment"><pre class="comment"> Smoothing noisy data using Local Regression and Likelihood.
  27. arguments still to add: dc maxit
  28. Usage: fit = locfit(x,y) % local regression fit of x and y.
  29. fit = locfit(x) % density estimation of x.
  30. Smoothing with locfit is a two-step procedure. The locfit()
  31. function evaluates the local regression smooth at a set of points
  32. (can be specified through an evaluation structure). Then, use
  33. the predict() function to interpolate this fit to other points.
  34. Additional arguments to locfit() are specified as 'name',value pairs, e.g.:
  35. locfit( x, 'alpha',[0.7,1.5] , 'family','rate' , 'ev','grid' , 'mg',100 );
  36. Data-related inputs:
  37. x is a vector or matrix of the independent (or predictor) variables.
  38. Rows of x represent subjects, columns represent variables.
  39. Generally, local regression would be used with 1-4 independent
  40. variables. In higher dimensions, the curse-of-dimensionality,
  41. as well as the difficulty of visualizing higher dimensional
  42. surfaces, may limit usefulness.
  43. y is the column vector of the dependent (or response) variable.
  44. For density families, 'y' is omitted.
  45. NOTE: x and y are the first two arguments. All other arguments require
  46. the 'name',value notation.
  47. 'weights' Prior weights for observations (reciprocal of variance, or
  48. sample size).
  49. 'cens' Censoring indicators for hazard rate or censored regression.
  50. The coding is '1' (or 'TRUE') for a censored observation, and
  51. '0' (or 'FALSE') for uncensored observations.
  52. 'base' Baseline parameter estimate. If a baseline is provided,
  53. the local regression model is fitted as
  54. Y_i = b_i + m(x_i) + epsilon_i,
  55. with Locfit estimating the m(x) term. For regression models,
  56. this effectively subtracts b_i from Y_i. The advantage of the
  57. 'base' formulation is that it extends to likelihood
  58. regression models.
  59. 'scale' A scale to apply to each variable. This is especially
  60. important for multivariate fitting, where variables may be
  61. measured in non-comparable units. It is also used to specify
  62. the frequency for variables with the 'a' (angular) style.
  63. 'sty' Character string (length d) of styles for each predictor variable.
  64. n denotes `normal'; a denotes angular (or periodic); l and r
  65. denotes one-sided left and right; c is conditionally parametric.
  66. Smoothing Parameters and Bandwidths:
  67. The bandwidth (or more accurately, half-width) of the smoothing window
  68. controls the amount of smoothing. Locfit allows specification of constant
  69. (fixed), nearest neighbor, certain locally adaptive variable bandwidths,
  70. and combinations of these. Also related to the smoothing parameter
  71. are the local polynmial degree and weight function.
  72. 'nn' 'Nearest neighbor' smoothing parameter. Specifying 'nn',0.5
  73. means that the width of each smoothing neighborhood is chosen
  74. to cover 50% of the data.
  75. 'h' A constant (or fixed) bandwidth parameter. For example, 'h',2
  76. means that the smoothing windows have constant half-width
  77. (or radius) 2. Note that h is applied after scaling.
  78. 'pen' penalty parameter for adaptive smoothing. Needs to be used
  79. with care.
  80. 'alpha' The old way of specifying smoothing parameters, as used in
  81. my book. alpha is equivalent to the vector [nn,h,pen].
  82. If multiple componenents are non-zero, the largest corresponding
  83. bandwidth is used. The default (if none of alpha,nn,h,pen
  84. are provided) is [0.7 0 0].
  85. 'deg' Degree of local polynomial. Default: 2 (local quadratic).
  86. Degrees 0 to 3 are supported by almost all parts of the
  87. Locfit code. Higher degrees may work in some cases.
  88. 'kern' Weight function, default = 'tcub'. Other choices are
  89. 'rect', 'trwt', 'tria', 'epan', 'bisq' and 'gauss'.
  90. Choices may be restricted when derivatives are
  91. required; e.g. for confidence bands and some bandwidth
  92. selectors.
  93. 'kt' Kernel type, 'sph' (default); 'prod'. In multivariate
  94. problems, 'prod' uses a simplified product model which
  95. speeds up computations.
  96. 'acri' Criterion for adaptive bandwidth selection.
  97. Derivative Estimation.
  98. Generally I recommend caution when using derivative estimation
  99. (and especially higher order derivative estimation) -- can you
  100. really estimate derivatives from noisy data? Any derivative
  101. estimate is inherently more dependent on an assumed smoothness
  102. (expressed through the bandwidth) than the data. Warnings aside...
  103. 'deriv' Derivative estimation. 'deriv',1 specifies the first derivative
  104. (or more correctly, an estimate of the local slope is returned.
  105. 'deriv',[1 1] specifies the second derivative. For bivariate fits
  106. 'deriv',2 specifies the first partial derivative wrt x2.
  107. 'deriv',[1 2] is mixed second-order derivative.
  108. Fitting family.
  109. 'family' is used to specify the local likelihood family.
  110. Regression-type families are 'gaussian', 'binomial',
  111. 'poisson', 'gamma' and 'geom'. If the family is preceded
  112. by a q (e.g. 'qgauss', or 'qpois') then quasi-likelihood is
  113. used; in particular, a dispersion estimate is computed.
  114. Preceding by an 'r' makes an attempt at robust (outlier-resistant)
  115. estimation. Combining q and r (e.g. 'family','qrpois') may
  116. work, if you're lucky.
  117. Density estimation-type families are 'dens', 'rate' and 'hazard'
  118. (hazard or failure rate). Note that `dens' scales the output
  119. to be a statistical density estimate (i.e. scaled to integrate
  120. to 1). 'rate' estimates the rate or intensity function (events
  121. per unit time, or events per unit area), which may be called
  122. density in some fields.
  123. The default family is 'qgauss' if a response (y argument) has been
  124. provided, and 'dens' if no response is given.
  125. 'link' Link function for local likelihood fitting. Depending on the
  126. family, choices may be 'ident', 'log', 'logit',
  127. 'inverse', 'sqrt' and 'arcsin'.
  128. Evaluation structures.
  129. By default, locfit chooses a set of points, depending on the data
  130. and smoothing parameters, to evaluate at. This is controlled by
  131. the evaluation structure.
  132. 'ev' Specify the evaluation structure. Default is 'tree'.
  133. Other choices include 'phull' (triangulation), 'grid' (a grid
  134. of points), 'data' (each data point), 'crossval' (data,
  135. but use leave-one-out cross validation), 'none' (no evaluation
  136. points, effectively producing the global parametric fit).
  137. Alternatively, a vector/matrix of evaluation points may be
  138. provided.
  139. (kd trees not currently supported in mlocfit)
  140. 'll' and 'ur' -- row vectors specifying the upper and lower limits
  141. for the bounding box used by the evaluation structure.
  142. They default to the data range.
  143. 'mg' For the 'grid' evaluation structure, 'mg' specifies the
  144. number of points on each margin. Default 10. Can be either a
  145. single number or vector.
  146. 'cut' Refinement parameter for adaptive partitions. Default 0.8;
  147. smaller values result in more refined partitions.
  148. 'maxk' Controls space assignment for evaluation structures. For the
  149. adaptive evaluation structures, it is impossible to be sure
  150. in advance how many vertices will be generated. If you get
  151. warnings about `Insufficient vertex space', Locfit's default
  152. assigment can be increased by increasing 'maxk'. The default
  153. is 'maxk','100'.
  154. 'xlim' For density estimation, Locfit allows the density to be
  155. supported on a bounded interval (or rectangle, in more than
  156. one dimension). The format should be [ll;ul] (ie, matrix with
  157. two rows, d columns) where ll is the lower left corner of
  158. the rectangle, and ur is the upper right corner.
  159. One-sided bounds, such as [0,infty), are not supported, but can be
  160. effectively specified by specifying a very large upper
  161. bound.
  162. 'module' either 'name' or {'name','/path/to/module',parameters}.
  163. Density Estimation
  164. 'renorm',1 will attempt to renormalize the local likelihood
  165. density estimate so that it integrates to 1. The llde
  166. (specified by 'family','dens') is scaled to estimate the
  167. density, but since the estimation is pointwise, there is
  168. no guarantee that the resulting density integrates exactly
  169. to 1. Renormalization attempts to achieve this.
  170. The output of locfit() is a Matlab structure:
  171. fit.data.x (n*d)
  172. fit.data.y (n*1)
  173. fit.data.weights (n*1 or 1*1)
  174. fit.data.censor (n*1 or 1*1)
  175. fit.data.baseline (n*1 or 1*1)
  176. fit.data.style (string length d)
  177. fit.data.scales (1*d)
  178. fit.data.xlim (2*d)
  179. fit.evaluation_structure.type (string)
  180. fit.evaluation_structure.module.name (string)
  181. fit.evaluation_structure.module.directory (string)
  182. fit.evaluation_structure.module.parameters (string)
  183. fit.evaluation_structure.lower_left (numeric 1*d)
  184. fit.evaluation_structure.upper_right (numeric 1*d)
  185. fit.evaluation_structure.grid (numeric 1*d)
  186. fit.evaluation_structure.cut (numeric 1*d)
  187. fit.evaluation_structure.maxk
  188. fit.evaluation_structure.derivative
  189. fit.smoothing_parameters.alpha = (nn h pen) vector
  190. fit.smoothing_parameters.adaptive_criterion (string)
  191. fit.smoothing_parameters.degree (numeric)
  192. fit.smoothing_parameters.family (string)
  193. fit.smoothing_parameters.link (string)
  194. fit.smoothing_parameters.kernel (string)
  195. fit.smoothing_parameters.kernel_type (string)
  196. fit.smoothing_parameters.deren
  197. fit.smoothing_parameters.deit
  198. fit.smoothing_parameters.demint
  199. fit.smoothing_parameters.debug
  200. fit.fit_points.evaluation_points (d*nv matrix)
  201. fit.fit_points.fitted_values (matrix, nv rows, many columns)
  202. fit.fit_points.evaluation_vectors.cell
  203. fit.fit_points.evaluation_vectors.splitvar
  204. fit.fit_points.evaluation_vectors.lo
  205. fit.fit_points.evaluation_vectors.hi
  206. fit.fit_points.fit_limits (d*2 matrix)
  207. fit.fit_points.family_link (numeric values)
  208. fit.fit_points.kappa (likelihood, degrees of freedom, etc)
  209. fit.parametric_component
  210. The OLD format:
  211. fit{1} = data.
  212. fit{2} = evaluation structure.
  213. fit{3} = smoothing parameter structure.
  214. fit{4}{1} = fit points matrix.
  215. fit{4}{2} = matrix of fitted values etc.
  216. Note that these are not back-transformed, and may have the
  217. parametric component removed.
  218. (exact content varies according to module).
  219. fit{4}{3} = various details of the evaluation points.
  220. fit{4}{4} = fit limits.
  221. fit{4}{5} = family,link.
  222. fit{5} = parametric component values.</pre></div>
  223. <!-- crossreference -->
  224. <h2><a name="_cross"></a>CROSS-REFERENCE INFORMATION <a href="#_top"><img alt="^" border="0" src="../../../up.png"></a></h2>
  225. This function calls:
  226. <ul style="list-style-image:url(../../../matlabicon.gif)">
  227. </ul>
  228. This function is called by:
  229. <ul style="list-style-image:url(../../../matlabicon.gif)">
  230. <li><a href="../../../chronux_2_10/locfit/Book/fig10_1.html" class="code" title="">fig10_1</a> Local Regression and Likelihood, Figure 10.1.</li><li><a href="../../../chronux_2_10/locfit/Book/fig11_1.html" class="code" title="">fig11_1</a> Local Regression and Likelihood, Figure 11.1</li><li><a href="../../../chronux_2_10/locfit/Book/fig11_4.html" class="code" title="">fig11_4</a> Local Regression and Likelihood, Figure 11.4.</li><li><a href="../../../chronux_2_10/locfit/Book/fig11_5.html" class="code" title="">fig11_5</a> Local Regression and Likelihood, Figure 11.5.</li><li><a href="../../../chronux_2_10/locfit/Book/fig13_1.html" class="code" title="">fig13_1</a> Local Regression and Likelihood, Figure 13.1</li><li><a href="../../../chronux_2_10/locfit/Book/fig1_1.html" class="code" title="">fig1_1</a> Local Regression and Likelihood, Figure 1.1.</li><li><a href="../../../chronux_2_10/locfit/Book/fig2_2.html" class="code" title="">fig2_2</a> Local Regression and Likelihood, Figure 2.2.</li><li><a href="../../../chronux_2_10/locfit/Book/fig2_3.html" class="code" title="">fig2_3</a> Local Regression and Likelihood, Figure 2.3.</li><li><a href="../../../chronux_2_10/locfit/Book/fig2_4.html" class="code" title="">fig2_4</a> Local Regression and Likelihood, Figure 2.4.</li><li><a href="../../../chronux_2_10/locfit/Book/fig2_5.html" class="code" title="">fig2_5</a> Local Regression and Likelihood, Figure 2.5.</li><li><a href="../../../chronux_2_10/locfit/Book/fig2_6.html" class="code" title="">fig2_6</a> Local Regression and Likelihood, Figure 2.6.</li><li><a href="../../../chronux_2_10/locfit/Book/fig3_1.html" class="code" title="">fig3_1</a> Local Regression and Likelihood, Figure 3.1.</li><li><a href="../../../chronux_2_10/locfit/Book/fig4_1.html" class="code" title="">fig4_1</a> Local Regression and Likelihood, Figure 4.1.</li><li><a href="../../../chronux_2_10/locfit/Book/fig4_2.html" class="code" title="">fig4_2</a> Local Regression and Likelihood, Figure 4.2.</li><li><a href="../../../chronux_2_10/locfit/Book/fig4_3.html" class="code" title="">fig4_3</a> Local Regression and Likelihood, Figure 4.3.</li><li><a href="../../../chronux_2_10/locfit/Book/fig5_1.html" class="code" title="">fig5_1</a> Local Regression and Likelihood, Figure 5.1.</li><li><a href="../../../chronux_2_10/locfit/Book/fig5_2.html" class="code" title="">fig5_2</a> Local Regression and Likelihood, Figure 5.2.</li><li><a href="../../../chronux_2_10/locfit/Book/fig5_3.html" class="code" title="">fig5_3</a> Local Regression and Likelihood, Figure 5.3.</li><li><a href="../../../chronux_2_10/locfit/Book/fig5_4.html" class="code" title="">fig5_4</a> Local Regression and Likelihood, Figure 5.4.</li><li><a href="../../../chronux_2_10/locfit/Book/fig5_5.html" class="code" title="">fig5_5</a> Local Regression and Likelihood, Figure 5.5.</li><li><a href="../../../chronux_2_10/locfit/Book/fig5_6.html" class="code" title="">fig5_6</a> Local Regression and Likelihood, Figure 5.6.</li><li><a href="../../../chronux_2_10/locfit/Book/fig6_1.html" class="code" title="">fig6_1</a> Local Regression and Likelihood, Figure 6.1.</li><li><a href="../../../chronux_2_10/locfit/Book/fig6_2.html" class="code" title="">fig6_2</a> Local Regression and Likelihood, Figure 6.2.</li><li><a href="../../../chronux_2_10/locfit/Book/fig6_3.html" class="code" title="">fig6_3</a> Local Regression and Likelihood, Figure 6.3.</li><li><a href="../../../chronux_2_10/locfit/Book/fig6_4.html" class="code" title="">fig6_4</a> Local Regression and Likelihood, Figure 6.4.</li><li><a href="../../../chronux_2_10/locfit/Book/fig6_5.html" class="code" title="">fig6_5</a> Local Regression and Likelihood, Figure 6.5.</li><li><a href="../../../chronux_2_10/locfit/Book/fig6_6.html" class="code" title="">fig6_6</a> Local Regression and Likelihood, Figure 6.6.</li><li><a href="../../../chronux_2_10/locfit/Book/fig6_7.html" class="code" title="">fig6_7</a> Local Regression and Likelihood, Figure 6.6.</li><li><a href="../../../chronux_2_10/locfit/Book/fig7_1.html" class="code" title="">fig7_1</a> Local Regression and Likelihood, Figure 7.1.</li><li><a href="../../../chronux_2_10/locfit/Book/fig7_2.html" class="code" title="">fig7_2</a> Local Regression and Likelihood, Figure 7.2.</li><li><a href="../../../chronux_2_10/locfit/Book/fig7_3.html" class="code" title="">fig7_3</a> Local Regression and Likelihood, Figure 7.3.</li><li><a href="../../../chronux_2_10/locfit/Book/fig7_4.html" class="code" title="">fig7_4</a> Local Regression and Likelihood, Figure 7.4.</li><li><a href="../../../chronux_2_10/locfit/Book/fig7_5.html" class="code" title="">fig7_5</a> Local Regression and Likelihood, Figure 7.5.</li><li><a href="../../../chronux_2_10/locfit/Book/fig7_6.html" class="code" title="">fig7_6</a> Local Regression and Likelihood, Figure 7.6.</li><li><a href="../../../chronux_2_10/locfit/Book/fig8_1.html" class="code" title="">fig8_1</a> Local Regression and Likelihood, Figure 8.1.</li><li><a href="../../../chronux_2_10/locfit/Book/fig8_2.html" class="code" title="">fig8_2</a> Local Regression and Likelihood, Figure 8.2.</li><li><a href="../../../chronux_2_10/locfit/Book/fig8_3.html" class="code" title="">fig8_3</a> Local Regression and Likelihood, Figure 8.3.</li><li><a href="../../../chronux_2_10/locfit/Book/fig9_2.html" class="code" title="">fig9_2</a> Local Regression and Likelihood, Figure 9.2.</li><li><a href="../../../chronux_2_10/locfit/Neuro/lfex1.html" class="code" title="">lfex1</a> Local Estimation a spike firing rate (in spikes per unit time).</li><li><a href="../../../chronux_2_10/locfit/Neuro/lfex2.html" class="code" title="">lfex2</a> Model the success probability of successive trials of a monkey</li><li><a href="aic.html" class="code" title="function g=aic(varargin)">aic</a> </li><li><a href="gcv.html" class="code" title="function g=gcv(varargin)">gcv</a> </li><li><a href="hatmatrix.html" class="code" title="function z=hatmatrix(varargin)">hatmatrix</a> </li><li><a href="kappa0.html" class="code" title="function kap=kappa0(x,y,varargin)">kappa0</a> Compute the constants for `tube-formula' based simultaneous</li><li><a href="lcv.html" class="code" title="function g=lcv(varargin)">lcv</a> </li><li><a href="lf_censor.html" class="code" title="function fit = lf_censor(x,y,cens,varargin)">lf_censor</a> </li><li><a href="lfgui.html" class="code" title="function varargout = lfgui(varargin)">lfgui</a> LFGUI M-file for lfgui.fig</li><li><a href="lfsmooth.html" class="code" title="function yhat=lfsmooth(varargin)">lfsmooth</a> </li><li><a href="locfit_all.html" class="code" title="function out=locfit_all(varargin)">locfit_all</a> Smoothing noisy data using Local Regression and Likelihood.</li><li><a href="scb.html" class="code" title="function z=scb(x,y,varargin)">scb</a> Simultaneous Confidence Bands</li><li><a href="smooth_lf.html" class="code" title="function z=smooth_lf(x,y,varargin)">smooth_lf</a> must (unlike R smooth.lf() function) give x and y.</li><li><a href="../../../chronux_2_10/spectral_analysis/helper/den_jack.html" class="code" title="function [m,ll,ul,llj,ulj]=den_jack(X,family,varargin)">den_jack</a> Function to compute smooth estimates of the mean of x using locfit,</li></ul>
  231. <!-- crossreference -->
  232. <h2><a name="_source"></a>SOURCE CODE <a href="#_top"><img alt="^" border="0" src="../../../up.png"></a></h2>
  233. <div class="fragment"><pre>0001 <a name="_sub0" href="#_subfunctions" class="code">function fit=locfit(varargin)</a>
  234. 0002
  235. 0003 <span class="comment">% Smoothing noisy data using Local Regression and Likelihood.</span>
  236. 0004 <span class="comment">%</span>
  237. 0005 <span class="comment">% arguments still to add: dc maxit</span>
  238. 0006 <span class="comment">%</span>
  239. 0007 <span class="comment">% Usage: fit = locfit(x,y) % local regression fit of x and y.</span>
  240. 0008 <span class="comment">% fit = locfit(x) % density estimation of x.</span>
  241. 0009 <span class="comment">%</span>
  242. 0010 <span class="comment">% Smoothing with locfit is a two-step procedure. The locfit()</span>
  243. 0011 <span class="comment">% function evaluates the local regression smooth at a set of points</span>
  244. 0012 <span class="comment">% (can be specified through an evaluation structure). Then, use</span>
  245. 0013 <span class="comment">% the predict() function to interpolate this fit to other points.</span>
  246. 0014 <span class="comment">%</span>
  247. 0015 <span class="comment">% Additional arguments to locfit() are specified as 'name',value pairs, e.g.:</span>
  248. 0016 <span class="comment">% locfit( x, 'alpha',[0.7,1.5] , 'family','rate' , 'ev','grid' , 'mg',100 );</span>
  249. 0017 <span class="comment">%</span>
  250. 0018 <span class="comment">%</span>
  251. 0019 <span class="comment">% Data-related inputs:</span>
  252. 0020 <span class="comment">%</span>
  253. 0021 <span class="comment">% x is a vector or matrix of the independent (or predictor) variables.</span>
  254. 0022 <span class="comment">% Rows of x represent subjects, columns represent variables.</span>
  255. 0023 <span class="comment">% Generally, local regression would be used with 1-4 independent</span>
  256. 0024 <span class="comment">% variables. In higher dimensions, the curse-of-dimensionality,</span>
  257. 0025 <span class="comment">% as well as the difficulty of visualizing higher dimensional</span>
  258. 0026 <span class="comment">% surfaces, may limit usefulness.</span>
  259. 0027 <span class="comment">%</span>
  260. 0028 <span class="comment">% y is the column vector of the dependent (or response) variable.</span>
  261. 0029 <span class="comment">% For density families, 'y' is omitted.</span>
  262. 0030 <span class="comment">% NOTE: x and y are the first two arguments. All other arguments require</span>
  263. 0031 <span class="comment">% the 'name',value notation.</span>
  264. 0032 <span class="comment">%</span>
  265. 0033 <span class="comment">% 'weights' Prior weights for observations (reciprocal of variance, or</span>
  266. 0034 <span class="comment">% sample size).</span>
  267. 0035 <span class="comment">% 'cens' Censoring indicators for hazard rate or censored regression.</span>
  268. 0036 <span class="comment">% The coding is '1' (or 'TRUE') for a censored observation, and</span>
  269. 0037 <span class="comment">% '0' (or 'FALSE') for uncensored observations.</span>
  270. 0038 <span class="comment">% 'base' Baseline parameter estimate. If a baseline is provided,</span>
  271. 0039 <span class="comment">% the local regression model is fitted as</span>
  272. 0040 <span class="comment">% Y_i = b_i + m(x_i) + epsilon_i,</span>
  273. 0041 <span class="comment">% with Locfit estimating the m(x) term. For regression models,</span>
  274. 0042 <span class="comment">% this effectively subtracts b_i from Y_i. The advantage of the</span>
  275. 0043 <span class="comment">% 'base' formulation is that it extends to likelihood</span>
  276. 0044 <span class="comment">% regression models.</span>
  277. 0045 <span class="comment">% 'scale' A scale to apply to each variable. This is especially</span>
  278. 0046 <span class="comment">% important for multivariate fitting, where variables may be</span>
  279. 0047 <span class="comment">% measured in non-comparable units. It is also used to specify</span>
  280. 0048 <span class="comment">% the frequency for variables with the 'a' (angular) style.</span>
  281. 0049 <span class="comment">% 'sty' Character string (length d) of styles for each predictor variable.</span>
  282. 0050 <span class="comment">% n denotes `normal'; a denotes angular (or periodic); l and r</span>
  283. 0051 <span class="comment">% denotes one-sided left and right; c is conditionally parametric.</span>
  284. 0052 <span class="comment">%</span>
  285. 0053 <span class="comment">%</span>
  286. 0054 <span class="comment">% Smoothing Parameters and Bandwidths:</span>
  287. 0055 <span class="comment">% The bandwidth (or more accurately, half-width) of the smoothing window</span>
  288. 0056 <span class="comment">% controls the amount of smoothing. Locfit allows specification of constant</span>
  289. 0057 <span class="comment">% (fixed), nearest neighbor, certain locally adaptive variable bandwidths,</span>
  290. 0058 <span class="comment">% and combinations of these. Also related to the smoothing parameter</span>
  291. 0059 <span class="comment">% are the local polynmial degree and weight function.</span>
  292. 0060 <span class="comment">%</span>
  293. 0061 <span class="comment">% 'nn' 'Nearest neighbor' smoothing parameter. Specifying 'nn',0.5</span>
  294. 0062 <span class="comment">% means that the width of each smoothing neighborhood is chosen</span>
  295. 0063 <span class="comment">% to cover 50% of the data.</span>
  296. 0064 <span class="comment">%</span>
  297. 0065 <span class="comment">% 'h' A constant (or fixed) bandwidth parameter. For example, 'h',2</span>
  298. 0066 <span class="comment">% means that the smoothing windows have constant half-width</span>
  299. 0067 <span class="comment">% (or radius) 2. Note that h is applied after scaling.</span>
  300. 0068 <span class="comment">%</span>
  301. 0069 <span class="comment">% 'pen' penalty parameter for adaptive smoothing. Needs to be used</span>
  302. 0070 <span class="comment">% with care.</span>
  303. 0071 <span class="comment">%</span>
  304. 0072 <span class="comment">% 'alpha' The old way of specifying smoothing parameters, as used in</span>
  305. 0073 <span class="comment">% my book. alpha is equivalent to the vector [nn,h,pen].</span>
  306. 0074 <span class="comment">% If multiple componenents are non-zero, the largest corresponding</span>
  307. 0075 <span class="comment">% bandwidth is used. The default (if none of alpha,nn,h,pen</span>
  308. 0076 <span class="comment">% are provided) is [0.7 0 0].</span>
  309. 0077 <span class="comment">%</span>
  310. 0078 <span class="comment">% 'deg' Degree of local polynomial. Default: 2 (local quadratic).</span>
  311. 0079 <span class="comment">% Degrees 0 to 3 are supported by almost all parts of the</span>
  312. 0080 <span class="comment">% Locfit code. Higher degrees may work in some cases.</span>
  313. 0081 <span class="comment">%</span>
  314. 0082 <span class="comment">% 'kern' Weight function, default = 'tcub'. Other choices are</span>
  315. 0083 <span class="comment">% 'rect', 'trwt', 'tria', 'epan', 'bisq' and 'gauss'.</span>
  316. 0084 <span class="comment">% Choices may be restricted when derivatives are</span>
  317. 0085 <span class="comment">% required; e.g. for confidence bands and some bandwidth</span>
  318. 0086 <span class="comment">% selectors.</span>
  319. 0087 <span class="comment">%</span>
  320. 0088 <span class="comment">% 'kt' Kernel type, 'sph' (default); 'prod'. In multivariate</span>
  321. 0089 <span class="comment">% problems, 'prod' uses a simplified product model which</span>
  322. 0090 <span class="comment">% speeds up computations.</span>
  323. 0091 <span class="comment">%</span>
  324. 0092 <span class="comment">% 'acri' Criterion for adaptive bandwidth selection.</span>
  325. 0093 <span class="comment">%</span>
  326. 0094 <span class="comment">%</span>
  327. 0095 <span class="comment">% Derivative Estimation.</span>
  328. 0096 <span class="comment">% Generally I recommend caution when using derivative estimation</span>
  329. 0097 <span class="comment">% (and especially higher order derivative estimation) -- can you</span>
  330. 0098 <span class="comment">% really estimate derivatives from noisy data? Any derivative</span>
  331. 0099 <span class="comment">% estimate is inherently more dependent on an assumed smoothness</span>
  332. 0100 <span class="comment">% (expressed through the bandwidth) than the data. Warnings aside...</span>
  333. 0101 <span class="comment">%</span>
  334. 0102 <span class="comment">% 'deriv' Derivative estimation. 'deriv',1 specifies the first derivative</span>
  335. 0103 <span class="comment">% (or more correctly, an estimate of the local slope is returned.</span>
  336. 0104 <span class="comment">% 'deriv',[1 1] specifies the second derivative. For bivariate fits</span>
  337. 0105 <span class="comment">% 'deriv',2 specifies the first partial derivative wrt x2.</span>
  338. 0106 <span class="comment">% 'deriv',[1 2] is mixed second-order derivative.</span>
  339. 0107 <span class="comment">%</span>
  340. 0108 <span class="comment">% Fitting family.</span>
  341. 0109 <span class="comment">% 'family' is used to specify the local likelihood family.</span>
  342. 0110 <span class="comment">% Regression-type families are 'gaussian', 'binomial',</span>
  343. 0111 <span class="comment">% 'poisson', 'gamma' and 'geom'. If the family is preceded</span>
  344. 0112 <span class="comment">% by a q (e.g. 'qgauss', or 'qpois') then quasi-likelihood is</span>
  345. 0113 <span class="comment">% used; in particular, a dispersion estimate is computed.</span>
  346. 0114 <span class="comment">% Preceding by an 'r' makes an attempt at robust (outlier-resistant)</span>
  347. 0115 <span class="comment">% estimation. Combining q and r (e.g. 'family','qrpois') may</span>
  348. 0116 <span class="comment">% work, if you're lucky.</span>
  349. 0117 <span class="comment">% Density estimation-type families are 'dens', 'rate' and 'hazard'</span>
  350. 0118 <span class="comment">% (hazard or failure rate). Note that `dens' scales the output</span>
  351. 0119 <span class="comment">% to be a statistical density estimate (i.e. scaled to integrate</span>
  352. 0120 <span class="comment">% to 1). 'rate' estimates the rate or intensity function (events</span>
  353. 0121 <span class="comment">% per unit time, or events per unit area), which may be called</span>
  354. 0122 <span class="comment">% density in some fields.</span>
  355. 0123 <span class="comment">% The default family is 'qgauss' if a response (y argument) has been</span>
  356. 0124 <span class="comment">% provided, and 'dens' if no response is given.</span>
  357. 0125 <span class="comment">% 'link' Link function for local likelihood fitting. Depending on the</span>
  358. 0126 <span class="comment">% family, choices may be 'ident', 'log', 'logit',</span>
  359. 0127 <span class="comment">% 'inverse', 'sqrt' and 'arcsin'.</span>
  360. 0128 <span class="comment">%</span>
  361. 0129 <span class="comment">% Evaluation structures.</span>
  362. 0130 <span class="comment">% By default, locfit chooses a set of points, depending on the data</span>
  363. 0131 <span class="comment">% and smoothing parameters, to evaluate at. This is controlled by</span>
  364. 0132 <span class="comment">% the evaluation structure.</span>
  365. 0133 <span class="comment">% 'ev' Specify the evaluation structure. Default is 'tree'.</span>
  366. 0134 <span class="comment">% Other choices include 'phull' (triangulation), 'grid' (a grid</span>
  367. 0135 <span class="comment">% of points), 'data' (each data point), 'crossval' (data,</span>
  368. 0136 <span class="comment">% but use leave-one-out cross validation), 'none' (no evaluation</span>
  369. 0137 <span class="comment">% points, effectively producing the global parametric fit).</span>
  370. 0138 <span class="comment">% Alternatively, a vector/matrix of evaluation points may be</span>
  371. 0139 <span class="comment">% provided.</span>
  372. 0140 <span class="comment">% (kd trees not currently supported in mlocfit)</span>
  373. 0141 <span class="comment">% 'll' and 'ur' -- row vectors specifying the upper and lower limits</span>
  374. 0142 <span class="comment">% for the bounding box used by the evaluation structure.</span>
  375. 0143 <span class="comment">% They default to the data range.</span>
  376. 0144 <span class="comment">% 'mg' For the 'grid' evaluation structure, 'mg' specifies the</span>
  377. 0145 <span class="comment">% number of points on each margin. Default 10. Can be either a</span>
  378. 0146 <span class="comment">% single number or vector.</span>
  379. 0147 <span class="comment">% 'cut' Refinement parameter for adaptive partitions. Default 0.8;</span>
  380. 0148 <span class="comment">% smaller values result in more refined partitions.</span>
  381. 0149 <span class="comment">% 'maxk' Controls space assignment for evaluation structures. For the</span>
  382. 0150 <span class="comment">% adaptive evaluation structures, it is impossible to be sure</span>
  383. 0151 <span class="comment">% in advance how many vertices will be generated. If you get</span>
  384. 0152 <span class="comment">% warnings about `Insufficient vertex space', Locfit's default</span>
  385. 0153 <span class="comment">% assigment can be increased by increasing 'maxk'. The default</span>
  386. 0154 <span class="comment">% is 'maxk','100'.</span>
  387. 0155 <span class="comment">%</span>
  388. 0156 <span class="comment">% 'xlim' For density estimation, Locfit allows the density to be</span>
  389. 0157 <span class="comment">% supported on a bounded interval (or rectangle, in more than</span>
  390. 0158 <span class="comment">% one dimension). The format should be [ll;ul] (ie, matrix with</span>
  391. 0159 <span class="comment">% two rows, d columns) where ll is the lower left corner of</span>
  392. 0160 <span class="comment">% the rectangle, and ur is the upper right corner.</span>
  393. 0161 <span class="comment">% One-sided bounds, such as [0,infty), are not supported, but can be</span>
  394. 0162 <span class="comment">% effectively specified by specifying a very large upper</span>
  395. 0163 <span class="comment">% bound.</span>
  396. 0164 <span class="comment">%</span>
  397. 0165 <span class="comment">% 'module' either 'name' or {'name','/path/to/module',parameters}.</span>
  398. 0166 <span class="comment">%</span>
  399. 0167 <span class="comment">% Density Estimation</span>
  400. 0168 <span class="comment">% 'renorm',1 will attempt to renormalize the local likelihood</span>
  401. 0169 <span class="comment">% density estimate so that it integrates to 1. The llde</span>
  402. 0170 <span class="comment">% (specified by 'family','dens') is scaled to estimate the</span>
  403. 0171 <span class="comment">% density, but since the estimation is pointwise, there is</span>
  404. 0172 <span class="comment">% no guarantee that the resulting density integrates exactly</span>
  405. 0173 <span class="comment">% to 1. Renormalization attempts to achieve this.</span>
  406. 0174 <span class="comment">%</span>
  407. 0175 <span class="comment">% The output of locfit() is a Matlab structure:</span>
  408. 0176 <span class="comment">%</span>
  409. 0177 <span class="comment">% fit.data.x (n*d)</span>
  410. 0178 <span class="comment">% fit.data.y (n*1)</span>
  411. 0179 <span class="comment">% fit.data.weights (n*1 or 1*1)</span>
  412. 0180 <span class="comment">% fit.data.censor (n*1 or 1*1)</span>
  413. 0181 <span class="comment">% fit.data.baseline (n*1 or 1*1)</span>
  414. 0182 <span class="comment">% fit.data.style (string length d)</span>
  415. 0183 <span class="comment">% fit.data.scales (1*d)</span>
  416. 0184 <span class="comment">% fit.data.xlim (2*d)</span>
  417. 0185 <span class="comment">%</span>
  418. 0186 <span class="comment">% fit.evaluation_structure.type (string)</span>
  419. 0187 <span class="comment">% fit.evaluation_structure.module.name (string)</span>
  420. 0188 <span class="comment">% fit.evaluation_structure.module.directory (string)</span>
  421. 0189 <span class="comment">% fit.evaluation_structure.module.parameters (string)</span>
  422. 0190 <span class="comment">% fit.evaluation_structure.lower_left (numeric 1*d)</span>
  423. 0191 <span class="comment">% fit.evaluation_structure.upper_right (numeric 1*d)</span>
  424. 0192 <span class="comment">% fit.evaluation_structure.grid (numeric 1*d)</span>
  425. 0193 <span class="comment">% fit.evaluation_structure.cut (numeric 1*d)</span>
  426. 0194 <span class="comment">% fit.evaluation_structure.maxk</span>
  427. 0195 <span class="comment">% fit.evaluation_structure.derivative</span>
  428. 0196 <span class="comment">%</span>
  429. 0197 <span class="comment">% fit.smoothing_parameters.alpha = (nn h pen) vector</span>
  430. 0198 <span class="comment">% fit.smoothing_parameters.adaptive_criterion (string)</span>
  431. 0199 <span class="comment">% fit.smoothing_parameters.degree (numeric)</span>
  432. 0200 <span class="comment">% fit.smoothing_parameters.family (string)</span>
  433. 0201 <span class="comment">% fit.smoothing_parameters.link (string)</span>
  434. 0202 <span class="comment">% fit.smoothing_parameters.kernel (string)</span>
  435. 0203 <span class="comment">% fit.smoothing_parameters.kernel_type (string)</span>
  436. 0204 <span class="comment">% fit.smoothing_parameters.deren</span>
  437. 0205 <span class="comment">% fit.smoothing_parameters.deit</span>
  438. 0206 <span class="comment">% fit.smoothing_parameters.demint</span>
  439. 0207 <span class="comment">% fit.smoothing_parameters.debug</span>
  440. 0208 <span class="comment">%</span>
  441. 0209 <span class="comment">% fit.fit_points.evaluation_points (d*nv matrix)</span>
  442. 0210 <span class="comment">% fit.fit_points.fitted_values (matrix, nv rows, many columns)</span>
  443. 0211 <span class="comment">% fit.fit_points.evaluation_vectors.cell</span>
  444. 0212 <span class="comment">% fit.fit_points.evaluation_vectors.splitvar</span>
  445. 0213 <span class="comment">% fit.fit_points.evaluation_vectors.lo</span>
  446. 0214 <span class="comment">% fit.fit_points.evaluation_vectors.hi</span>
  447. 0215 <span class="comment">% fit.fit_points.fit_limits (d*2 matrix)</span>
  448. 0216 <span class="comment">% fit.fit_points.family_link (numeric values)</span>
  449. 0217 <span class="comment">% fit.fit_points.kappa (likelihood, degrees of freedom, etc)</span>
  450. 0218 <span class="comment">%</span>
  451. 0219 <span class="comment">% fit.parametric_component</span>
  452. 0220 <span class="comment">%</span>
  453. 0221 <span class="comment">%</span>
  454. 0222 <span class="comment">% The OLD format:</span>
  455. 0223 <span class="comment">%</span>
  456. 0224 <span class="comment">% fit{1} = data.</span>
  457. 0225 <span class="comment">% fit{2} = evaluation structure.</span>
  458. 0226 <span class="comment">% fit{3} = smoothing parameter structure.</span>
  459. 0227 <span class="comment">% fit{4}{1} = fit points matrix.</span>
  460. 0228 <span class="comment">% fit{4}{2} = matrix of fitted values etc.</span>
  461. 0229 <span class="comment">% Note that these are not back-transformed, and may have the</span>
  462. 0230 <span class="comment">% parametric component removed.</span>
  463. 0231 <span class="comment">% (exact content varies according to module).</span>
  464. 0232 <span class="comment">% fit{4}{3} = various details of the evaluation points.</span>
  465. 0233 <span class="comment">% fit{4}{4} = fit limits.</span>
  466. 0234 <span class="comment">% fit{4}{5} = family,link.</span>
  467. 0235 <span class="comment">% fit{5} = parametric component values.</span>
  468. 0236 <span class="comment">%</span>
  469. 0237
  470. 0238
  471. 0239
  472. 0240 <span class="comment">% Minimal input validation</span>
  473. 0241 <span class="keyword">if</span> nargin &lt; 1
  474. 0242 error( <span class="string">'At least one input argument required'</span> );
  475. 0243 <span class="keyword">end</span>
  476. 0244
  477. 0245 xdata = double(varargin{1});
  478. 0246 d = size(xdata,2);
  479. 0247 n = size(xdata,1);
  480. 0248 <span class="keyword">if</span> ((nargin&gt;1) &amp;&amp; (~ischar(varargin{2})))
  481. 0249 ydata = double(varargin{2});
  482. 0250 <span class="keyword">if</span> (any(size(ydata) ~= [n 1])); error(<span class="string">'y must be n*1 column vector'</span>); <span class="keyword">end</span>;
  483. 0251 family = <span class="string">'qgauss'</span>;
  484. 0252 na = 3;
  485. 0253 <span class="keyword">else</span>
  486. 0254 ydata = 0;
  487. 0255 family = <span class="string">'density'</span>;
  488. 0256 na = 2;
  489. 0257 <span class="keyword">end</span>;
  490. 0258 <span class="keyword">if</span> mod(nargin-na,2)==0
  491. 0259 error( <span class="string">'All arguments other than x, y must be name,value pairs'</span> );
  492. 0260 <span class="keyword">end</span>
  493. 0261
  494. 0262
  495. 0263 wdata = ones(n,1);
  496. 0264 cdata = 0;
  497. 0265 base = 0;
  498. 0266 style = <span class="string">'n'</span>;
  499. 0267 scale = 1;
  500. 0268 xl = zeros(2,d);
  501. 0269
  502. 0270 alpha = [0 0 0];
  503. 0271 deg = 2;
  504. 0272 link = <span class="string">'default'</span>;
  505. 0273 acri = <span class="string">'none'</span>;
  506. 0274 kern = <span class="string">'tcub'</span>;
  507. 0275 kt = <span class="string">'sph'</span>;
  508. 0276 deren = 0;
  509. 0277 deit = <span class="string">'default'</span>;
  510. 0278 demint= 20;
  511. 0279 debug = 0;
  512. 0280
  513. 0281 ev = <span class="string">'tree'</span>;
  514. 0282 ll = zeros(1,d);
  515. 0283 ur = zeros(1,d);
  516. 0284 mg = 10;
  517. 0285 maxk = 100;
  518. 0286 deriv=0;
  519. 0287 cut = 0.8;
  520. 0288 mdl = struct(<span class="string">'name'</span>,<span class="string">'std'</span>, <span class="string">'directory'</span>,<span class="string">''</span>, <span class="string">'parameters'</span>,0 );
  521. 0289
  522. 0290 <span class="keyword">while</span> na &lt; length(varargin)
  523. 0291 inc = 0;
  524. 0292 <span class="keyword">if</span> (varargin{na}==<span class="string">'y'</span>)
  525. 0293 ydata = double(varargin{na+1});
  526. 0294 family = <span class="string">'qgauss'</span>;
  527. 0295 inc = 2;
  528. 0296 <span class="keyword">if</span> (any(size(ydata) ~= [n 1])); error(<span class="string">'y must be n*1 column vector'</span>); <span class="keyword">end</span>;
  529. 0297 <span class="keyword">end</span>
  530. 0298 <span class="keyword">if</span> (strcmp(varargin{na},<span class="string">'weights'</span>))
  531. 0299 wdata = double(varargin{na+1});
  532. 0300 inc = 2;
  533. 0301 <span class="keyword">if</span> (any(size(wdata) ~= [n 1])); error(<span class="string">'weights must be n*1 column vector'</span>); <span class="keyword">end</span>;
  534. 0302 <span class="keyword">end</span>
  535. 0303 <span class="keyword">if</span> (strcmp(varargin{na},<span class="string">'cens'</span>))
  536. 0304 cdata = double(varargin{na+1});
  537. 0305 inc = 2;
  538. 0306 <span class="keyword">if</span> (any(size(cdata) ~= [n 1])); error(<span class="string">'cens must be n*1 column vector'</span>); <span class="keyword">end</span>;
  539. 0307 <span class="keyword">end</span>
  540. 0308 <span class="keyword">if</span> (strcmp(varargin{na},<span class="string">'base'</span>)) <span class="comment">% numeric vector, n*1 or 1*1.</span>
  541. 0309 base = double(varargin{na+1});
  542. 0310 <span class="keyword">if</span> (length(base)==1); base = base*ones(n,1); <span class="keyword">end</span>;
  543. 0311 inc = 2;
  544. 0312 <span class="keyword">end</span>
  545. 0313 <span class="keyword">if</span> (strcmp(varargin{na},<span class="string">'style'</span>)) <span class="comment">% character string of length d.</span>
  546. 0314 style = varargin{na+1};
  547. 0315 inc = 2;
  548. 0316 <span class="keyword">end</span>;
  549. 0317 <span class="keyword">if</span> (strcmp(varargin{na},<span class="string">'scale'</span>)) <span class="comment">% row vector, length 1 or d.</span>
  550. 0318 scale = varargin{na+1};
  551. 0319 <span class="keyword">if</span> (scale==0)
  552. 0320 scale = zeros(1,d);
  553. 0321 <span class="keyword">for</span> i=1:d
  554. 0322 scale(i) = sqrt(var(xdata(:,i)));
  555. 0323 <span class="keyword">end</span>;
  556. 0324 <span class="keyword">end</span>;
  557. 0325 inc = 2;
  558. 0326 <span class="keyword">end</span>;
  559. 0327 <span class="keyword">if</span> (strcmp(varargin{na},<span class="string">'xlim'</span>)) <span class="comment">% 2*d numeric matrix.</span>
  560. 0328 xl = varargin{na+1};
  561. 0329 inc = 2;
  562. 0330 <span class="keyword">end</span>
  563. 0331 <span class="keyword">if</span> (strcmp(varargin{na},<span class="string">'alpha'</span>)) <span class="comment">% row vector of length 1, 2 or 3.</span>
  564. 0332 alpha = [varargin{na+1} 0 0 0];
  565. 0333 alpha = alpha(1:3);
  566. 0334 inc = 2;
  567. 0335 <span class="keyword">end</span>
  568. 0336 <span class="keyword">if</span> (strcmp(varargin{na},<span class="string">'nn'</span>)) <span class="comment">% scalar</span>
  569. 0337 alpha(1) = varargin{na+1};
  570. 0338 inc = 2;
  571. 0339 <span class="keyword">end</span>
  572. 0340 <span class="keyword">if</span> (strcmp(varargin{na},<span class="string">'h'</span>)) <span class="comment">% scalar</span>
  573. 0341 alpha(2) = varargin{na+1};
  574. 0342 inc = 2;
  575. 0343 <span class="keyword">end</span>;
  576. 0344 <span class="keyword">if</span> (strcmp(varargin{na},<span class="string">'pen'</span>)) <span class="comment">% scalar</span>
  577. 0345 alpha(3) = varargin{na+1};
  578. 0346 inc = 2;
  579. 0347 <span class="keyword">end</span>;
  580. 0348 <span class="keyword">if</span> (strcmp(varargin{na},<span class="string">'acri'</span>)) <span class="comment">% string</span>
  581. 0349 acri = varargin{na+1};
  582. 0350 inc = 2;
  583. 0351 <span class="keyword">end</span>
  584. 0352 <span class="keyword">if</span> (strcmp(varargin{na},<span class="string">'deg'</span>)) <span class="comment">% positive integer.</span>
  585. 0353 deg = varargin{na+1};
  586. 0354 inc = 2;
  587. 0355 <span class="keyword">end</span>;
  588. 0356 <span class="keyword">if</span> (strcmp(varargin{na},<span class="string">'family'</span>)) <span class="comment">% character string.</span>
  589. 0357 family = varargin{na+1};
  590. 0358 inc = 2;
  591. 0359 <span class="keyword">end</span>;
  592. 0360 <span class="keyword">if</span> (strcmp(varargin{na},<span class="string">'link'</span>)) <span class="comment">% character string.</span>
  593. 0361 link = varargin{na+1};
  594. 0362 inc = 2;
  595. 0363 <span class="keyword">end</span>;
  596. 0364 <span class="keyword">if</span> (strcmp(varargin{na},<span class="string">'kern'</span>)) <span class="comment">% character string.</span>
  597. 0365 kern = varargin{na+1};
  598. 0366 inc = 2;
  599. 0367 <span class="keyword">end</span>;
  600. 0368 <span class="keyword">if</span> (strcmp(varargin{na},<span class="string">'kt'</span>)) <span class="comment">% character string.</span>
  601. 0369 kt = varargin{na+1};
  602. 0370 inc = 2;
  603. 0371 <span class="keyword">end</span>;
  604. 0372 <span class="keyword">if</span> (strcmp(varargin{na},<span class="string">'ev'</span>)) <span class="comment">% char. string, or matrix with d columns.</span>
  605. 0373 ev = varargin{na+1};
  606. 0374 <span class="keyword">if</span> (isnumeric(ev)); ev = ev'; <span class="keyword">end</span>;
  607. 0375 inc = 2;
  608. 0376 <span class="keyword">end</span>;
  609. 0377 <span class="keyword">if</span> (strcmp(varargin{na},<span class="string">'ll'</span>)) <span class="comment">% row vector of length d.</span>
  610. 0378 ll = varargin{na+1};
  611. 0379 inc = 2;
  612. 0380 <span class="keyword">end</span>;
  613. 0381 <span class="keyword">if</span> (strcmp(varargin{na},<span class="string">'ur'</span>)) <span class="comment">% row vector of length d.</span>
  614. 0382 ur = varargin{na+1};
  615. 0383 inc = 2;
  616. 0384 <span class="keyword">end</span>;
  617. 0385 <span class="keyword">if</span> (strcmp(varargin{na},<span class="string">'mg'</span>)) <span class="comment">% row vector of length d.</span>
  618. 0386 mg = varargin{na+1};
  619. 0387 inc = 2;
  620. 0388 <span class="keyword">end</span>;
  621. 0389 <span class="keyword">if</span> (strcmp(varargin{na},<span class="string">'cut'</span>)) <span class="comment">% positive scalar.</span>
  622. 0390 cut = varargin{na+1};
  623. 0391 inc = 2;
  624. 0392 <span class="keyword">end</span>;
  625. 0393 <span class="keyword">if</span> (strcmp(varargin{na},<span class="string">'module'</span>)) <span class="comment">% string.</span>
  626. 0394 mdl = struct(<span class="string">'name'</span>,varargin{na+1}, <span class="string">'directory'</span>,<span class="string">''</span>, <span class="string">'parameters'</span>,0 );
  627. 0395 inc = 2;
  628. 0396 <span class="keyword">end</span>;
  629. 0397 <span class="keyword">if</span> (strcmp(varargin{na},<span class="string">'maxk'</span>)) <span class="comment">% positive integer.</span>
  630. 0398 maxk = varargin{na+1};
  631. 0399 inc = 2;
  632. 0400 <span class="keyword">end</span>;
  633. 0401 <span class="keyword">if</span> (strcmp(varargin{na},<span class="string">'deriv'</span>)) <span class="comment">% numeric row vector, up to deg elements.</span>
  634. 0402 deriv = varargin{na+1};
  635. 0403 inc = 2;
  636. 0404 <span class="keyword">end</span>;
  637. 0405 <span class="keyword">if</span> (strcmp(varargin{na},<span class="string">'renorm'</span>)) <span class="comment">% density renormalization.</span>
  638. 0406 deren = varargin{na+1};
  639. 0407 inc = 2;
  640. 0408 <span class="keyword">end</span>;
  641. 0409 <span class="keyword">if</span> (strcmp(varargin{na},<span class="string">'itype'</span>)) <span class="comment">% density - integration type.</span>
  642. 0410 deit = varargin{na+1};
  643. 0411 inc = 2;
  644. 0412 <span class="keyword">end</span>;
  645. 0413 <span class="keyword">if</span> (strcmp(varargin{na},<span class="string">'mint'</span>)) <span class="comment">% density - # of integration points.</span>
  646. 0414 demint = varargin{na+1};
  647. 0415 inc = 2;
  648. 0416 <span class="keyword">end</span>;
  649. 0417 <span class="keyword">if</span> (strcmp(varargin{na},<span class="string">'debug'</span>)) <span class="comment">% debug level.</span>
  650. 0418 debug = varargin{na+1};
  651. 0419 inc = 2;
  652. 0420 <span class="keyword">end</span>;
  653. 0421 <span class="keyword">if</span> (inc==0)
  654. 0422 disp(varargin{na});
  655. 0423 error(<span class="string">'Unknown Input Argument.'</span>);
  656. 0424 <span class="keyword">end</span>;
  657. 0425 na=na+inc;
  658. 0426 <span class="keyword">end</span>
  659. 0427
  660. 0428
  661. 0429 fit.data.x = xdata;
  662. 0430 fit.data.y = ydata;
  663. 0431 fit.data.weights = wdata;
  664. 0432 fit.data.censor = cdata;
  665. 0433 fit.data.baseline = base;
  666. 0434 fit.data.style = style;
  667. 0435 fit.data.scales = scale;
  668. 0436 fit.data.xlim = xl;
  669. 0437
  670. 0438 fit.evaluation_structure.type = ev;
  671. 0439 fit.evaluation_structure.module = mdl;
  672. 0440 fit.evaluation_structure.lower_left = ll;
  673. 0441 fit.evaluation_structure.upper_right = ur;
  674. 0442 fit.evaluation_structure.grid = mg;
  675. 0443 fit.evaluation_structure.cut = cut;
  676. 0444 fit.evaluation_structure.maxk = maxk;
  677. 0445 fit.evaluation_structure.derivative = deriv;
  678. 0446
  679. 0447 <span class="keyword">if</span> (alpha==0); alpha = [0.7 0 0]; <span class="keyword">end</span>;
  680. 0448
  681. 0449 fit.smoothing_parameters.alpha = alpha;
  682. 0450 fit.smoothing_parameters.adaptive_criterion = acri;
  683. 0451 fit.smoothing_parameters.degree = deg;
  684. 0452 fit.smoothing_parameters.family = family;
  685. 0453 fit.smoothing_parameters.link = link;
  686. 0454 fit.smoothing_parameters.kernel = kern;
  687. 0455 fit.smoothing_parameters.kernel_type = kt;
  688. 0456 fit.smoothing_parameters.deren = deren;
  689. 0457 fit.smoothing_parameters.deit = deit;
  690. 0458 fit.smoothing_parameters.demint = demint;
  691. 0459 fit.smoothing_parameters.debug = debug;
  692. 0460
  693. 0461 [fpc pcomp] = mexlf(fit.data,fit.evaluation_structure,fit.smoothing_parameters);
  694. 0462 fit.fit_points = fpc;
  695. 0463 fit.parametric_component = pcomp;
  696. 0464
  697. 0465 <span class="keyword">return</span>
  698. 0466
  699. 0467
  700. 0468</pre></div>
  701. <hr><address>Generated on Fri 12-Aug-2011 11:36:15 by <strong><a href="http://www.artefact.tk/software/matlab/m2html/" target="_parent">m2html</a></strong> &copy; 2005</address>
  702. </body>
  703. </html>