How to set slope in linear regression

6 次查看(过去 30 天)
I want to run a linear regression where I set the slope of the regression line to 1 and the intercept to 0. In other words, I want to see how well a set of points fits along the line y = x and I am not concerned about finding the line of best fit. I know how to use the fitlm to remove the intercept term, but I don't yet know how to set the slope. This is what I have so far:
vec1 = (0:10)+rand(1,11);
vec2 = (0:10)+rand(1,11);
scatter(vec1, vec2)
hold on
plot(0:11, 0:11)
mdl = fitlm(vec1, vec2, 'Intercept', false);
.Are there any other arguments that I can add to this function to set the slope, or is it necessary to calculate terms like R^2 and the p-value manually?
  1 个评论
dpb
dpb 2020-1-11
If the intercept is zero and the slope is one; you've already determined the regression expression uniquely--there's nothing left to solve for.
I've at least temporarily lost access to ML license so can't test; but I don't think any of the regression toolsets are coded such as to just allow for the statistics to be computed from a given regression for a data set.
Not such a bad idea to ask for a tool enhancement to do so...

请先登录,再进行评论。

采纳的回答

Star Strider
Star Strider 2020-1-11
Determing the statistic you want to use to determine how well the regression explains the points is not difficult. It is relatively striaghtforward to calculate the Coefficient of determination, .
vec1 = (0:10)+rand(1,11);
vec2 = (0:10)+rand(1,11);
scatter(vec1, vec2)
hold on
plot(0:10, 0:10)
hold off
SStot = sum((vec2-mean(vec2)).^2);
SSres = sum((vec2-vec1).^2);
Rsq = 1-SSres/SStot;
pval = ttest(resd);
text(min(xlim)+0.2*diff(xlim), min(ylim)+0.7*diff(ylim), sprintf('R^2 = %.3f\n\\itp\\rm = %.3f', Rsq,pval))
A one-sample t-test on the residuials is probably adequate to provide a p-value.
  1 个评论
dpb
dpb 2020-1-12
It would be kinda' convenient to have a prepared function that output a clean table, though...the presentation of results in the statistics area is still pretty far from ideal altho has certainly gotten better.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Linear and Nonlinear Regression 的更多信息

产品


版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by