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