How to show the regression plot in a figure?

42 次查看(过去 30 天)
Plot x vs y, with y plotted as the independent variable. need to find out the slope, y-intercept,t-statistic for the regression plot, p-value for the regression plot and the r^2 value.
x=[1 2 3 4 5 6 7 8 9 10]
y=[4 5 2 7 2 8 10 2 1 5]
  2 个评论
Hildo
Hildo 2016-11-28
You can use the Curve Fitting toolbox and plot its object
plot(curvefitted)
or use in code the functions of this toolbox.

请先登录,再进行评论。

回答(1 个)

Soumya Saxena
Soumya Saxena 2016-12-21
编辑:Soumya Saxena 2016-12-22
I understand that you would like to plot a regression plot for the x and y values specified. If y is independent variable and x is dependent variable, you may specify them as follows:
x=[1 2 3 4 5 6 7 8 9 10]
y=[4 5 2 7 2 8 10 2 1 5]
You can define a table containing y as the independant variable and x as the response variable. The "fitlm" function takes the last variable in the table as the response variable by default.
tbl = table(y' , x')
You can then create a linear model as:
mdl = fitlm(tbl,'linear')
You can plot it as:
plot(mdl)
The model generated will have the intercept values along with the t-statistic, p value, degrees of freedom and r squared values.
The documentation of the "fitlm" function can be found at:
The output should be similar to:
mdl =
Linear regression model:
Var2 ~ 1 + Var1
Estimated Coefficients:
Estimate SE tStat pValue
_________ _______ _________ ________
(Intercept) 5.6144 1.9347 2.902 0.019832
Var1 -0.024876 0.35803 -0.069479 0.94631
Number of observations: 10, Error degrees of freedom: 8
Root Mean Squared Error: 3.21
R-squared: 0.000603, Adjusted R-Squared -0.124
F-statistic vs. constant model: 0.00483, p-value = 0.946

Community Treasure Hunt

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

Start Hunting!

Translated by