- 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
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (1)
Ronit
el 24 de Mayo de 2024
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 comentarios
Ver también
Categorías
Más información sobre Descriptive Statistics en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!