How to show the regression plot in a figure?
조회 수: 28 (최근 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
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
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
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Model Building and Assessment에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!