How to show the regression plot in a figure?
28 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Hildo
el 28 de Nov. de 2016
You can use the Curve Fitting toolbox and plot its object
plot(curvefitted)
or use in code the functions of this toolbox.
Respuestas (1)
Soumya Saxena
el 21 de Dic. de 2016
Editada: Soumya Saxena
el 22 de Dic. de 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 comentarios
Ver también
Categorías
Más información sobre Model Building and Assessment en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!