- Setup the environment and generate data.
- Run stepwise multivariate regression - using “stepwiselm”.
- Identify the best explanatory variables - You can extract these variables directly from the model.
- Run another regression with selected variables.
How to do a stepwise multivariate regression analysis with random variables
조회 수: 2 (최근 30일)
이전 댓글 표시
Hey folks!
I would like to run a stepwise multivariate regression analysis with random variables using:
rng(10, 'twister')
I tried to to create 100 normally distributed random variables with 100 observations per variable.
Runned it like this format but couldn't do it: y = a + b1 * x1 + b2 * x2 + ... + b100 * x100 + u
There 5 best explanatory variables should be kind of picked and used to run another regression:
y = a + b1 * z1 + b2 * z2 + ... + b5 * z5 + v
I would very much appreciate any input and help! Thanks!
댓글 수: 0
답변 (1개)
Ronit
2024년 5월 24일
Hello,
To conduct a stepwise multivariate regression analysis with random variables as you have described, the process involves generating random variables, running the stepwise regression to identify 5 best variables, and then running another regression with the selected variables. Following is the overview of the steps:
Following is a sample code for above mentioned steps:
% Initialize the random number generator for reproducibility
rng(10, 'twister');
X = randn(100, 100); % 100 observations of 100 variables
% For simplicity, let's assume y is a linear combination of some variables in X plus some noise
coefficients = randn(100, 1); % Random coefficients for the 100 predictors
noise = randn(100, 1); % Random noise
y = X * coefficients + noise; % Linear model
% Running stepwise linear regression
model = stepwiselm(X, y, 'linear', 'Criterion', 'bic', 'Upper', 'interactions', 'Verbose', 2);
% For example, let's say the indices are 1, 2, 3, 4, 5 for simplicity
Z = X(:, [1, 2, 3, 4, 5]);
% Run the regression with the selected variables
finalModel = fitlm(Z, y);
For more information regarding the models used, refer to the following links:
Hope this helps!
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Regression에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!