www.gusucode.com > mbcmodels 工具箱 matlab 源码程序 > mbcmodels/@xreglinear/InitStore.m
function [m,OK]= InitStore(m,x,y,bd,doRinvCalc) %INITSTORE initialises model for use by stats and leastsq % Copyright 2000-2006 The MathWorks, Inc. and Ford Global Technologies, Inc. if nargin<5 doRinvCalc= true; end m.Store= struct('y',[],... 'X',[],... 'D',[],... 'Q',[],... 'R',[],... 'H',[],... 'Wc',[],... 'DispOrder',0,... 'mse',[]); if nargin>=3 m.Store.y= ytrans(m,y); if nargin > 3 if ~islogical(bd) BDL= false(size(x,1),1); BDL(bd)= true; else BDL= bd; end m.Store.y(BDL)= NaN; else BDL= ~isfinite(m.Store.y); end x(BDL,:)= []; else BDL= false(size(x,1),1); end m.Store.D= x; if ~isempty(x) FX= x2fx(m,x); m.Store.X= FX; % DispOrder==0 implies use model term order % rather than more logical user display order m.Store.DispOrder=0; t= ~m.TermsOut; FX= FX(:,t); if doRinvCalc [Q,R,OK,df,Ri]= qrdecomp(m,x,[],FX); else [Q,R,OK,df]= qrdecomp(m,x,[],FX); end else df= 0; m.Store.X= []; m.Store.DispOrder=0; Q=[]; R=[]; Ri=[]; OK=0; end m.Store.Q= Q; m.Store.R= R; H= zeros(size(BDL,1),1); if OK && ~all(m.TermsOut) H(~BDL)= sum(Q.*Q,2); end m.Store.H= H; if nargin>=3 && OK % calculate MSE y= m.Store.y(isfinite(y)); %pad y r= y- Q*(Q'*y); if df>0 mse= sum(r.^2)/df; else mse=0; end m.Store.mse = mse; else mse=1; m.Store.mse= []; end if doRinvCalc if OK % store variance info m= var(m,Ri*sqrt(mse),m.Store.mse,df); else m= var(m,[],0,Inf); end end