Home > chronux > locfit > m > locfit.m

locfit

PURPOSE ^

Smoothing noisy data using Local Regression and Likelihood.

SYNOPSIS ^

function fit=locfit(varargin)

DESCRIPTION ^

 Smoothing noisy data using Local Regression and Likelihood.

 arguments still to add: dc maxit

  Usage: fit = locfit(x,y)   % local regression fit of x and y.
         fit = locfit(x)     % density estimation of x.

  Smoothing with locfit is a two-step procedure. The locfit()
  function evaluates the local regression smooth at a set of points
  (can be specified through an evaluation structure). Then, use
  the predict() function to interpolate this fit to other points.

  Additional arguments to locfit() are specified as 'name',value pairs, e.g.:
  locfit( x, 'alpha',[0.7,1.5] , 'family','rate' , 'ev','grid' , 'mg',100 ); 


  Data-related inputs:

    x is a vector or matrix of the independent (or predictor) variables.
      Rows of x represent subjects, columns represent variables.
      Generally, local regression would be used with 1-4 independent
      variables. In higher dimensions, the curse-of-dimensionality,
      as well as the difficulty of visualizing higher dimensional
      surfaces, may limit usefulness.

    y is the column vector of the dependent (or response) variable.
      For density families, 'y' is omitted. 
 NOTE: x and y are the first two arguments. All other arguments require
        the 'name',value notation.

    'weights' Prior weights for observations (reciprocal of variance, or
           sample size). 
    'cens' Censoring indicators for hazard rate or censored regression.
           The coding is '1' (or 'TRUE') for a censored observation, and
           '0' (or 'FALSE') for uncensored observations. 
    'base' Baseline parameter estimate. If a baseline is provided,
           the local regression model is fitted as
                        Y_i = b_i + m(x_i) + epsilon_i,
           with Locfit estimating the m(x) term. For regression models,
           this effectively subtracts b_i from Y_i. The advantage of the
           'base' formulation is that it extends to likelihood
           regression models. 
    'scale' A scale to apply to each variable. This is especially
           important for multivariate fitting, where variables may be
           measured in non-comparable units. It is also used to specify
           the frequency for variables with the 'a' (angular) style.
     'sty' Character string (length d) of styles for each predictor variable.
           n denotes `normal'; a denotes angular (or periodic); l and r
           denotes one-sided left and right; c is conditionally parametric.
 

  Smoothing Parameters and Bandwidths:
  The bandwidth (or more accurately, half-width) of the smoothing window
  controls the amount of smoothing. Locfit allows specification of constant
  (fixed), nearest neighbor, certain locally adaptive variable bandwidths,
  and combinations of these. Also related to the smoothing parameter
  are the local polynmial degree and weight function.

    'nn' 'Nearest neighbor' smoothing parameter. Specifying 'nn',0.5
         means that the width of each smoothing neighborhood is chosen
         to cover 50% of the data.

     'h' A constant (or fixed) bandwidth parameter. For example, 'h',2
         means that the smoothing windows have constant half-width
         (or radius) 2. Note that h is applied after scaling.

   'pen' penalty parameter for adaptive smoothing. Needs to be used
         with care.

  'alpha' The old way of specifying smoothing parameters, as used in
         my book. alpha is equivalent to the vector [nn,h,pen].
         If multiple componenents are non-zero, the largest corresponding
         bandwidth is used. The default (if none of alpha,nn,h,pen
         are provided) is [0.7 0 0].

   'deg' Degree of local polynomial. Default: 2 (local quadratic).
         Degrees 0 to 3 are supported by almost all parts of the
         Locfit code. Higher degrees may work in some cases. 
 
  'kern' Weight function, default = 'tcub'. Other choices are
         'rect', 'trwt', 'tria', 'epan', 'bisq' and 'gauss'.
         Choices may be restricted when derivatives are
         required; e.g. for confidence bands and some bandwidth
         selectors. 
 
    'kt' Kernel type, 'sph' (default); 'prod'. In multivariate
         problems, 'prod' uses a simplified product model which
         speeds up computations. 
 
  'acri' Criterion for adaptive bandwidth selection.
 

  Derivative Estimation.
  Generally I recommend caution when using derivative estimation
  (and especially higher order derivative estimation) -- can you
  really estimate derivatives from noisy data? Any derivative
  estimate is inherently more dependent on an assumed smoothness
  (expressed through the bandwidth) than the data. Warnings aside...

  'deriv' Derivative estimation. 'deriv',1 specifies the first derivative
         (or more correctly, an estimate of the local slope is returned.
         'deriv',[1 1] specifies the second derivative. For bivariate fits
         'deriv',2 specifies the first partial derivative wrt x2.
         'deriv',[1 2] is mixed second-order derivative.
 
  Fitting family.
  'family' is used to specify the local likelihood family.
         Regression-type families are 'gaussian', 'binomial',
           'poisson', 'gamma' and 'geom'. If the family is preceded
           by a q (e.g. 'qgauss', or 'qpois') then quasi-likelihood is
           used; in particular, a dispersion estimate is computed.
           Preceding by an 'r' makes an attempt at robust (outlier-resistant)
           estimation. Combining q and r (e.g. 'family','qrpois') may
           work, if you're lucky.
         Density estimation-type families are 'dens', 'rate' and 'hazard'
           (hazard or failure rate). Note that `dens' scales the output
           to be a statistical density estimate (i.e. scaled to integrate
           to 1). 'rate' estimates the rate or intensity function (events
           per unit time, or events per unit area), which may be called
           density in some fields.
         The default family is 'qgauss' if a response (y argument) has been
         provided, and 'dens' if no response is given.
    'link' Link function for local likelihood fitting. Depending on the
           family, choices may be 'ident', 'log', 'logit',
           'inverse', 'sqrt' and 'arcsin'. 
 
  Evaluation structures.
    By default, locfit chooses a set of points, depending on the data
    and smoothing parameters, to evaluate at. This is controlled by
    the evaluation structure.
      'ev' Specify the evaluation structure. Default is 'tree'.
           Other choices include 'phull' (triangulation), 'grid' (a grid
           of points), 'data' (each data point), 'crossval' (data,
           but use leave-one-out cross validation), 'none' (no evaluation
           points, effectively producing the global parametric fit).
           Alternatively, a vector/matrix of evaluation points may be
           provided. 
           (kd trees not currently supported in mlocfit)
     'll' and 'ur' -- row vectors specifying the upper and lower limits
           for the bounding box used by the evaluation structure.
           They default to the data range. 
     'mg' For the 'grid' evaluation structure, 'mg' specifies the
           number of points on each margin. Default 10. Can be either a
           single number or vector. 
    'cut' Refinement parameter for adaptive partitions. Default 0.8;
           smaller values result in more refined partitions. 
    'maxk' Controls space assignment for evaluation structures. For the
           adaptive evaluation structures, it is impossible to be sure
           in advance how many vertices will be generated. If you get
           warnings about `Insufficient vertex space', Locfit's default
           assigment can be increased by increasing 'maxk'. The default
           is 'maxk','100'. 

    'xlim' For density estimation, Locfit allows the density to be
           supported on a bounded interval (or rectangle, in more than
           one dimension). The format should be [ll;ul] (ie, matrix with
           two rows, d columns) where ll is the lower left corner of
           the rectangle, and ur is the upper right corner.
           One-sided bounds, such as [0,infty), are not supported, but can be
           effectively specified by specifying a very large upper
           bound. 
 
      'module' either 'name' or {'name','/path/to/module',parameters}.
 
  Density Estimation
      'renorm',1  will attempt to renormalize the local likelihood
           density estimate so that it integrates to 1. The llde
           (specified by 'family','dens') is scaled to estimate the
           density, but since the estimation is pointwise, there is
           no guarantee that the resulting density integrates exactly
           to 1. Renormalization attempts to achieve this.

  The output of locfit() is a Matlab structure:

 fit.data.x (n*d)
 fit.data.y (n*1)
 fit.data.weights (n*1 or 1*1)
 fit.data.censor (n*1 or 1*1)
 fit.data.baseline (n*1 or 1*1)
 fit.data.style (string length d)
 fit.data.scales (1*d)
 fit.data.xlim (2*d)

 fit.evaluation_structure.type (string)
 fit.evaluation_structure.module.name (string)
 fit.evaluation_structure.module.directory (string)
 fit.evaluation_structure.module.parameters (string)
 fit.evaluation_structure.lower_left (numeric 1*d)
 fit.evaluation_structure.upper_right (numeric 1*d)
 fit.evaluation_structure.grid (numeric 1*d)
 fit.evaluation_structure.cut (numeric 1*d)
 fit.evaluation_structure.maxk
 fit.evaluation_structure.derivative

 fit.smoothing_parameters.alpha = (nn h pen) vector
 fit.smoothing_parameters.adaptive_criterion (string)
 fit.smoothing_parameters.degree (numeric)
 fit.smoothing_parameters.family (string)
 fit.smoothing_parameters.link (string)
 fit.smoothing_parameters.kernel (string)
 fit.smoothing_parameters.kernel_type (string)
 fit.smoothing_parameters.deren 
 fit.smoothing_parameters.deit
 fit.smoothing_parameters.demint
 fit.smoothing_parameters.debug

 fit.fit_points.evaluation_points (d*nv matrix)
 fit.fit_points.fitted_values (matrix, nv rows, many columns)
 fit.fit_points.evaluation_vectors.cell
 fit.fit_points.evaluation_vectors.splitvar
 fit.fit_points.evaluation_vectors.lo
 fit.fit_points.evaluation_vectors.hi
 fit.fit_points.fit_limits (d*2 matrix)
 fit.fit_points.family_link (numeric values)
 fit.fit_points.kappa (likelihood, degrees of freedom, etc)

 fit.parametric_component


  The OLD format:

    fit{1} = data.
    fit{2} = evaluation structure.
    fit{3} = smoothing parameter structure.
    fit{4}{1} = fit points matrix.
    fit{4}{2} = matrix of fitted values etc.
           Note that these are not back-transformed, and may have the
           parametric component removed.
           (exact content varies according to module).
    fit{4}{3} = various details of the evaluation points.
    fit{4}{4} = fit limits.
    fit{4}{5} = family,link.
    fit{5} = parametric component values.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function fit=locfit(varargin)
0002 
0003 % Smoothing noisy data using Local Regression and Likelihood.
0004 %
0005 % arguments still to add: dc maxit
0006 %
0007 %  Usage: fit = locfit(x,y)   % local regression fit of x and y.
0008 %         fit = locfit(x)     % density estimation of x.
0009 %
0010 %  Smoothing with locfit is a two-step procedure. The locfit()
0011 %  function evaluates the local regression smooth at a set of points
0012 %  (can be specified through an evaluation structure). Then, use
0013 %  the predict() function to interpolate this fit to other points.
0014 %
0015 %  Additional arguments to locfit() are specified as 'name',value pairs, e.g.:
0016 %  locfit( x, 'alpha',[0.7,1.5] , 'family','rate' , 'ev','grid' , 'mg',100 );
0017 %
0018 %
0019 %  Data-related inputs:
0020 %
0021 %    x is a vector or matrix of the independent (or predictor) variables.
0022 %      Rows of x represent subjects, columns represent variables.
0023 %      Generally, local regression would be used with 1-4 independent
0024 %      variables. In higher dimensions, the curse-of-dimensionality,
0025 %      as well as the difficulty of visualizing higher dimensional
0026 %      surfaces, may limit usefulness.
0027 %
0028 %    y is the column vector of the dependent (or response) variable.
0029 %      For density families, 'y' is omitted.
0030 % NOTE: x and y are the first two arguments. All other arguments require
0031 %        the 'name',value notation.
0032 %
0033 %    'weights' Prior weights for observations (reciprocal of variance, or
0034 %           sample size).
0035 %    'cens' Censoring indicators for hazard rate or censored regression.
0036 %           The coding is '1' (or 'TRUE') for a censored observation, and
0037 %           '0' (or 'FALSE') for uncensored observations.
0038 %    'base' Baseline parameter estimate. If a baseline is provided,
0039 %           the local regression model is fitted as
0040 %                        Y_i = b_i + m(x_i) + epsilon_i,
0041 %           with Locfit estimating the m(x) term. For regression models,
0042 %           this effectively subtracts b_i from Y_i. The advantage of the
0043 %           'base' formulation is that it extends to likelihood
0044 %           regression models.
0045 %    'scale' A scale to apply to each variable. This is especially
0046 %           important for multivariate fitting, where variables may be
0047 %           measured in non-comparable units. It is also used to specify
0048 %           the frequency for variables with the 'a' (angular) style.
0049 %     'sty' Character string (length d) of styles for each predictor variable.
0050 %           n denotes `normal'; a denotes angular (or periodic); l and r
0051 %           denotes one-sided left and right; c is conditionally parametric.
0052 %
0053 %
0054 %  Smoothing Parameters and Bandwidths:
0055 %  The bandwidth (or more accurately, half-width) of the smoothing window
0056 %  controls the amount of smoothing. Locfit allows specification of constant
0057 %  (fixed), nearest neighbor, certain locally adaptive variable bandwidths,
0058 %  and combinations of these. Also related to the smoothing parameter
0059 %  are the local polynmial degree and weight function.
0060 %
0061 %    'nn' 'Nearest neighbor' smoothing parameter. Specifying 'nn',0.5
0062 %         means that the width of each smoothing neighborhood is chosen
0063 %         to cover 50% of the data.
0064 %
0065 %     'h' A constant (or fixed) bandwidth parameter. For example, 'h',2
0066 %         means that the smoothing windows have constant half-width
0067 %         (or radius) 2. Note that h is applied after scaling.
0068 %
0069 %   'pen' penalty parameter for adaptive smoothing. Needs to be used
0070 %         with care.
0071 %
0072 %  'alpha' The old way of specifying smoothing parameters, as used in
0073 %         my book. alpha is equivalent to the vector [nn,h,pen].
0074 %         If multiple componenents are non-zero, the largest corresponding
0075 %         bandwidth is used. The default (if none of alpha,nn,h,pen
0076 %         are provided) is [0.7 0 0].
0077 %
0078 %   'deg' Degree of local polynomial. Default: 2 (local quadratic).
0079 %         Degrees 0 to 3 are supported by almost all parts of the
0080 %         Locfit code. Higher degrees may work in some cases.
0081 %
0082 %  'kern' Weight function, default = 'tcub'. Other choices are
0083 %         'rect', 'trwt', 'tria', 'epan', 'bisq' and 'gauss'.
0084 %         Choices may be restricted when derivatives are
0085 %         required; e.g. for confidence bands and some bandwidth
0086 %         selectors.
0087 %
0088 %    'kt' Kernel type, 'sph' (default); 'prod'. In multivariate
0089 %         problems, 'prod' uses a simplified product model which
0090 %         speeds up computations.
0091 %
0092 %  'acri' Criterion for adaptive bandwidth selection.
0093 %
0094 %
0095 %  Derivative Estimation.
0096 %  Generally I recommend caution when using derivative estimation
0097 %  (and especially higher order derivative estimation) -- can you
0098 %  really estimate derivatives from noisy data? Any derivative
0099 %  estimate is inherently more dependent on an assumed smoothness
0100 %  (expressed through the bandwidth) than the data. Warnings aside...
0101 %
0102 %  'deriv' Derivative estimation. 'deriv',1 specifies the first derivative
0103 %         (or more correctly, an estimate of the local slope is returned.
0104 %         'deriv',[1 1] specifies the second derivative. For bivariate fits
0105 %         'deriv',2 specifies the first partial derivative wrt x2.
0106 %         'deriv',[1 2] is mixed second-order derivative.
0107 %
0108 %  Fitting family.
0109 %  'family' is used to specify the local likelihood family.
0110 %         Regression-type families are 'gaussian', 'binomial',
0111 %           'poisson', 'gamma' and 'geom'. If the family is preceded
0112 %           by a q (e.g. 'qgauss', or 'qpois') then quasi-likelihood is
0113 %           used; in particular, a dispersion estimate is computed.
0114 %           Preceding by an 'r' makes an attempt at robust (outlier-resistant)
0115 %           estimation. Combining q and r (e.g. 'family','qrpois') may
0116 %           work, if you're lucky.
0117 %         Density estimation-type families are 'dens', 'rate' and 'hazard'
0118 %           (hazard or failure rate). Note that `dens' scales the output
0119 %           to be a statistical density estimate (i.e. scaled to integrate
0120 %           to 1). 'rate' estimates the rate or intensity function (events
0121 %           per unit time, or events per unit area), which may be called
0122 %           density in some fields.
0123 %         The default family is 'qgauss' if a response (y argument) has been
0124 %         provided, and 'dens' if no response is given.
0125 %    'link' Link function for local likelihood fitting. Depending on the
0126 %           family, choices may be 'ident', 'log', 'logit',
0127 %           'inverse', 'sqrt' and 'arcsin'.
0128 %
0129 %  Evaluation structures.
0130 %    By default, locfit chooses a set of points, depending on the data
0131 %    and smoothing parameters, to evaluate at. This is controlled by
0132 %    the evaluation structure.
0133 %      'ev' Specify the evaluation structure. Default is 'tree'.
0134 %           Other choices include 'phull' (triangulation), 'grid' (a grid
0135 %           of points), 'data' (each data point), 'crossval' (data,
0136 %           but use leave-one-out cross validation), 'none' (no evaluation
0137 %           points, effectively producing the global parametric fit).
0138 %           Alternatively, a vector/matrix of evaluation points may be
0139 %           provided.
0140 %           (kd trees not currently supported in mlocfit)
0141 %     'll' and 'ur' -- row vectors specifying the upper and lower limits
0142 %           for the bounding box used by the evaluation structure.
0143 %           They default to the data range.
0144 %     'mg' For the 'grid' evaluation structure, 'mg' specifies the
0145 %           number of points on each margin. Default 10. Can be either a
0146 %           single number or vector.
0147 %    'cut' Refinement parameter for adaptive partitions. Default 0.8;
0148 %           smaller values result in more refined partitions.
0149 %    'maxk' Controls space assignment for evaluation structures. For the
0150 %           adaptive evaluation structures, it is impossible to be sure
0151 %           in advance how many vertices will be generated. If you get
0152 %           warnings about `Insufficient vertex space', Locfit's default
0153 %           assigment can be increased by increasing 'maxk'. The default
0154 %           is 'maxk','100'.
0155 %
0156 %    'xlim' For density estimation, Locfit allows the density to be
0157 %           supported on a bounded interval (or rectangle, in more than
0158 %           one dimension). The format should be [ll;ul] (ie, matrix with
0159 %           two rows, d columns) where ll is the lower left corner of
0160 %           the rectangle, and ur is the upper right corner.
0161 %           One-sided bounds, such as [0,infty), are not supported, but can be
0162 %           effectively specified by specifying a very large upper
0163 %           bound.
0164 %
0165 %      'module' either 'name' or {'name','/path/to/module',parameters}.
0166 %
0167 %  Density Estimation
0168 %      'renorm',1  will attempt to renormalize the local likelihood
0169 %           density estimate so that it integrates to 1. The llde
0170 %           (specified by 'family','dens') is scaled to estimate the
0171 %           density, but since the estimation is pointwise, there is
0172 %           no guarantee that the resulting density integrates exactly
0173 %           to 1. Renormalization attempts to achieve this.
0174 %
0175 %  The output of locfit() is a Matlab structure:
0176 %
0177 % fit.data.x (n*d)
0178 % fit.data.y (n*1)
0179 % fit.data.weights (n*1 or 1*1)
0180 % fit.data.censor (n*1 or 1*1)
0181 % fit.data.baseline (n*1 or 1*1)
0182 % fit.data.style (string length d)
0183 % fit.data.scales (1*d)
0184 % fit.data.xlim (2*d)
0185 %
0186 % fit.evaluation_structure.type (string)
0187 % fit.evaluation_structure.module.name (string)
0188 % fit.evaluation_structure.module.directory (string)
0189 % fit.evaluation_structure.module.parameters (string)
0190 % fit.evaluation_structure.lower_left (numeric 1*d)
0191 % fit.evaluation_structure.upper_right (numeric 1*d)
0192 % fit.evaluation_structure.grid (numeric 1*d)
0193 % fit.evaluation_structure.cut (numeric 1*d)
0194 % fit.evaluation_structure.maxk
0195 % fit.evaluation_structure.derivative
0196 %
0197 % fit.smoothing_parameters.alpha = (nn h pen) vector
0198 % fit.smoothing_parameters.adaptive_criterion (string)
0199 % fit.smoothing_parameters.degree (numeric)
0200 % fit.smoothing_parameters.family (string)
0201 % fit.smoothing_parameters.link (string)
0202 % fit.smoothing_parameters.kernel (string)
0203 % fit.smoothing_parameters.kernel_type (string)
0204 % fit.smoothing_parameters.deren
0205 % fit.smoothing_parameters.deit
0206 % fit.smoothing_parameters.demint
0207 % fit.smoothing_parameters.debug
0208 %
0209 % fit.fit_points.evaluation_points (d*nv matrix)
0210 % fit.fit_points.fitted_values (matrix, nv rows, many columns)
0211 % fit.fit_points.evaluation_vectors.cell
0212 % fit.fit_points.evaluation_vectors.splitvar
0213 % fit.fit_points.evaluation_vectors.lo
0214 % fit.fit_points.evaluation_vectors.hi
0215 % fit.fit_points.fit_limits (d*2 matrix)
0216 % fit.fit_points.family_link (numeric values)
0217 % fit.fit_points.kappa (likelihood, degrees of freedom, etc)
0218 %
0219 % fit.parametric_component
0220 %
0221 %
0222 %  The OLD format:
0223 %
0224 %    fit{1} = data.
0225 %    fit{2} = evaluation structure.
0226 %    fit{3} = smoothing parameter structure.
0227 %    fit{4}{1} = fit points matrix.
0228 %    fit{4}{2} = matrix of fitted values etc.
0229 %           Note that these are not back-transformed, and may have the
0230 %           parametric component removed.
0231 %           (exact content varies according to module).
0232 %    fit{4}{3} = various details of the evaluation points.
0233 %    fit{4}{4} = fit limits.
0234 %    fit{4}{5} = family,link.
0235 %    fit{5} = parametric component values.
0236 %
0237 
0238 
0239 
0240 % Minimal input validation
0241 if nargin < 1
0242    error( 'At least one input argument required' );
0243 end
0244 
0245 xdata = double(varargin{1});
0246 d = size(xdata,2);
0247 n = size(xdata,1);
0248 if ((nargin>1) && (~ischar(varargin{2})))
0249   ydata = double(varargin{2});
0250   if (any(size(ydata) ~= [n 1])); error('y must be n*1 column vector'); end;
0251   family = 'qgauss';
0252   na = 3;
0253 else
0254   ydata = 0;
0255   family = 'density';
0256   na = 2;
0257 end;
0258 if mod(nargin-na,2)==0
0259   error( 'All arguments other than x, y must be name,value pairs' );
0260 end
0261 
0262 
0263 wdata = ones(n,1);
0264 cdata = 0;
0265 base  = 0;
0266 style = 'n';
0267 scale = 1;
0268 xl = zeros(2,d);
0269 
0270 alpha = [0 0 0];
0271 deg = 2;
0272 link = 'default';
0273 acri = 'none';
0274 kern = 'tcub';
0275 kt = 'sph';
0276 deren = 0;
0277 deit  = 'default';
0278 demint= 20;
0279 debug = 0;
0280 
0281 ev = 'tree';
0282 ll = zeros(1,d);
0283 ur = zeros(1,d);
0284 mg = 10;
0285 maxk = 100;
0286 deriv=0;
0287 cut = 0.8;
0288 mdl = struct('name','std', 'directory','', 'parameters',0 );
0289 
0290 while na < length(varargin)
0291     inc = 0;
0292     if (varargin{na}=='y')
0293         ydata = double(varargin{na+1});
0294         family = 'qgauss';
0295         inc = 2;
0296         if (any(size(ydata) ~= [n 1])); error('y must be n*1 column vector'); end;
0297     end
0298     if (strcmp(varargin{na},'weights'))
0299         wdata = double(varargin{na+1});
0300         inc = 2;
0301         if (any(size(wdata) ~= [n 1])); error('weights must be n*1 column vector'); end;
0302     end
0303     if (strcmp(varargin{na},'cens'))
0304         cdata = double(varargin{na+1});
0305         inc = 2;
0306         if (any(size(cdata) ~= [n 1])); error('cens must be n*1 column vector'); end;
0307     end
0308     if (strcmp(varargin{na},'base')) % numeric vector, n*1 or 1*1.
0309         base = double(varargin{na+1});
0310         if (length(base)==1); base = base*ones(n,1); end;
0311         inc = 2;
0312     end
0313     if (strcmp(varargin{na},'style')) % character string of length d.
0314         style = varargin{na+1};
0315         inc = 2;
0316     end;
0317     if (strcmp(varargin{na},'scale')) % row vector, length 1 or d.
0318         scale = varargin{na+1};
0319         if (scale==0)
0320           scale = zeros(1,d);
0321           for i=1:d
0322             scale(i) = sqrt(var(xdata(:,i)));
0323           end;
0324         end;
0325         inc = 2;
0326     end;
0327     if (strcmp(varargin{na},'xlim')) % 2*d numeric matrix.
0328         xl = varargin{na+1};
0329         inc = 2;
0330     end
0331     if (strcmp(varargin{na},'alpha')) % row vector of length 1, 2 or 3.
0332         alpha = [varargin{na+1} 0 0 0];
0333         alpha = alpha(1:3);
0334         inc = 2;
0335     end
0336     if (strcmp(varargin{na},'nn')) % scalar
0337         alpha(1) = varargin{na+1};
0338         inc = 2;
0339     end
0340     if (strcmp(varargin{na},'h')) % scalar
0341         alpha(2) = varargin{na+1};
0342         inc = 2;
0343     end;
0344     if (strcmp(varargin{na},'pen')) % scalar
0345         alpha(3) = varargin{na+1};
0346         inc = 2;
0347     end;
0348     if (strcmp(varargin{na},'acri')) % string
0349         acri = varargin{na+1};
0350         inc = 2;
0351     end
0352     if (strcmp(varargin{na},'deg')) % positive integer.
0353         deg = varargin{na+1};
0354         inc = 2;
0355     end;
0356     if (strcmp(varargin{na},'family')) % character string.
0357         family = varargin{na+1};
0358         inc = 2;
0359     end;
0360     if (strcmp(varargin{na},'link')) % character string.
0361         link = varargin{na+1};
0362         inc = 2;
0363     end;
0364     if (strcmp(varargin{na},'kern')) % character string.
0365         kern = varargin{na+1};
0366         inc = 2;
0367     end;
0368     if (strcmp(varargin{na},'kt')) % character string.
0369         kt = varargin{na+1};
0370         inc = 2;
0371     end;
0372     if (strcmp(varargin{na},'ev')) % char. string, or matrix with d columns.
0373         ev = varargin{na+1};
0374         if (isnumeric(ev)); ev = ev'; end;
0375         inc = 2;
0376     end;
0377     if (strcmp(varargin{na},'ll')) % row vector of length d.
0378         ll = varargin{na+1};
0379         inc = 2;
0380     end;
0381     if (strcmp(varargin{na},'ur')) % row vector of length d.
0382         ur = varargin{na+1};
0383         inc = 2;
0384     end;
0385     if (strcmp(varargin{na},'mg')) % row vector of length d.
0386         mg = varargin{na+1};
0387         inc = 2;
0388     end;
0389     if (strcmp(varargin{na},'cut')) % positive scalar.
0390         cut = varargin{na+1};
0391         inc = 2;
0392     end;
0393     if (strcmp(varargin{na},'module')) % string.
0394         mdl = struct('name',varargin{na+1}, 'directory','', 'parameters',0 );
0395         inc = 2;
0396     end;
0397     if (strcmp(varargin{na},'maxk')) % positive integer.
0398         maxk = varargin{na+1};
0399         inc = 2;
0400     end;
0401     if (strcmp(varargin{na},'deriv')) % numeric row vector, up to deg elements.
0402         deriv = varargin{na+1};
0403         inc = 2;
0404     end;
0405     if (strcmp(varargin{na},'renorm')) % density renormalization.
0406         deren = varargin{na+1};
0407         inc = 2;
0408     end;
0409     if (strcmp(varargin{na},'itype')) % density - integration type.
0410         deit = varargin{na+1};
0411         inc = 2;
0412     end;
0413     if (strcmp(varargin{na},'mint')) % density - # of integration points.
0414         demint = varargin{na+1};
0415         inc = 2;
0416     end;
0417     if (strcmp(varargin{na},'debug')) % debug level.
0418         debug = varargin{na+1};
0419         inc = 2;
0420     end;
0421     if (inc==0)
0422       disp(varargin{na});
0423       error('Unknown Input Argument.');
0424     end;
0425     na=na+inc;
0426 end
0427 
0428 
0429 fit.data.x = xdata;
0430 fit.data.y = ydata;
0431 fit.data.weights = wdata;
0432 fit.data.censor = cdata;
0433 fit.data.baseline = base;
0434 fit.data.style = style;
0435 fit.data.scales = scale;
0436 fit.data.xlim = xl;
0437 
0438 fit.evaluation_structure.type = ev;
0439 fit.evaluation_structure.module = mdl;
0440 fit.evaluation_structure.lower_left = ll;
0441 fit.evaluation_structure.upper_right = ur;
0442 fit.evaluation_structure.grid = mg;
0443 fit.evaluation_structure.cut = cut;
0444 fit.evaluation_structure.maxk = maxk;
0445 fit.evaluation_structure.derivative = deriv;
0446 
0447 if (alpha==0); alpha = [0.7 0 0]; end;
0448 
0449 fit.smoothing_parameters.alpha = alpha;
0450 fit.smoothing_parameters.adaptive_criterion = acri;
0451 fit.smoothing_parameters.degree = deg;
0452 fit.smoothing_parameters.family = family;
0453 fit.smoothing_parameters.link = link;
0454 fit.smoothing_parameters.kernel = kern;
0455 fit.smoothing_parameters.kernel_type = kt;
0456 fit.smoothing_parameters.deren = deren;
0457 fit.smoothing_parameters.deit = deit;
0458 fit.smoothing_parameters.demint = demint;
0459 fit.smoothing_parameters.debug = debug;
0460 
0461 [fpc pcomp] = mexlf(fit.data,fit.evaluation_structure,fit.smoothing_parameters);
0462 fit.fit_points = fpc;
0463 fit.parametric_component = pcomp;
0464 
0465 return
0466 
0467 
0468

Generated on Fri 28-Sep-2012 12:34:30 by m2html © 2005