1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295
|
.TH " monolr" 2 " March 9, 1998" "Fractales Group" "Scilab Function"
.so ../sci.an
.SH NAME
monolr - monovariate linear regression
.sp
Author: Christophe Canus
.sp
This C_LAB routine provides six different algorithms to proceed linear
regression on monovariate data: least square, weighted least square,
penalized least square, multiple least square, maximum likelyhood and
Lepskii's adaptive procedure least square, in one sole routine.
.sp
.sp
.SH Usage
\f(CR[\fPa_hat,\f(CR[\fPb_hat,y_hat,e_hat,sigma2_e_hat,optvarargout\f(CR]\fP=
monolr(x,y,\f(CR[\fPlrstr,optvarargin\f(CR]\fP)
.SH Input parameters
.RS
.TP
o
\fBx\fP : real vector \f(CR[\fP1,J\f(CR]\fP or
\f(CR[\fPJ,1\f(CR]\fP
Contains the abscissa.
.TP
o
\fBy\fP : real vector \f(CR[\fP1,J\f(CR]\fP or
\f(CR[\fPJ,1\f(CR]\fP
Contains the ordinates to be regressed.
.TP
o
\fBlrstr\fP : string
Contains the string which specifies the type of linear regression to
be used.
.TP
o
\fBoptvarargin\fP :
Contains optional variable input arguments. Depending on the choice of
linear regression, the fourth parameter can be
.RS
.TP
o
\fBw\fP : strictly positive real vector \f(CR[\fP1,J\f(CR]\fP or
\f(CR[\fPJ,1\f(CR]\fP
If weighted least square is chosen, contains the weights.
.TP
o
\fBI\fP : strictly positive real (integer) scalar
If penalized least square is chosen, contains the number of iterations.
.TP
o
\fBsigma2_j\fP : strictly positive real vector \f(CR[\fP1,J\f(CR]\fP or
\f(CR[\fPJ,1\f(CR]\fP
If Lepskii's adaptive procedure least square is chosen, contains the
sequence of variances.
.RE
The fifth parameter can be
.RS
.TP
o
\fBm\fP : real scalar
If penalized least square is chosen, contains the mean of the normal weights.
.TP
o
\fBK\fP : strictly positive real scalar
If Lepskii's adaptive procedure least square is chosen, contains the
confidence constant.
.RE
The sixth parameter can be
.RS
.TP
o
\fBs\fP : strictly positive real scalar
If penalized least square is chosen, contains the variance of the
normal weights.
.RE
.RE
.SH Output parameters
.RS
.TP
o
\fBa_hat\fP : real scalar or vector \f(CR[\fP1,J\f(CR]\fP
Contains the estimated slope.
.TP
o
\fBb_hat\fP : real scalar or vector \f(CR[\fP1,J\f(CR]\fP
Contains the estimated ordimate at the origin.
.TP
o
\fBy_hat\fP : real vector \f(CR[\fP1,J\f(CR]\fP or
\f(CR[\fP1,(J+2)*(J-1)/2\f(CR]\fP
Contains the regressed ordinates.
.TP
o
\fBe_hat\fP : real vector \f(CR[\fP1,J\f(CR]\fP or
\f(CR[\fP1,(J+2)*(J-1)/2\f(CR]\fP
Contains the residuals.
.TP
o
\fBsigma2_e_hat\fP : real scalar
Contains the residuals' variance (that is, the mean square error).
.TP
o
\fBoptvarargout\fP :
Contains optional variable output arguments. If Lepskii's adaptive
procedure least square is chosen, the parameters are
.RS
.TP
o
\fBK_star\fP : strictly positive real scalar
Contains the optimal confidence constant.
.TP
o
\fBj_hat\fP : strictly positive real (integer) scalar
Contains the selected index.
.TP
o
\fBI_c_j_min\fP : real vector \f(CR[\fP1,J\f(CR]\fP
Contains the minimum bounds of the confidence intervals.
.TP
o
\fBI_c_j_max\fP : real vector \f(CR[\fP1,J\f(CR]\fP
Contains the maximum bounds of the confidence intervals.
.TP
o
\fBE_c_j_hat_min\fP : real scalar
Contains the minimum bound of the selected intersection interval.
.TP
o
\fBE_c_j_hat_max\fP : real scalar
Contains the maximum bound of the selected intersection interval.
.RE
.RE
.SH Description
.SH Parameters
The abscissa \fIx\fP and the ordinate \fIy\fP to be regressed with must
be of the same size \f(CR[\fP1,J\f(CR]\fP or \f(CR[\fPJ,1\f(CR]\fP.
The linear regression string \fIlrstr\fP specifies the type of linear
regression used. It can be '\fIls\fP' for least square, '\fIwls\fP' for
weighted least square, '\fIpls\fP' for penalized least
square, '\fImls\fP' for multiple least square (that is for \fIj\fP
varying from \fI1\fP to \fIJ\fP), '\fIml\fP' for maximum
likelyhood, '\fIlapls\fP' for Lepskii's adaptive procedure least
square. The default value for \fIlrstr\fP is '\fIls\fP'.
The weights \fIw\fP or the sequence of variances \fIsigma2_j\fP must be
strictly positive and of size \f(CR[\fP1,J\f(CR]\fP or \f(CR[\fPJ,1\f(CR]\fP.
For the meaning of the variable optional input parameters
\fIsigma2_j\fP and \fIK\fP, see \fIlepskiiap\fP (Lepskii's Adaptive
Procedure) C_LAB routine's help.
The number of iterations \fII\fP must be \fI>=2\fP.
The variance of the normal weights \fIs\fP must be strictly positive.
If multiple least square, maximum likelyhood or Lepskii's adaptive
procedure least square is chosen, the estimated slope \fIa_hat\fP and
the ordinate at the origin \fIb_hat\fP are vectors of size
\f(CR[\fP1,J\f(CR]\fP, resp. the regressed ordinates \fIy_hat\fP and the
residuals \fIe_hat\fP vectors are of size \f(CR[\fP1,(J+2)*(J-1)/2\f(CR]\fP
(as they contains results for multiple linear regression, be aware of
that when vizualising them :-), see examples), otherwise there are
scalars, resp. vectors of size \f(CR[\fP1,J\f(CR]\fP. For maximum
likelyhood, multiple least square linear regressions are proceeded in
order to obtain variance estimates. Then maximum likelyhood linear
regression is proceeded (corresponding results are found in
\fIa_hat(1)\fP, \fIb_hat(1)\fP, \fIy_hat(1:J)\fP, \fIe_hat(1:J)\fP and
\fIsigma2_e_hat(1)\fP, see examples).
For the meaning of the variable optional output parameters
\fIK_star\fP, \fIj_hat\fP, \fII_c_j_min\fP, \fII_c_j_max\fP,
\fIE_c_j_max\fP, and \fIE_c_j_max\fP, see \fIlepskiiap\fP (Lepskii's
Adaptive Procedure) C_LAB routine's help.
.SH Algorithm details
For the details of the Lepskii's adaptive procedure, see
\fIlepskiiap\fP (Lepskii's Adaptive Procedure) C_LAB routine's help.
.SH Examples
.SH Matlab
.sp
.ft CR
.nf
J=32;
x=1+linspace(0,1,J);
% Wiener process
W=randn(1,J);
epsilon=.1;
y=x+epsilon*W;
% least square
[a_hat,b_hat,y_hat,e_hat,sigma2_e_hat]=monolr(x,y);
plot(x);hold on;plot(y);plot(y_hat,'kd');
plot(epsilon.*W);hold on;plot(e_hat);
title('least square');
disp('type return');
pause;
clf;
% weighted least square
epsilon=linspace(.05,.5,J);
y=x+epsilon.*W;
[a_hat,b_hat,y_hat,e_hat,sigma2_e_hat]=monolr(x,y,'wls',1./epsilon);
plot(x);hold on;plot(y);plot(y_hat,'kd');
plot(epsilon.*W);hold on;plot(e_hat);
title('weighted least square');
disp('type return');
pause;
clf;
% penalized least square
[a_hat,b_hat,y_hat,e_hat,sigma2_e_hat]=monolr(x,y,'pls',30);
plot(x);hold on;plot(y);plot(y_hat);
title('penalized least square');
disp('type return');
pause;
clf;
% multiple least square
[a_hat,b_hat,y_hat,e_hat,sigma2_e_hat]=monolr(x,y,'mls');
plot(x);hold on;plot(y)
start_j=0;
hold on;
for j=2:J
plot([1:j],y_hat(start_j+1:start_j+j),'k');
disp(['estimated slope a_hat =',num2str(a_hat(j))]);
disp('type return');
pause;
start_j=start_j+j;
j=j+1;
end
clf
% maximum likelyhood
[a_hat,b_hat,y_hat,e_hat,sigma2_e_hat]=monolr(x,y,'ml');
plot(x);hold on;plot(y_hat(1:J),'kd');
plot(epsilon.*W);hold on;plot(e_hat(1:J));
clf;
% Lespkii's adaptive procedure
epsilon=.01;
y(1:16)=x(1:16)+epsilon*W(1:16);
y(16:32)=2*x(16:32)+epsilon*W(16:32);
[a_hat,b_hat,y_hat,e_hat,sigma2_e_hat,K_star,j_hat,I_c_j_min,I_c_j_max,E_c_j_hat_min,E_c_j_hat_max]=monolr(x,y,'lapls');
plot(a_hat);
hold on;
plot(I_c_j_max,'r^');
plot(I_c_j_min,'gV');
title('LAP: estimator vs. index');
xlabel('index: j');
ylabel('estimator: \theta_j');
plot(j_hat,E_c_j_hat_min,'ko');
plot(j_hat,E_c_j_hat_max,'ko');
.fi
.ec
.ft P
.sp
.SH Scilab
.sp
.ft CR
.nf
//
.fi
.ec
.ft P
.sp
.SH References
To be published..SH See Also
\fBlepskiiap\fP (C_LAB routine).
|