www.gusucode.com > mbcmodels 工具箱 matlab 源码程序 > mbcmodels/@xregtwostage/xregtwostage.m
function TS= xregtwostage(LMod,GMods,Datum,m) %XREGTWOSTAGE two-stage hierarchical model % % TS= xregtwostage(LMod,GMods,Datum,xregmodel); % TS= xregtwostage(LMod,m); % Copyright 2000-2007 The MathWorks, Inc. and Ford Global Technologies, Inc. loadstr=0; % empty covariance model cmodel= xregcovariance('','tscov'); if nargin== 0; % default properties LMod= localpspline([2 2]); set(LMod,'symbols',{'L1'}); m= xregcubic; GM= m; GMods= {m m m m}; Datum= m; nf= nfactors(LMod)+nfactors(GM); m= xregmodel('nfactors',nf); elseif nargin==1 && isstruct(LMod) % load old object (from loadobj) loadstr=1; TS= LMod; LMod= TS.Local; GMods= TS.Global; % Base model m= TS.xregmodel; if isempty(GMods) % no global models so make up base object ng= nfactors(TS.xregmodel)-nfactors(LMod); GM= xregcubic('nfactors',ng); set(GM,'order',zeros(1,ng)); cinps= getInputs(m); GM = setInputs(GM,cinps(nfactors(LMod)+1:end)); else GM= GMods{1}; end Datum= TS.datum; if isfield(TS,'PEV') % move PEV store to model PEV= TS.PEV; TS= rmfield(TS,'PEV'); % define model variance m= var(m,PEV,0,Inf); end if isfield(TS,'covmodel') % old covariance model cmodel= TS.covmodel; end % remove base model object so we can reconstruct this TS= rmfield(TS,'xregmodel'); elseif nargin==2 GM= GMods; if DatumType(LMod) Datum= GM; else Datum= []; end GMods= repmat({GM},numfeats(LMod),1); else GM= GMods{1}; end % version number TS.version= 3; if DatumType(LMod) LMod= datum(LMod,0); end % different models TS.Local= LMod; TS.Global= GMods; TS.datum= Datum; if nargin<4 && ~loadstr % define base model object m= xregCreateModel(@xregmodel,[getInputs(LMod);getInputs(GM)]); end % 2nd stage covariance model TS.covmodel= cmodel; % logical array indicating whether to consider the global error as a random effect TS.RandomEffects= true(length(TS.Global),1); TS=class(TS,'xregtwostage',m); if ~loadstr % update model info TS= copyToExternal(TS); end % needed for xregtwostage/plot superiorto('sweepset','double');