linear regression

12 次查看(过去 30 天)
lowcalorie
lowcalorie 2012-5-12
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?

采纳的回答

Image Analyst
Image Analyst 2012-5-12
% 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');

更多回答(2 个)

Richard Willey
Richard Willey 2012-5-14
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)

Maria Ghani
Maria Ghani 2022-10-19
i need to run regression to get coeffecient between two variables x, y . my data set is daily from 1995 to 2022 . i need monthly coeffecient between two variables . what command should i need to write please anyone help. my dat afile is attached for detail information. x regress y but how i can get for every month ?
thanks in advance
  1 个评论
Image Analyst
Image Analyst 2022-10-19
Extract out each month's data and then fit them individually using polyfit.
If you have any more questions, then attach your data and code to read it in with the paperclip icon, in a brand new discussion thread (not here), after you read this:

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Descriptive Statistics 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by