how can i find the slope of a regression line
조회 수: 40 (최근 30일)
이전 댓글 표시
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
Adam Danz
2023년 4월 28일
😀
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.
채택된 답변
the cyclist
2023년 4월 18일
% 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
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!