How to specify a specific constant for a multiple linear regression?

1 visualización (últimos 30 días)
I would like to know if it is possible to specify a certain constant to a multiple linear regression abd how?
  2 comentarios
jean claude
jean claude el 14 de Oct. de 2017
would you clarify your question with an example that we can help ?
Khaled Ahmat
Khaled Ahmat el 14 de Oct. de 2017
I have a multiple linear regression using three predictor variables, say x1,x2,x3 the resulting equation is y=43-1.4x1+3.8x2-1.1x3 due to some presentation reasons I want to force the constant to be 30 instead of 43; so that the resulting equation becomes y=30-ax1+bx2-cx3;
is this possible in MATLAB?

Iniciar sesión para comentar.

Respuesta aceptada

Image Analyst
Image Analyst el 14 de Oct. de 2017
You can fit y-43 instead of y, then do the fit and add back in the 43 to get yFitted .
  4 comentarios
Jan
Jan el 15 de Oct. de 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.

Iniciar sesión para comentar.

Más respuestas (4)

Khaled Ahmat
Khaled Ahmat el 15 de Oct. de 2017
Thank you very much for your suggestion; my next question is how to run a Multiple linear regression without a constant in MATLAB? Is it the same function Regress(y,x) or there is another function for regression without a constant? Thank you in advance
  3 comentarios
Khaled Ahmat
Khaled Ahmat el 15 de Oct. de 2017
Editada: Khaled Ahmat el 15 de Oct. de 2017
Yes it is a Multiple linear regression, but my question is how to make it with a zero constant in MATLAB
Image Analyst
Image Analyst el 15 de Oct. de 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.

Iniciar sesión para comentar.


Khaled Ahmat
Khaled Ahmat el 15 de Oct. de 2017
The m.file along with the data file is attached. Thank you for your effort
  2 comentarios
Image Analyst
Image Analyst el 16 de Oct. de 2017
Not familiar with regress(). Why didn't you use the method of John D'Errico?
Khaled Ahmat
Khaled Ahmat el 16 de Oct. de 2017
Editada: Khaled Ahmat el 16 de Oct. de 2017
Actually I liked the method he which proposed y-30= ax1+bx2+cx3; and I am sure that there is a function in MATLAB for linear regression without a constant but now I am not able to get the function in MATLAB! This my Challenge now. If Mr John D'Errico can give us a clue about the function or an example it would be great

Iniciar sesión para comentar.


Image Analyst
Image Analyst el 17 de Oct. de 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

Khaled Ahmat
Khaled Ahmat el 17 de Oct. de 2017
It worked, thank you very much! Really appreciate it.

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!

Translated by