📄 regcon.m
字号:
function [a,b] = regcon(mod,xmn,ymn,xst,yst);
%REGCON Converts regression model to y = ax + b form
% REGCON can be used to convert a model (mod) generated by
% the function MODLGUI. The outputs are the regression
% coefficients (a) and the intercept (b) such that
% y = ax + b. In this case the I/O syntax is:
%
%I/O: [a,b] = regcon(mod);
%
% REGCON can also be used to convert the individual parts of a
% regression model, including the column vector of regression
% coefficients (regv), predictor variable means (xmn),
% predicted variable means (ymn), predictor variable scaling
% (xst), and predicted variable scaling (yst). If xmn or ymn
% is not supplied or is set equal to 0 or [], then it is assumed
% to be zero (i.e. no centering was used in the model). If xst
% or yst is not supplied or is set equal to 0 or [], then it is
% assumed to be one (i.e. no scaling was used in the model).
%
%I/0: [a,b] = regcon(regv,xmn,ymn,xst,yst);
%
%Examples:
% [a,b] = regcon(mod); % using MODLGUI model
% [a,b] = regcon(regv,xmn,ymn); % mean centered only
% [a,b] = regcon(regv,xmn,ymn,xst,yst); % mean centered and scaled
% [a,b] = regcon(regv,xmn,ymn,[],yst); % x data centered but not scaled
% [a,b] = regcon(regv,0,0,xst,yst); % x and y scaled by not centered
%
%See also: AUTO, MNCN, MODLGUI, MODLPRED, MODLRDER, PCR, PLS, RIDGE, SIMPLS
%Copyright Eigenvector Research, Inc. 1997-98
%bmw 7/97
%bmw 3/98
%bmw 3/99
if strcmp(class(mod),'struct')
xmn = mod.meanx; ymn = mod.meany; xst = mod.stdx; yst = mod.stdy;
bb = mod.reg;
[nxv,nyv] = size(bb);
if strcmp(mod.scale,'mean') | strcmp(mod.scale,'none')
xst = ones(size(xst));
yst = ones(size(yst));
end
if strcmp(mod.scale,'none')
xmn = zeros(size(xmn));
ymn = zeros(size(ymn));
end
else
bb = mod;
[nxv,nyv] = size(mod);
if nargin == 1
xmn = 0; ymn = 0; xst = 0; yst = 0;
elseif nargin == 2
ymn = 0; xst = 0; yst = 0;
elseif nargin == 3
xst = 0; yst = 0;
elseif nargin == 4
yst = 0;
end
end
if (xmn == 0 | isempty(xmn))
xmn = zeros(1,nxv);
end
if (xst == 0 | isempty(xst))
xst = ones(1,nxv);
end
if (ymn == 0 | isempty(ymn))
ymn == zeros(1,nyv);
end
if (yst == 0 | isempty(yst))
yst = ones(1,nyv);
end
b = -((xmn./xst)*bb).*yst + ymn;
a = diag(yst)*(bb'./xst(ones(nyv,1),:));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -