Multiple Regression and Intercept
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
% Load the data from the Excel file
data = readtable('데이터(최종).xlsx', 'Sheet', 'Sheet5');
% Define the dependent variable
y = data.Arrive;
% Define the independent variables
X = [data.Price_m, data.Volme, data.Relative_y, data.Relative_m, ...
data.mine, data.debt, data.Quin, data.Cpi, data.Rate, data.Depo, ...
data.Bull, data.Sale, data.Move, data.Sub];
% Add a column of ones to the independent variables matrix for the intercept
X = [ones(size(X, 1), 1), X];
% Perform the multiple linear regression
[b, ~, ~, ~, stats] = regress(y, X);
% Display the results
disp('Regression Coefficients:');
disp(b);
disp('R-squared:');
disp(stats(1));
disp('F-statistic:');
disp(stats(2));
disp('p-value:');
disp(stats(3));
disp('Error Variance:');
disp(stats(4));
I'm going to proceed with a multilinear regression analysis with the data string called Arrive as the dependent variable, and the result is as follows. Is it ok...?
disp(stats(4));
Regression Coefficients:
1.0e+06 *
4.1453
-0.0190
0.0040
-0.0960
-0.6115
-0.0022
-0.0140
0.0259
0.0070
-0.0602
-0.0196
-0.0003
-0.0000
0.0000
0.0000
R-squared:
0.3997
F-statistic:
4.5189
p-value:
3.5809e-06
Error Variance:
3.8687e+09
0 comentarios
Respuestas (1)
Star Strider
el 25 de Mayo de 2024
I see nothing wrong with the code, and it conforms to the example in the regress documentation.
The only suggestion I have is to use table indexing to replace the initial ‘X’ so —
data = readtable('데이터(최종).xlsx', 'Sheet', 'Sheet5')
% Define the dependent variable
y = data.Arrive;
% Add a column of ones to the independent variables matrix for the intercept, Add a column of ones to the independent variables matrix for the intercept
X = [ones(size(data{:,1})) data{:,3:end}];
% Perform the multiple linear regression
[b, ~, ~, ~, stats] = regress(y, X);
% Display the results
disp('Regression Coefficients:');
disp(b);
disp('R-squared:');
disp(stats(1));
disp('F-statistic:');
disp(stats(2));
disp('p-value:');
disp(stats(3));
disp('Error Variance:');
disp(stats(4));
This is slightly more efficient code, and the result is the same.
.
2 comentarios
Star Strider
el 27 de Mayo de 2024
There is a problem with statistical significance, because only four variables (including the Intercept term) are statistically significant, in the usual sense of having . I used fitlm to get those statistics —
data = readtable('데이터(최종).xlsx', 'Sheet', 'Sheet5')
% Define the dependent variable
y = data.Arrive;
% Add a column of ones to the independent variables matrix for the intercept, Add a column of ones to the independent variables matrix for the intercept
X = [ones(size(data{:,1})) data{:,3:end}];
% Perform the multiple linear regression
[b, ~, ~, ~, stats] = regress(y, X);
% Display the results
disp('Regression Coefficients:');
disp(b);
disp('R-squared:');
disp(stats(1));
disp('F-statistic:');
disp(stats(2));
disp('p-value:');
disp(stats(3));
disp('Error Variance:');
disp(stats(4));
VN = data.Properties.VariableNames;
mdl = fitlm(data{:,3:end}, data.Arrive, 'VarNames',{VN{3:end},VN{2}})
Significant_Independent_Variables = mdl.CoefficientNames(mdl.Coefficients.pValue <= 0.05)
However considering the F-statistic, the regression itself is highly significant.
These are your data. I defer to you to interprret them and the regression results. (I am not even certain what the variables are.)
.
Ver también
Categorías
Más información sobre Linear and Nonlinear Regression 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!