www.gusucode.com > mbcmodels 工具箱 matlab 源码程序 > mbcmodels/@xreglinear/summary.m
function [s,list,SummStatsType,Description] = summary(m,Criteria,x,y,s2full,s2mle) %SUMMARY Calculate summary statistics % % [s,list,SummStats] = summary(m,Criteria,x,y); % [s,list,SummStats] = summary(m,Criteria,x,y,s2full); % [MINorMAX,list,SummStatsType] = summary(m) returns a list of criteria % and whether to use as summary: % -1 special calculation done differently in summary stats % 1 use as calculated % 2 only compare if data and transforms the same for all models % 0 don't use for comparison in summary table (only in prune) % % Criteria list = {'PRESS RMSE','RMSE','GCV','Weighted PRESS',... % '-2logL','AIC','AICc','BIC','R^2','R^2 adj','Cp','cond(J)'} % Copyright 2000-2015 The MathWorks, Inc. and Ford Global Technologies, Inc. list= {'PRESS RMSE','RMSE','GCV','Weighted PRESS','-2logL','AIC','AICc','BIC','R^2','R^2 adj','PRESS R^2','DW','Cp','cond(J)'}; SummStatsType= [-1 -1 1 1 2 2 2 2 1 1 1 1 0 1]; if nargout>3 Description= {'Predicted Standard Error' 'sqrt(PRESS/N)' 'Root Mean Square Error' 'sqrt(SSE/(N-p))' 'Generalized Cross-validation Variance' 'N*SSE/(N-p)^2' 'Weighted Predicted Standard Error' 'sqrt(PRESS/(N-p-1))' '-2 * log likelihood' 'N*log(SSE/N)' 'Akaike Information Criteria' '-2logL + 2*(p+1)' 'Small Sample Akaike Information Criteria' '-2logL + 2(p+1)*N/(N-p)' 'Bayesian Information Criteria' '-2logL + 2*log(N)*(p+1)' 'R^2' '1 - SSE/SST' 'Adjusted R^2' '1 - SSE/SST*(N-1)/(N-p)' 'PRESS R^2' '1 - PRESS/SST' 'Durbin-Watson Statistic' 'sum((e_i-e_{i+1})^2)/sum((e_i^2) ' 'Mallow''s Statistic' 'SSE/(SSEmax/(N-pmax)) - N + 2*p' 'Condition of Regression Matrix' 'cond(J)'}; end if nargin<2 % true indicates minimise and false maximise s= true(size(list)); s(9:11)= false; return end if isempty(m.Store) m = InitModel(m,x,y,[],false); end if nargin<4 || isempty(x); x= m.Store.D; y= m.Store.y; end if ischar(Criteria) switch lower(Criteria) case 'all' sel= 1:length(list); case 'data' sel= find(abs(SummStatsType)~=1); case 'summary' sel= find(abs(SummStatsType)~=0); case 'multi' sel= find(SummStatsType<=0); otherwise sel= find(ismember(list,Criteria)); end elseif iscell(Criteria) sel= find(ismember(list,Criteria)); elseif islogical(Criteria) sel= find(Criteria); else sel= Criteria; end nObs=size(y,1); [~,mse,df] = var(m);% degrees of freedom [anova,R2,R2adj] = AnovaTable(m); sst= anova(end,1); sse= anova(2,1); if nargin<6 s2mle= sse/nObs; end if nargin<5 s2full = mse; end s= NaN(1,length(sel)); for i=1:length(sel) switch sel(i) case 1 % PRESS RMSE s(i) = NaturalPressRMSE(m,x,y); case 2 % RMSE s(i) = NaturalRMSE(m,x,y); case 3 % GCV s(i) = calcGCV(m); case 4 % Weighted PRESS if df>1 s(i) = sqrt(press(m,y)/(df-1)); end case 5 % log likelihood actually -2logL if s2mle>0 s(i)= nObs*log(s2mle); end case 6 % Akaike Information Criteria K= nObs-df+1; % note variance is included as a parameter if s2mle>0 s(i) = nObs*log(s2mle) + 2*K; end case 7 % AICc Akaike Information Criteria for small samples K= nObs-df+1; if s2mle>0 && nObs>K+1 s(i) = nObs*log(s2mle) + 2*K*nObs/(nObs-K-1); end case 8 % Bayesian Information Criteria K= nObs-df+1; if s2mle>0 s(i) = nObs*log(s2mle) + log(nObs)*K; end case 9 % R^2 s(i)= R2; case 10 %Adjusted R-squared statistic s(i)= R2adj; case 11 if sst>0 s(i)= 1-press(m,y)/sst; else s(i)= 1; end case 12 % Durban-Watson yhat= eval(m,x); r= y - yhat; s(i)= sum( (r(1:end-1)- r(2:end)).^2 ) /sum(r.^2); case 13 % Mallow's Statistic s(i)= sse/s2full - df + numParams(m); case 14 % condition of Jacobian J = CalcJacob(m,x); if all(isfinite(J(:))) if issparse(J) s(i) = condest(J); else s(i) = cond(J); end end end end