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).

 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 %
0020 % To add confidence bands, use the lfband() function.
0021 %
0022 % Author: Catherine Loader.
0023 
0024 fit = varargin{1};
0025 data = fit{1};
0026 xdata = data{1};
0027 n = size(xdata,1);
0028 d = size(xdata,2);
0029 fali = fit{4}{5};
0030 ydata = data{2};
0031 wdata = data{3};
0032 cdata = data{4};
0033 if (length(cdata)==1) cdata = zeros(n,1); end;
0034 showdata = (fit{2}{8}==0);
0035 ppargs = {};
0036 
0037 type = 's';
0038 na = 2;
0039 while na <= length(varargin)
0040   inc = 0;
0041   if (strcmp(varargin{na},'contour'))
0042     type = 'c';
0043     inc = 1;
0044   end;
0045   if (strcmp(varargin{na},'nodata'))
0046     showdata = 0;
0047     inc = 1;
0048   end;
0049   if (strcmp(varargin{na},'direct'))
0050     ppargs = {ppargs{:} 'direct'};
0051     inc = 1;
0052   end;
0053   if (inc==0)
0054     error('Unknown Input',varargin{na});
0055   end;
0056   na = na+inc;
0057 end;
0058 
0059 xfit = lfmarg(fit);
0060 yfit = predict(fit,xfit,ppargs{:});
0061 yfit = invlink(yfit,fali);
0062 fam = mod(fali(1),64);
0063 if (fam>4)
0064   ydata = ydata ./ wdata;
0065 end;
0066 
0067 if (d==1)
0068   plot(xfit{1},yfit);
0069   if (showdata)
0070     hold on;
0071     if (length(ydata)==1) ydata = zeros(n,1); end;
0072     plotbyfactor(xdata,ydata,cdata);
0073     hold off;
0074   end;
0075 end;
0076 
0077 if (d==2)
0078   x1 = xfit{1};
0079   x2 = xfit{2};
0080   yfit = reshape(yfit,length(x1),length(x2));
0081   if (type=='c')
0082     [C h] = contour(x1,x2,yfit');
0083     clabel(C,h);
0084     if (showdata)
0085       hold on;
0086       plotbyfactor(xdata(:,1),xdata(:,2),cdata);
0087       hold off;
0088     end;
0089   else
0090     surf(x1,x2,yfit');
0091   end;
0092 end;
0093 
0094 return;

Generated on Tue 28-Mar-2006 14:37:41 by m2html © 2003