Multiple Regression and Intercept
4 次查看(过去 30 天)
显示 更早的评论
% 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 个评论
回答(1 个)
Star Strider
2024-5-25
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 个评论
Star Strider
2024-5-27
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.)
.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Linear and Nonlinear Regression 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!