Borrar filtros
Borrar filtros

simple regression analysis issue

3 visualizaciones (últimos 30 días)
Coleman Hiett
Coleman Hiett el 16 de Sept. de 2022
Editada: the cyclist el 16 de Sept. de 2022
I am trying to get a simple regression analysis to work, using the \ operator, following the example in this page: https://www.mathworks.com/help/matlab/data_analysis/linear-regression.html
Somehow my regression coefficient is not coming up correct, it has an opposite slope and the value is off. Can someone help me figure out what I'm doing wrong?
Ultimately, I hope to run a loop and find the regression coeffecients between a column vector and a large number of other column vectors pulled from an array, but I need to first pass this simple test...
y = [-38.34; -42.48; -52.71; -49.72];
x = [69.482; 60.645; 37.093; 42.889];
b1 = x\y;
yreg = b1*x;
scatter(x,y)
hold on
plot(x,yreg)

Respuesta aceptada

the cyclist
the cyclist el 16 de Sept. de 2022
Editada: the cyclist el 16 de Sept. de 2022
The method you used does not include an intercept, so your fit is forced to go through the origin. Try this instead (which is also on that documentation page).
y = [-38.34; -42.48; -52.71; -49.72];
x = [69.482; 60.645; 37.093; 42.889];
X = [ones(size(x)), x];
b1 = X\y;
yreg = X*b1;
scatter(x,y)
hold on
plot(x,yreg)
  1 comentario
Coleman Hiett
Coleman Hiett el 16 de Sept. de 2022
duhh! thanks for your help. I knew it would be something obvious that I wan't seeing...

Iniciar sesión para comentar.

Más respuestas (0)

Productos


Versión

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by