Regcon: Difference between revisions

From Eigenvector Research Documentation Wiki
Jump to navigation Jump to search
imported>Jeremy
(Importing text file)
 
imported>Donal
 
(13 intermediate revisions by 3 users not shown)
Line 1: Line 1:
===Purpose===
===Purpose===
Converts a regression model to y = ax + b form.
Converts a regression model to y = ax + b form.
===Synopsis===
===Synopsis===
:[a,b] = regcon(mod)
 
:[a,b] = regcon(regv,xmn,ymn)
:[a,b] = regcon(mod)   % using REGRESSION model
:[a,b] = regcon(regv,xmn,ymn,xst,yst)
:[a,b] = regcon(regv,xmn,ymn)   % mean centered only
:[a,b] = regcon(regv,xmn,ymn,xst,yst)   % mean centered and scaled
 
 
===Description===
===Description===
REGCON can be used to convert a model mod generated by the PCR, PLS, or ANALYSIS functions. The outputs are the regression coefficients a and the intercept b such that y = ax + b. In this case the I/O syntax is:
 
:[a,b] = regcon(mod)
'''regcon''' can be used to convert a model <tt>mod</tt> generated by the [[pcr]], [[pls]], or [[mlr]] analysis functions, into a form expressed by the linear equation y = ax + b, where x and y are raw (not preprocessed) data.
Notes:  
 
(1) REGCON can will convert a regression model which uses Mean Centering, Autoscaling, or None as the preprocessing. Any other preprocessing will be rejected and cause an error.
'''NOTES:'''
(2) If the model was built with some variables excluded, REGCON will infill with zeros as appropriate so that the output can be used on the original X-block with all variables present.
 
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). In this case the I/O syntax is:
:(1) '''IMPORTANT''': '''regcon''' can only convert a regression model which uses Mean Centering, Autoscaling, or None as the preprocessing. Any other preprocessing will be rejected and cause an error.
:[a,b] = regcon(regv,xmn,ymn,xst,yst)
:(2) If the model was built with some variables excluded, '''regcon''' will infill with zeros as appropriate so that the output can be used on the original X-block with all variables present.
:(3) Note that the command to use in Matlab is actually in the form y = a*x' + b, not y = a*x + b.
:(4) The regression vector returned by regcon is based on raw data. It can be numerically different from the regression vector shown in the Analysis window's Loadings Plot since this plot shows the regression vector based on preprocessed data.
 
Alternatively, '''regcon''' can be used to convert the individual parts of a regression model, including the vector of regression coefficients <tt>regv</tt> and the means and scaling factors of the x- and y-block variables, to y = ax + b form. 
 
====Inputs====
 
* '''mod''' = model structure that was generated by [[pls]], [[pcr]], or [[mlr]]
 
Alternatively, the following 5 individual parts of a regression model can be used as inputs:
 
* '''regv''' = column vector of regression coefficients
* '''xmn''' = predictor variable means
* '''ymn''' = predicted variable means
* '''xst''' = predictor variable scaling
* '''yst''' = predicted variable scaling
 
'''Note:''' 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).
 
====Outputs====
 
* '''a''' = regression coefficients (a, in y = ax + b)
* '''b''' = intercept (b, in y = ax + b)
 
===Examples===
===Examples===
[a,b] = regcon(mod);                using REGRESSION model
 
