Home > chronux_1_50 > locfit > 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).

 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 % Plot (for one or two dimensions) a locfit() fit.
0003 %
0004 % Usage:
0005 %   fit = locfit(x,y);
0006 %   lfplot(fit);
0007 %
0008 % Plot the fitted smooth curve, and add a scatterplot of the data.
0009 %
0010 % Required argument:
0011 %   fit  (produced by locfit()).
0012 %
0013 % Optional arguments:
0014 %   'nodata'  - don't add data to plot.
0015 %   'contour' - for 2-d predictors, use contour instead of surf.
0016 %   'direct'  - fit directly, instead of using interpolation
0017 %               (see the predict() function).
0018 %
0019 % To add confidence bands, use the lfband() function.
0020 %
0021 % Author: Catherine Loader.
0022 
0023 fit = varargin{1};
0024 data = fit{1};
0025 xdata = data{1};
0026 n = size(xdata,1);
0027 d = size(xdata,2);
0028 fali = fit{4}{5};
0029 ydata = data{2};
0030 wdata = data{3};
0031 cdata = data{4};
0032 if length(cdata)==1 ; cdata = zeros(n,1); end;
0033 showdata = (fit{2}{8}==0);
0034 ppargs = {};
0035 
0036 type = 's';
0037 na = 2;
0038 while na <= length(varargin)
0039   inc = 0;
0040   if (strcmp(varargin{na},'contour'))
0041     type = 'c';
0042     inc = 1;
0043   end;
0044   if (strcmp(varargin{na},'nodata'))
0045     showdata = 0;
0046     inc = 1;
0047   end;
0048   if (strcmp(varargin{na},'direct'))
0049     ppargs = {ppargs{:} 'direct'};
0050     inc = 1;
0051   end;
0052   if (inc==0)
0053     error('Unknown Input',varargin{na});
0054   end;
0055   na = na+inc;
0056 end;
0057 
0058 xfit = lfmarg(fit);
0059 yfit = predict(fit,xfit,ppargs{:});
0060 yfit = invlink(yfit,fali);
0061 fam = mod(fali(1),64);
0062 if (fam>4)
0063   ydata = ydata ./ wdata;
0064 end;
0065 
0066 if (d==1)
0067   plot(xfit{1},yfit);
0068   if (showdata)
0069     hold on;
0070      if (length(ydata)==1); ydata = zeros(n,1); end;
0071 
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 Mon 09-Oct-2006 00:54:52 by m2html © 2003