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