Function Reference: ridge

statistics: b = ridge (y, X, k)
statistics: b = ridge (y, X, k, scaled)

Ridge regression.

b = ridge (y, X, k) returns the vector of coefficient estimates by applying ridge regression from the predictor matrix X to the response vector y. Each value of b is the coefficient for the respective ridge parameter given k. By default, b is calculated after centering and scaling the predictors to have a zero mean and standard deviation 1.

b = ridge (y, X, k, scaled) performs the regression with the specified scaling of the coefficient estimates b. When scaled = 0, the function restores the coefficients to the scale of the original data thus is more useful for making predictions. When scaled = 1, the coefficient estimates correspond to the scaled centered data.

  • y must be an N×1 numeric vector with the response data.
  • X must be an N×p numeric matrix with the predictor data.
  • k must be a numeric vectir with the ridge parameters.
  • scaled must be a numeric scalar indicating whether the coefficient estimates in b are restored to the scale of the original data. By default, scaled = 1.

Further information about Ridge regression can be found at https://en.wikipedia.org/wiki/Ridge_regression

See also: lasso, stepwisefit, regress

Source Code: ridge

Example: 1

 

 ## Add some description here!!

 load acetylene

 X = [x1, x2, x3];

 x0 = ones (16, 1);
 x1x2 = x1 .* x2;
 x1x3 = x1 .* x3;
 x2x3 = x2 .* x3;

 D = [x1, x2, x3, x1x2, x1x3, x2x3];

 k = 0:1e-5:5e-3;

 b = ridge (y, D, k);

 figure
 plot (k, b, "LineWidth", 2)
 ylim ([-100, 100])
 grid on
 xlabel ("Ridge Parameter")
 ylabel ("Standardized Coefficient")
 title ("Ridge Trace")
 legend ("x1", "x2", "x3", "x1x2", "x1x3", "x2x3")

                    
plotted figure