annotate rDiff/src/locfit/m/predict.m @ 3:29a698dc5c7e default tip

Merge multiple heads.
author Dave Bouvier <dave@bx.psu.edu>
date Mon, 27 Jan 2014 14:15:36 -0500
parents 0f80a5141704
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 [y, se] = predict(varargin)
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
2
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
3 % Interpolate a fit produced by locfit().
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
4 %
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
5 % predict(fit) produces the fitted values at locfit's selected points.
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
6 % predict(fit,x) interpolates the fits to points specified by x.
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
7 %
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
8 % Input arguments:
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
9 % fit The locfit() fit.
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
10 % x Points to interpolate at. May be a matrix with d columns,
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
11 % or cell with d components (each a vector). In the former
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
12 % case, a fitted value is computed for each row of x.
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
13 % In the latter, the components of x are interpreted as
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
14 % grid margins.
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
15 % Can also specify 'data' (evaluate at data points);
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
16 % or 'fitp' (extract the fitted points).
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
17 % 'band',value
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
18 % Type of standard errors to compute. Default is 'band','n', for none.
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
19 % Other choices are 'band','g' (use a global s to estimate the resiudal
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
20 % standard deviation, so standard errors are s*||l(x)||);
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
21 % 'band','l' (use a local s(x), so std. errors are s(x)*||l(x)||);
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
22 % 'band','p' (prediction errors, so s*sqrt(1+||l(x)||^2).
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
23 % 'direct'
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
24 % Compute the local fit directly (rather than using local
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
25 % regression, at each point specified by the x argument.
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
26 % 'kappa',vector
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
27 % Vector of constants for simultaneous confidence bands,
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
28 % computed by the kappa0() function.
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
29 % 'level',value
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
30 % Coverage probability for confidence intervals and bands.
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
31 % Default is 0.95.
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
32 %
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
33 % Output is a vector of fitted values (if 'band','n'), or a cell
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
34 % with fitted value, standard error vectors, and matrix of lower
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
35 % and upper confidence limits.
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
36 %
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
37 % Note that for local likelihood fits, back-transformation is
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
38 % not performed, so that (e.g.) for Poisson regression with the
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
39 % log-link, the output estimates the log-mean, and its standard errors.
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
40 % Likewise, for density estimation, the output is log(density).
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
41 %
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
42 % Author: Catherine Loader.
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
43
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
44 if (nargin<1)
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
45 error('predict requires fit argument');
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
46 end;
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
47
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
48 fit = varargin{1};
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
49
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
50 if (nargin==1) x = 'fitp'; else x = varargin{2}; end;
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
51
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
52 band = 'n';
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
53 what = 'coef';
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
54 rest = 'none';
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
55 dir = 0;
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
56 level = 0.95;
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
57 d = size(fit.data.x,2);
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
58 kap = [zeros(1,d) 1];
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
59
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
60 na = 3;
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
61 while na <= nargin
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
62 inc = 0;
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
63 if strcmp(varargin{na},'band')
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
64 band = varargin{na+1};
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
65 inc = 2;
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
66 end;
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
67 if strcmp(varargin{na},'what')
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
68 what = varargin{na+1};
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
69 inc = 2;
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
70 end;
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
71 if strcmp(varargin{na},'restyp')
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
72 rest = varargin{na+1};
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
73 inc = 2;
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
74 end;
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
75 if strcmp(varargin{na},'direct')
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
76 dir = 1;
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
77 inc = 1;
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
78 end;
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
79 if strcmp(varargin{na},'kappa')
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
80 kap = varargin{na+1};
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
81 inc = 2;
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
82 end;
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
83 if strcmp(varargin{na},'level')
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
84 level = varargin{na+1};
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
85 inc = 2;
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
86 end;
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
87 if (inc == 0)
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
88 disp(varargin{na});
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
89 error('Unknown argument');
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
90 end;
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
91 na = na+inc;
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
92 end;
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
93
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
94 [y se cb] = mexpp(x,fit,band,what,rest,dir,kap,level);
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
95 if (band=='n')
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
96 y = y;
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
97 else
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
98 y = {y se cb};
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
99 end;
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
100
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
101 return;