Residual plot & Calculation of Coefficient of Determination using Regression output | MATLAB
Code:-
%Residual Concept
x=input('Enter the x coordinates');
y=input('Enter the y coordinates');
stem(x,y);
a=[];
for i=1:length(x)
a=[a ; x(i) 1];
end
c =a\y';
yR = c(1)*x + c(2); % the fitted line
r=y-yR;
stem(x,r);
hold on;
plot(x,r,'o','linewidth',5);
grid on;
r=r.^2;
rsq=1-(sum(r)/sum((y-mean(y)).^2));
%Residual Concept
x=input('Enter the x coordinates');
y=input('Enter the y coordinates');
stem(x,y);
a=[];
for i=1:length(x)
a=[a ; x(i) 1];
end
c =a\y';
yR = c(1)*x + c(2); % the fitted line
r=y-yR;
stem(x,r);
hold on;
plot(x,r,'o','linewidth',5);
grid on;
r=r.^2;
rsq=1-(sum(r)/sum((y-mean(y)).^2));
No comments