How to create a multiple linear regression model

14 visualizaciones (últimos 30 días)
Keegan Carvalho
Keegan Carvalho el 27 de Jun. de 2018
Respondida: Ameer Hamza el 27 de Jun. de 2018
I wanted to create a regression model in which sl = sst+at+vlm (Column headings in the csv file). I have attached the csv file and will be grateful if someone could provide me with the code. I wanted to get a formula like y = 1 +ax1 +bx2 +cx3.
Thanks!
  3 comentarios
Keegan Carvalho
Keegan Carvalho el 27 de Jun. de 2018
Editada: dpb el 27 de Jun. de 2018
Actually i tried it but I'm a little confused on the result.
Estimate SE tStat pValue
________ _______ _______ ________
(Intercept) 8477.6 4797.1 1.7672 0.098969
x1 39.134 46.506 0.84148 0.41422
x2 128.31 80.696 1.59 0.13415
x3 -0.86657 0.61528 -1.4084 0.18083
This is what I got.
I used the following code:
data=readtable('seyreg.csv')
X = [data.sst,data.at,data.vlm]
lm = fitlm(X,data.sl,'linear')
Is this correct?
Adam Danz
Adam Danz el 27 de Jun. de 2018
What are you confused about and is what correct? Your code along with your data should produce those results. Interpreting those results is a whole other story that can't be told without knowing more background information. Is there something unexpected in the output?
If you're having trouble understanding the output table or are uncertain of the inputs to the model, read the matlab literature on fitlm .
If your uncertainty is due to not understanding linear models it would be helpful to read a chapter about them or watch some introductory videos.
If there's a more specific question about the matlab code or function, people may be able to help more.

Iniciar sesión para comentar.

Respuestas (1)

Ameer Hamza
Ameer Hamza el 27 de Jun. de 2018
Your use of fitlm() is correct. Alternatively, if you don't need all the extra information provided by fitlm() and speed is a concern then you can use MATLAB mldivide (\.) to solve it more efficiently.
data = readtable('seyreg.csv');
X = [data.sst data.at data.vlm ones(size(data.sst))];
Y = data.sl;
coefficient = X\Y;
the coefficient are in same order as the column of X.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by