How can I calculate the Variance Inflation Factor (VIF) for a linear regression model
I have a long set of linear models developed from a space-filling DOE I ran. Many of the parameters in the DOE are correlated to different degrees and I’m interested in calculating the VIF of each parameter, and recalculating the model if the VIF for some parameters is high. I saw this code in another answer https://www.mathworks.com/matlabcentral/answers/1964984-tolerance-value-and-variance-inflation-factor-in-stepwiselm
% Define the predictors and response variable
X = [x1, x2, x3, x4, x5];
Y = y;
% Define the options for stepwise regression
options = statset(‘Display’,’iter’, ‘TolFun’, 0.01, ‘TolTypeFun’, ‘rel’, ‘PEnter’, 0.05, ‘PRemove’, 0.1);
% Run the stepwise regression with predefined multicollinearity threshold settings
mdl = stepwiselm(X, Y, ‘Criterion’, ‘bic’, ‘Upper’, ‘linear’, ‘Lower’, ‘constant’, ‘PEnter’, 0.05, ‘PRemove’, 0.1, ‘Verbose’, 1, ‘Options’, options);
% Check the multicollinearity
[vif, tolerance] = vif(mdl);
% Check for variable inclusion
included_vars = mdl.predictorNames(mdl.Coefficients.Estimate ~= 0);
However, I ran into a couple problems when trying to execute this snippet.
1) statset doesn’t take ‘PEnter’ or ‘PRemove’ as arguments. Removing those two arguments allowed that line to run.
2) stepwiselm doesn’t seem to take ‘Options’ as a valid argument
3) I can’t seem to find a function called vif that takes a linear model object as an argument
I have the curve fitting, data acquisition, deep learning, and statistics toolboxes installed. If there is another toolbox with applicable functions I can install that as well.I have a long set of linear models developed from a space-filling DOE I ran. Many of the parameters in the DOE are correlated to different degrees and I’m interested in calculating the VIF of each parameter, and recalculating the model if the VIF for some parameters is high. I saw this code in another answer https://www.mathworks.com/matlabcentral/answers/1964984-tolerance-value-and-variance-inflation-factor-in-stepwiselm
% Define the predictors and response variable
X = [x1, x2, x3, x4, x5];
Y = y;
% Define the options for stepwise regression
options = statset(‘Display’,’iter’, ‘TolFun’, 0.01, ‘TolTypeFun’, ‘rel’, ‘PEnter’, 0.05, ‘PRemove’, 0.1);
% Run the stepwise regression with predefined multicollinearity threshold settings
mdl = stepwiselm(X, Y, ‘Criterion’, ‘bic’, ‘Upper’, ‘linear’, ‘Lower’, ‘constant’, ‘PEnter’, 0.05, ‘PRemove’, 0.1, ‘Verbose’, 1, ‘Options’, options);
% Check the multicollinearity
[vif, tolerance] = vif(mdl);
% Check for variable inclusion
included_vars = mdl.predictorNames(mdl.Coefficients.Estimate ~= 0);
However, I ran into a couple problems when trying to execute this snippet.
1) statset doesn’t take ‘PEnter’ or ‘PRemove’ as arguments. Removing those two arguments allowed that line to run.
2) stepwiselm doesn’t seem to take ‘Options’ as a valid argument
3) I can’t seem to find a function called vif that takes a linear model object as an argument
I have the curve fitting, data acquisition, deep learning, and statistics toolboxes installed. If there is another toolbox with applicable functions I can install that as well. I have a long set of linear models developed from a space-filling DOE I ran. Many of the parameters in the DOE are correlated to different degrees and I’m interested in calculating the VIF of each parameter, and recalculating the model if the VIF for some parameters is high. I saw this code in another answer https://www.mathworks.com/matlabcentral/answers/1964984-tolerance-value-and-variance-inflation-factor-in-stepwiselm
% Define the predictors and response variable
X = [x1, x2, x3, x4, x5];
Y = y;
% Define the options for stepwise regression
options = statset(‘Display’,’iter’, ‘TolFun’, 0.01, ‘TolTypeFun’, ‘rel’, ‘PEnter’, 0.05, ‘PRemove’, 0.1);
% Run the stepwise regression with predefined multicollinearity threshold settings
mdl = stepwiselm(X, Y, ‘Criterion’, ‘bic’, ‘Upper’, ‘linear’, ‘Lower’, ‘constant’, ‘PEnter’, 0.05, ‘PRemove’, 0.1, ‘Verbose’, 1, ‘Options’, options);
% Check the multicollinearity
[vif, tolerance] = vif(mdl);
% Check for variable inclusion
included_vars = mdl.predictorNames(mdl.Coefficients.Estimate ~= 0);
However, I ran into a couple problems when trying to execute this snippet.
1) statset doesn’t take ‘PEnter’ or ‘PRemove’ as arguments. Removing those two arguments allowed that line to run.
2) stepwiselm doesn’t seem to take ‘Options’ as a valid argument
3) I can’t seem to find a function called vif that takes a linear model object as an argument
I have the curve fitting, data acquisition, deep learning, and statistics toolboxes installed. If there is another toolbox with applicable functions I can install that as well. regression, curve fitting MATLAB Answers — New Questions









