predict

PURPOSE ^

Interpolate a fit produced by locfit().

SYNOPSIS ^

function [y, se] = predict(varargin)

DESCRIPTION ^

 Interpolate a fit produced by locfit().

 predict(fit)    produces the fitted values at locfit's selected points.
 predict(fit,x)  interpolates the fits to points specified by x.

 Input arguments:
   fit   The locfit() fit.
   x     Points to interpolate at. May be a matrix with d columns,
         or cell with d components (each a vector). In the former
         case, a fitted value is computed for each row of x.
         In the latter, the components of x are interpreted as
         grid margins.
         Can also specify 'data' (evaluate at data points);
         or 'fitp' (extract the fitted points).
  'band',value
         Type of standard errors to compute. Default is 'band','n', for none.
         Other choices are 'band','g' (use a global s to estimate the resiudal
         standard deviation, so standard errors are s*||l(x)||);
         'band','l' (use a local s(x), so std. errors are s(x)*||l(x)||);
         'band','p' (prediction errors, so s*sqrt(1+||l(x)||^2).
  'direct'
         Compute the local fit directly (rather than using local
         regression, at each point specified by the x argument.
  'kappa',vector
         Vector of constants for simultaneous confidence bands,
         computed by the kappa0() function.
  'level',value
         Coverage probability for confidence intervals and bands.
         Default is 0.95.

  Output is a vector of fitted values (if 'band','n'), or a cell
  with fitted value, standard error vectors, and matrix of lower
  and upper confidence limits.

  Note that for local likelihood fits, back-transformation is
  not performed, so that (e.g.) for Poisson regression with the
  log-link, the output estimates the log-mean, and its standard errors.
  Likewise, for density estimation, the output is log(density).

  Author: Catherine Loader.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [y, se] = predict(varargin)
0002 
0003 % Interpolate a fit produced by locfit().
0004 %
0005 % predict(fit)    produces the fitted values at locfit's selected points.
0006 % predict(fit,x)  interpolates the fits to points specified by x.
0007 %
0008 % Input arguments:
0009 %   fit   The locfit() fit.
0010 %   x     Points to interpolate at. May be a matrix with d columns,
0011 %         or cell with d components (each a vector). In the former
0012 %         case, a fitted value is computed for each row of x.
0013 %         In the latter, the components of x are interpreted as
0014 %         grid margins.
0015 %         Can also specify 'data' (evaluate at data points);
0016 %         or 'fitp' (extract the fitted points).
0017 %  'band',value
0018 %         Type of standard errors to compute. Default is 'band','n', for none.
0019 %         Other choices are 'band','g' (use a global s to estimate the resiudal
0020 %         standard deviation, so standard errors are s*||l(x)||);
0021 %         'band','l' (use a local s(x), so std. errors are s(x)*||l(x)||);
0022 %         'band','p' (prediction errors, so s*sqrt(1+||l(x)||^2).
0023 %  'direct'
0024 %         Compute the local fit directly (rather than using local
0025 %         regression, at each point specified by the x argument.
0026 %  'kappa',vector
0027 %         Vector of constants for simultaneous confidence bands,
0028 %         computed by the kappa0() function.
0029 %  'level',value
0030 %         Coverage probability for confidence intervals and bands.
0031 %         Default is 0.95.
0032 %
0033 %  Output is a vector of fitted values (if 'band','n'), or a cell
0034 %  with fitted value, standard error vectors, and matrix of lower
0035 %  and upper confidence limits.
0036 %
0037 %  Note that for local likelihood fits, back-transformation is
0038 %  not performed, so that (e.g.) for Poisson regression with the
0039 %  log-link, the output estimates the log-mean, and its standard errors.
0040 %  Likewise, for density estimation, the output is log(density).
0041 %
0042 %  Author: Catherine Loader.
0043 
0044 if (nargin<1)
0045     error('predict requires fit argument');
0046 end;
0047 
0048 fit = varargin{1};
0049 
0050 if (nargin==1) x = 'fitp'; else x = varargin{2}; end;
0051 
0052 band = 'n';
0053 what = 'coef';
0054 rest = 'none';
0055 dir  = 0;
0056 level = 0.95;
0057 d = size(fit.data.x,2);
0058 kap = [zeros(1,d) 1];
0059 
0060 na = 3;
0061 while na <= nargin
0062   inc = 0;
0063   if strcmp(varargin{na},'band')
0064     band = varargin{na+1};
0065     inc = 2;
0066   end;
0067   if strcmp(varargin{na},'what')
0068     what = varargin{na+1};
0069     inc = 2;
0070   end;
0071   if strcmp(varargin{na},'restyp')
0072     rest = varargin{na+1};
0073     inc = 2;
0074   end;
0075   if strcmp(varargin{na},'direct')
0076     dir = 1;
0077     inc = 1;
0078   end;
0079   if strcmp(varargin{na},'kappa')
0080     kap = varargin{na+1};
0081     inc = 2;
0082   end;
0083   if strcmp(varargin{na},'level')
0084     level = varargin{na+1};
0085     inc = 2;
0086   end;
0087   if (inc == 0)
0088     disp(varargin{na});
0089     error('Unknown argument');
0090   end;
0091   na = na+inc;
0092 end;
0093 
0094 [y se cb] = mexpp(x,fit,band,what,rest,dir,kap,level);
0095 if (band=='n')
0096     y = y;
0097 else
0098     y = {y se cb};
0099 end;
0100 
0101 return;

Generated on Fri 12-Aug-2011 11:36:15 by m2html © 2005