# linear regression

83 views (last 30 days)
lowcalorie on 12 May 2012
Commented: Image Analyst on 22 Jul 2021
i have a table of data
X = 1,2,3,4,5,6,7,8,9
Y= 4 5 6 9 8 7 4 1 2
how can i plot these points without having a line then using linear regression to find the uncertainty with a 95% confidence interval and plot that?
emmanuel zambrano on 21 Jul 2021
Can you help me with Linear regression approximation of errors. Please I need a code now

Image Analyst on 12 May 2012
% Define sample data.
X = [1,2,3,4,5,6,7,8,9];
Y = [4 5 6 9 8 7 4 1 2];
% Do the plotting:
plot(X, Y, 'bo', 'LineWidth', 3, 'MarkerSize', 15);
grid on;
% Maximize the figure window.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
% Label the various parts of the plot.
fontSize = 20;
title('lowcalorie Plot', 'FontSize', fontSize);
xlabel('X', 'FontSize', fontSize);
ylabel('Y', 'FontSize', fontSize);
coefficients = polyfit(X, Y, 1);
fittedY = polyval(coefficients, X);
hold on;
% Do the plotting:
plot(X, fittedY, 'rs-', 'LineWidth', 3, 'MarkerSize', 15);
legend('Y', 'Fitted Y');
emmanuel zambrano on 21 Jul 2021
Can you help me with Linear regression approximation of errors. Please I need a code now

Richard Willey on 14 May 2012
Alternatively, if you have the 12a version of Statistics Tbx
X = [1,2,3,4,5,6,7,8,9];
Y = [4 5 6 9 8 7 4 1 2];
myFit = LinearModel.fit(X,Y);
plot(myFit)
emmanuel zambrano on 21 Jul 2021
Can you help me with Linear regression approximation of errors. Please I need a code now

Nadeem Ali on 4 Apr 2021
%% datasets
x=[3,4,6,4,2,5]';
y=[6,8,9,5,4.5,9.5]';

Nadeem Ali on 4 Apr 2021
% Define sample data.
X = [1,2,3,4,5,6,7,8,9];
Y = [4 5 6 9 8 7 4 1 2];
% Do the plotting:
plot(X, Y, 'bo', 'LineWidth', 3, 'MarkerSize', 15);
grid on;
% Maximize the figure window.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
% Label the various parts of the plot.
fontSize = 20;
title('lowcalorie Plot', 'FontSize', fontSize);
xlabel('X', 'FontSize', fontSize);
ylabel('Y', 'FontSize', fontSize);
coefficients = polyfit(X, Y, 1);
fittedY = polyval(coefficients, X);
hold on;
% Do the plotting:
plot(X, fittedY, 'rs-', 'LineWidth', 3, 'MarkerSize', 15);
legend('Y', 'Fitted Y');
Image Analyst on 21 Jul 2021
@emmanuel zambranoThe errors on a linear regression will be normally distributed because that's how the regression was determined - that's the assumption that was made. So you cannot approximate the errors with any independent variable, other than perhaps y=0. Just plot the errors for all the data points and you'll see a random pattern along the x-axis.

emmanuel zambrano on 21 Jul 2021
How do I do then?

emmanuel zambrano on 21 Jul 2021
##### 2 CommentsShowHide 1 older comment
Image Analyst on 22 Jul 2021
@emmanuel zambrano, this is not an answer to @lowcalorie's original question. I suggest you start your own question, this time make it explained much much better, rather than continue the discussion here in @lowcalorie's thread. But read this first: