comparison rDiff/src/locfit/m/lfplot.m @ 0:0f80a5141704

version 0.3 uploaded
author vipints
date Thu, 14 Feb 2013 23:38:36 -0500
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:0f80a5141704
1 function lfplot(varargin)
2
3 % Plot (for one or two dimensions) a locfit() fit.
4 %
5 % Usage:
6 % fit = locfit(x,y);
7 % lfplot(fit);
8 %
9 % Plot the fitted smooth curve, and add a scatterplot of the data.
10 %
11 % Required argument:
12 % fit (produced by locfit()).
13 %
14 % Optional arguments:
15 % 'nodata' - don't add data to plot.
16 % 'contour' - for 2-d predictors, use contour instead of surf.
17 % 'direct' - fit directly, instead of using interpolation
18 % (see the predict() function).
19 % 'what' - locfit what argument ('coef', 'infl', 'vari', 'band' etc).
20 % Any additional arguments are passed to Matlab's plot(), contour()
21 % or surf() function as appropriate.
22 %
23 % To add confidence bands, use the lfband() function.
24 %
25 % Author: Catherine Loader.
26
27 fit = varargin{1};
28 data = fit.data;
29 xdata = data.x;
30 n = size(xdata,1);
31 d = size(xdata,2);
32 fali = fit.fit_points.family_link;
33 ydata = data.y;
34 wdata = data.weights;
35 cdata = data.censor;
36 if (length(cdata)==1) cdata = zeros(n,1); end;
37 showdata = (fit.evaluation_structure.derivative==0);
38 ppargs = {};
39 plotargs = {};
40
41 type = 's';
42 na = 2;
43 while na <= length(varargin)
44 inc = 0;
45 if (strcmp(varargin{na},'contour'))
46 type = 'c';
47 inc = 1;
48 end;
49 if (strcmp(varargin{na},'what'))
50 ppargs = {ppargs{:}, 'what', varargin{na+1}};
51 showdata = 0;
52 inc = 2;
53 end;
54 if (strcmp(varargin{na},'nodata'))
55 showdata = 0;
56 inc = 1;
57 end;
58 if (strcmp(varargin{na},'direct'))
59 ppargs = {ppargs{:} 'direct'};
60 inc = 1;
61 end;
62 if (inc==0)
63 plotargs = {plotargs{:} varargin{na}};
64 inc = 1;
65 end;
66 na = na+inc;
67 end;
68
69 xfit = lfmarg(fit);
70 yfit = predict(fit,xfit,ppargs{:});
71 yfit = invlink(yfit,fali);
72 fam = mod(fali(1),64);
73 if (fam>4)
74 ydata = ydata ./ wdata;
75 end;
76
77 if (d==1)
78 plot(xfit{1},yfit,plotargs{:});
79 if (showdata)
80 hold on;
81 if (length(ydata)==1) ydata = zeros(n,1); end;
82 plotbyfactor(xdata,ydata,cdata);
83 hold off;
84 end;
85 end;
86
87 if (d==2)
88 x1 = xfit{1};
89 x2 = xfit{2};
90 yfit = reshape(yfit,length(x1),length(x2));
91 if (type=='c')
92 [C h] = contour(x1,x2,yfit',plotargs{:});
93 clabel(C,h);
94 if (showdata)
95 hold on;
96 plotbyfactor(xdata(:,1),xdata(:,2),cdata);
97 hold off;
98 end;
99 else
100 surf(x1,x2,yfit',plotargs{:});
101 end;
102 end;
103
104 return;