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.
채택된 답변
추가 답변 (1개)
That is a very peculiar response from a MathWorks staff person, indeed. stepwiselm documentation doesn't support the use of the statset object nor does statset doc from R2022b to current indicate the stepwise linear model parameters are in its repertoire(*).
However, 'PEnter' and 'PRemove' are valid parameters, so recast your code to not use statset at all, but pass all parameters directly into stepwiselm
which -all stepwiselm
There appears still to be only the one Mathworks-supplied version ; this is the same result I get with R2022b and earlier and the doc is also the same.
Might be worth a poke at official support referencing the prior post and asking about that syntax and making necessary corrections there so somebody else doesn't get blindsided later on, too.
(*) It also seems as though an enhancement request to for these to be extended would not be out of order; it would help reqgularize syntax across the family of fitting functions.
카테고리
도움말 센터 및 File Exchange에서 Gaussian Process Regression에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!