How to specify a specific constant for a multiple linear regression?
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Khaled Ahmat
le 14 Oct 2017
Réponse apportée : Khaled Ahmat
le 17 Oct 2017
I would like to know if it is possible to specify a certain constant to a multiple linear regression abd how?
2 commentaires
Réponse acceptée
Image Analyst
le 14 Oct 2017
See John's answer. https://www.mathworks.com/matlabcentral/answers/274980-linear-fit-to-data-with-intercept-at-origin#answer_214651
You can fit y-43 instead of y, then do the fit and add back in the 43 to get yFitted .
4 commentaires
Jan
le 15 Oct 2017
@Khaled Ahmat: Please use flags only to inform editors and admins about contributions, which might conflict with the terms of use e.g. by rudeness. Thanks.
Plus de réponses (4)
Khaled Ahmat
le 15 Oct 2017
3 commentaires
Image Analyst
le 15 Oct 2017
But we already solved that in the first answer. If you don't know how to do it, then just attach vectors x1, x2, x3, and y in a .mat file.
Khaled Ahmat
le 15 Oct 2017
2 commentaires
Image Analyst
le 16 Oct 2017
Not familiar with regress(). Why didn't you use the method of John D'Errico?
Image Analyst
le 17 Oct 2017
I'm not sure I've got the columns correct for x1, x2, x3, and y, but this is essentially how you'd do it (again, thanks to John D'Errico):
% Read in data file.
data = importdata('Data_case1.txt')
% Extract columns into separate variables.
% Make sure the column numbers are the correct ones!!!!
x1 = data(:, 1);
x2 = data(:, 2);
x3 = data(:, 3);
y = data(:, 4);
% Construct x matrix
x = [x1, x2, x3];
% Construct y
y = y - 30;
% Get the cofficients:
coefficients = x \ y; % Estimate Parameter: x*coefficients = y
% Get fitted values for y. Be sure to add back in the 30 we subtracted!
y_estimated = x*coefficients + 30;
% Print them out
fprintf(' x1 x2 x3 y y_estimated\n');
for row = 1 : length(x1)
fprintf('%8.4f, %8.4f, %8.4f, %8.4f, %8.4f\n', ...
x1(row), x2(row), x3(row), y(row), y_estimated(row));
end
0 commentaires
Voir également
Catégories
En savoir plus sur Linear and Nonlinear Regression dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!