How to show the regression plot in a figure?
28 views (last 30 days)
Show older comments
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 Comments
Hildo
on 28 Nov 2016
You can use the Curve Fitting toolbox and plot its object
plot(curvefitted)
or use in code the functions of this toolbox.
Answers (1)
Soumya Saxena
on 21 Dec 2016
Edited: Soumya Saxena
on 22 Dec 2016
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
0 Comments
See Also
Categories
Find more on Model Building and Assessment in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!