how can i find the slope of a regression line
19 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Omer hakan Yaran
am 17 Apr. 2023
Kommentiert: Adam Danz
am 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.
3 Kommentare
Adam Danz
am 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.
Akzeptierte Antwort
the cyclist
am 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 Kommentare
Weitere Antworten (0)
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!