How to calculate the standard error of my linear regression coefficient?
89 次查看(过去 30 天)
显示 更早的评论
I want to create a linear regression for my data through the origin. My code works fine, but I also need to determine the error of the coefficient K. My y data also has an error of ±0.001 (the x data has not) which have to be taken into account.
x=[-7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7];
y=[-9 -7.65 -6.35 -5.05 -3.8 -2.6 -1.2 0 1.1 2.4 3.7 4.9 6.2 7.25 8.35]*0.01;
% Computing fitted line
K = x(:)\y(:);
yfit = x(:)*K;
scatter(x, y)
hold on
plot (x, yfit, '-r')
hold off
K
0 个评论
回答(1 个)
Star Strider
2021-4-24
You can certainly look this up and calculate it on your own, however using fitlm and predict is easier —
x=[-7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7];
y=[-9 -7.65 -6.35 -5.05 -3.8 -2.6 -1.2 0 1.1 2.4 3.7 4.9 6.2 7.25 8.35]*0.01;
% Computing fitted line
K = x(:)\y(:);
yfit = x(:)*K;
mdl = fitlm(x,y,'Intercept',false)
[ypred,yci] = predict(mdl,x(:));
figure
scatter(x, y)
hold on
plot (x, yfit, '-r')
plot(x, yci, '-g')
hold off
K
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Regression 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!