Home > chronux > locfit > m > lfplot.m

lfplot

PURPOSE ^

Plot (for one or two dimensions) a locfit() fit.

SYNOPSIS ^

function lfplot(varargin)

DESCRIPTION ^

 Plot (for one or two dimensions) a locfit() fit.

 Usage:
   fit = locfit(x,y);
   lfplot(fit);

 Plot the fitted smooth curve, and add a scatterplot of the data.

 Required argument:
   fit  (produced by locfit()).

 Optional arguments:
   'nodata'  - don't add data to plot.
   'contour' - for 2-d predictors, use contour instead of surf.
   'direct'  - fit directly, instead of using interpolation
               (see the predict() function).
   'what'    - locfit what argument ('coef', 'infl', 'vari', 'band' etc).
   Any additional arguments are passed to Matlab's plot(), contour()
     or surf() function as appropriate.

 To add confidence bands, use the lfband() function.

 Author: Catherine Loader.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function lfplot(varargin)
0002  
0003 % Plot (for one or two dimensions) a locfit() fit.
0004 %
0005 % Usage:
0006 %   fit = locfit(x,y);
0007 %   lfplot(fit);
0008 %
0009 % Plot the fitted smooth curve, and add a scatterplot of the data.
0010 %
0011 % Required argument:
0012 %   fit  (produced by locfit()).
0013 %
0014 % Optional arguments:
0015 %   'nodata'  - don't add data to plot.
0016 %   'contour' - for 2-d predictors, use contour instead of surf.
0017 %   'direct'  - fit directly, instead of using interpolation
0018 %               (see the predict() function).
0019 %   'what'    - locfit what argument ('coef', 'infl', 'vari', 'band' etc).
0020 %   Any additional arguments are passed to Matlab's plot(), contour()
0021 %     or surf() function as appropriate.
0022 %
0023 % To add confidence bands, use the lfband() function.
0024 %
0025 % Author: Catherine Loader.
0026 
0027 fit = varargin{1};
0028 data = fit.data;
0029 xdata = data.x;
0030 n = size(xdata,1);
0031 d = size(xdata,2);
0032 fali = fit.fit_points.family_link;
0033 ydata = data.y;
0034 wdata = data.weights;
0035 cdata = data.censor;
0036 if (length(cdata)==1) cdata = zeros(n,1); end;
0037 showdata = (fit.evaluation_structure.derivative==0);
0038 ppargs = {};
0039 plotargs = {};
0040 
0041 type = 's';
0042 na = 2;
0043 while na <= length(varargin)
0044   inc = 0;
0045   if (strcmp(varargin{na},'contour'))
0046     type = 'c';
0047     inc = 1;
0048   end;
0049   if (strcmp(varargin{na},'what'))
0050     ppargs = {ppargs{:}, 'what', varargin{na+1}};
0051     showdata = 0;
0052     inc = 2;
0053   end;
0054   if (strcmp(varargin{na},'nodata'))
0055     showdata = 0;
0056     inc = 1;
0057   end;
0058   if (strcmp(varargin{na},'direct'))
0059     ppargs = {ppargs{:} 'direct'};
0060     inc = 1;
0061   end;
0062   if (inc==0)
0063     plotargs = {plotargs{:} varargin{na}};
0064     inc = 1;
0065   end;
0066   na = na+inc;
0067 end;
0068 
0069 xfit = lfmarg(fit);
0070 yfit = predict(fit,xfit,ppargs{:});
0071 yfit = invlink(yfit,fali);
0072 fam = mod(fali(1),64);
0073 if (fam>4)
0074   ydata = ydata ./ wdata;
0075 end;
0076 
0077 if (d==1)
0078   plot(xfit{1},yfit,plotargs{:});
0079   if (showdata)
0080     hold on;
0081     if (length(ydata)==1) ydata = zeros(n,1); end;
0082     plotbyfactor(xdata,ydata,cdata);
0083     hold off;
0084   end;
0085 end;
0086 
0087 if (d==2)
0088   x1 = xfit{1};
0089   x2 = xfit{2};
0090   yfit = reshape(yfit,length(x1),length(x2));
0091   if (type=='c')
0092     [C h] = contour(x1,x2,yfit',plotargs{:});
0093     clabel(C,h);
0094     if (showdata)
0095       hold on;
0096       plotbyfactor(xdata(:,1),xdata(:,2),cdata);
0097       hold off;
0098     end;
0099   else
0100     surf(x1,x2,yfit',plotargs{:});
0101   end;
0102 end;
0103 
0104 return;

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