How to show the regression plot in a figure?

28 ビュー (過去 30 日間)
Weiyan Chen
Weiyan Chen 2016 年 11 月 28 日
編集済み: Soumya Saxena 2016 年 12 月 22 日
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.
KSSV
KSSV 2016 年 11 月 29 日
Home work...

サインインしてコメントする。

回答 (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

カテゴリ

Help Center および File ExchangeModel Building and Assessment についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by