statistics: stepwisefit (X, y)
statistics: b = stepwisefit (X, y)
statistics: b, se, pval, finalmodel, stats, nextstep, history = stepwisefit (X, y, varargin)
Perform stepwise linear regression using conditional p-value criteria.
stepwisefit fits a linear regression model to response vector
y using predictor matrix X and performs stepwise variable
selection based on hypothesis tests for individual regression coefficients.
At each iteration, predictors not currently in the model are tested for
inclusion using partial F- or t-tests. The predictor with the smallest
p-value below the entry threshold is added. Predictors currently in the
model (excluding forced predictors) are then tested for removal, and the
predictor with the largest p-value exceeding the removal threshold is
removed. The procedure repeats until the model stabilizes or the maximum
number of iterations is reached.
After variable selection, the final regression model is refit using
regress to compute coefficient estimates and inferential statistics
for both included and excluded predictors.
Arguments
-
X is an n-by-p numeric matrix of predictor variables.
-
y is an n-by-1 numeric response vector.
-
Optional Name–Value pairs may be supplied to control the stepwise
selection procedure.
Name–Value Arguments
-
'InModel'
- Logical row vector of length p specifying predictors that are initially
included in the model.
-
'Keep'
- Logical row vector of length p specifying predictors that must remain
in the model and are never removed during stepwise selection.
-
'PEnter'
- Scalar significance level in the open interval (0,1) specifying the maximum
p-value required for a predictor to enter the model. Default is
0.05.
-
'PRemove'
- Scalar significance level in the open interval (0,1) specifying the minimum
p-value required for a predictor to be removed from the model. If not
specified, a default value greater than or equal to
'PEnter' is used.
-
'MaxIter'
- Positive integer specifying the maximum number of stepwise iterations.
Default is
Inf.
-
'Scale'
- Either
'on' or 'off'. When enabled, predictors are
standardized prior to stepwise selection only. Final regression
coefficients are always reported on the original data scale.
-
'Display'
- Either
'on' or 'off'. Accepted for compatibility but
currently does not affect output.
Return Values
-
b is a p-by-1 vector of regression coefficients. Coefficients
for excluded predictors are computed conditionally.
-
se is a p-by-1 vector of standard errors.
-
pval is a p-by-1 vector of two-sided p-values.
-
finalmodel is a logical row vector indicating which predictors are
included in the final model.
-
stats is a structure containing regression diagnostics, including
sums of squares, degrees of freedom, residuals, covariance estimates,
F-statistic, and related quantities.
-
nextstep is a scalar indicating whether an additional stepwise
iteration is recommended. Currently always zero.
-
history is a structure summarizing the final model state, including
selected predictors and coefficient history.
See also:
regress
Source Code:
stepwisefit