how can i find the slope of a regression line
19 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Omer hakan Yaran
il 17 Apr 2023
Commentato: Adam Danz
il 28 Apr 2023
i have a large set of data, i can plot it and graph its regression line as can be seen on the figure below. all of my regression line slope calculations are giving me a wrong value, either an absurt number or 95 degrees (i think it can be 90 degrees rotated). chatgpt failed to find a solution so im trying my chances here.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1359268/image.png)
3 Commenti
Adam Danz
il 28 Apr 2023
😀
I saw that the cyclist addressed your question quickly after your reply. I'm curious what issues you had with ChatGPT when trying to solve this problem. This was at least 11 days ago so I understand if those memories are faded.
Risposta accettata
the cyclist
il 18 Apr 2023
% Set seed, for reproduciblity
rng default
% Make up some data
x = (1:10)';
y = 2 + 3*x + randn(10,1);
% Fit the model
mdl = fitlm(x,y)
% Get the coefficient estimate from the model object
intercept = mdl.Coefficients.Estimate(1);
slope = mdl.Coefficients.Estimate(2); % <------- I think this is the slope you want
% To display the fit, pick two arbitrary points
x0 = [0; 10];
y0 = intercept + slope*([0; 10]);
% Plot the data and the fit
figure
hold on
scatter(x,y)
line(x0, y0,"Color","red")
legend(["data";"fit"],"Location","NorthWest")
0 Commenti
Più risposte (0)
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!