How to calculate the standard error of my linear regression coefficient?
47 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (1)
Star Strider
le 24 Avr 2021
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 commentaires
Voir également
Catégories
En savoir plus sur Histograms dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