[a,b] = regcon(regv,xmn,ymn);      mean centered only
:[a,b] = regcon(mod);                using REGRESSION model
[a,b] = regcon(regv,xmn,ymn,xst,yst); mean centered and scaled
:[a,b] = regcon(regv,xmn,ymn);      mean centered only
[a,b] = regcon(regv,xmn,ymn,[],yst); x data centered but not scaled
:[a,b] = regcon(regv,xmn,ymn,xst,yst); mean centered and scaled
[a,b] = regcon(regv,0,0,xst,yst);  x and y scaled by not centered
:[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
 
<pre>
%---
% Use REGCON to get a PLS model's regression vector and intercept, then apply
% it to X-block data to get predicted Y values.
% REGCON takes care of preprocessing details provided the preprocessing used was
% either Mean Centering, Autoscaling, or None (see note 1, above).
%
% Run the plsdemo to generate a PLS model:
pause off; plsdemo; pause on; close all
% This builds a PLS model using xblock1 and yblock1 as calibration X and Y
 
% Use regcon to get the regression parameters
[a,b] = regcon(model);
 
% Use the regcon output to predict y from the calibration X-block:
y1 = a*xblock1.data' + b;
% Verify y predicted by the regression equation (regcon) is the same as PLS model's ypred
comparevars(model.pred{2}, y1')
% or view them:
% [model.pred{2} y1']
 
% Do the same comparison using the validation X-block data, xblock2.
% The PLS-predicted y is in valid.pred{2}.
yt1 = a*xblock2.data' + b;
comparevars(valid.pred{2}, yt1')
% [valid.pred{2} yt1']
%---
</pre>
 
===See Also===
===See Also===
[[analysis]], [[auto]], [[mncn]], [[modlpred]], [[modlrder]], [[pcr]], [[pls]], [[ridge]]
 
[[analysis]], [[auto]], [[mncn]], [[modlpred]], [[modlrder]], [[pcr]], [[pls]], [[mlr]]

Latest revision as of 21:47, 22 August 2016

Purpose

Converts a regression model to y = ax + b form.

Synopsis

[a,b] = regcon(mod)  % using REGRESSION model
[a,b] = regcon(regv,xmn,ymn)  % mean centered only
[a,b] = regcon(regv,xmn,ymn,xst,yst)  % mean centered and scaled


Description

regcon can be used to convert a model mod generated by the pcr, pls, or mlr analysis functions, into a form expressed by the linear equation y = ax + b, where x and y are raw (not preprocessed) data.

NOTES:

(1) IMPORTANT: regcon can only convert a regression model which uses Mean Centering, Autoscaling, or None as the preprocessing. Any other preprocessing will be rejected and cause an error.
(2) If the model was built with some variables excluded, regcon will infill with zeros as appropriate so that the output can be used on the original X-block with all variables present.
(3) Note that the command to use in Matlab is actually in the form y = a*x' + b, not y = a*x + b.
(4) The regression vector returned by regcon is based on raw data. It can be numerically different from the regression vector shown in the Analysis window's Loadings Plot since this plot shows the regression vector based on preprocessed data.

Alternatively, regcon can be used to convert the individual parts of a regression model, including the vector of regression coefficients regv and the means and scaling factors of the x- and y-block variables, to y = ax + b form.

Inputs

  • mod = model structure that was generated by pls, pcr, or mlr

Alternatively, the following 5 individual parts of a regression model can be used as inputs:

  • regv = column vector of regression coefficients
  • xmn = predictor variable means
  • ymn = predicted variable means
  • xst = predictor variable scaling
  • yst = predicted variable scaling

Note: 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).

Outputs

  • a = regression coefficients (a, in y = ax + b)
  • b = intercept (b, in y = ax + b)

Examples

[a,b] = regcon(mod); using REGRESSION 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
%---
% Use REGCON to get a PLS model's regression vector and intercept, then apply 
% it to X-block data to get predicted Y values. 
% REGCON takes care of preprocessing details provided the preprocessing used was 
% either Mean Centering, Autoscaling, or None (see note 1, above).
%
% Run the plsdemo to generate a PLS model:
pause off; plsdemo; pause on; close all
% This builds a PLS model using xblock1 and yblock1 as calibration X and Y

% Use regcon to get the regression parameters
[a,b] = regcon(model);

% Use the regcon output to predict y from the calibration X-block:
y1 = a*xblock1.data' + b;
% Verify y predicted by the regression equation (regcon) is the same as PLS model's ypred
comparevars(model.pred{2}, y1')
% or view them:
% [model.pred{2} y1']

% Do the same comparison using the validation X-block data, xblock2. 
% The PLS-predicted y is in valid.pred{2}.
yt1 = a*xblock2.data' + b;
comparevars(valid.pred{2}, yt1')
% [valid.pred{2} yt1']
%---

See Also

analysis, auto, mncn, modlpred, modlrder, pcr, pls, mlr