필터 지우기
필터 지우기

How to find standard deviation of a linear regression?

조회 수: 77 (최근 30일)
Ronny
Ronny 2014년 7월 20일
댓글: star 2016년 6월 28일
Hi everybody
I have an actually pretty simple problem which is driving me crazy right now. There are two sets of data: one for O2 and one for Heat. I made a linear regression in the plot of those two data sets which gives me an equation of the form O2 = a*Heat +b. So now I need to find the confidance interval of a. That for I need to find the standard deviation of a which I somehow just can't find out how to get it. Of course it would also work for me if there is a function that returns the confidance interval directly.
Cheers Ronny

채택된 답변

Star Strider
Star Strider 2014년 7월 20일
편집: Star Strider 2014년 7월 21일
With absolutely no humility at all I direct you to polyparci. It calculates the confidence intervals for you for both parameters:
[p,S] = polyfit(Heat, O2, 1);
CI = polyparci(p,S);
If you have two vectors, Heat and O2, and a linear fit is appropriate to your data, this code should work.

추가 답변 (1개)

Shashank Prasanna
Shashank Prasanna 2014년 7월 21일
Ronny, it is fairly easy to calculate in few lines of code, however it is easier to use functions such as fitlm to perform linear regression. fitlm gives you standard errors, tstats and goodness of fit statistics right out of the box:
If you want to code it up yourself, its 5 or so lines of code, but I'll let you give it a shot first.
  댓글 수: 3
Shashank Prasanna
Shashank Prasanna 2014년 7월 21일
What do you mean by no intercept and strange slope ?
You should get the same results no matter what approach you use to solve your least squares problem.
If you got something different, I'd be interested in knowing more about it.
fitlm by default computes the intercept for you, here is an example:
x = (1:10)'
y = 10+5*x + randn(10,1)
fitlm(x,y)
ans =
Linear regression model:
y ~ 1 + x1
Estimated Coefficients:
Estimate SE tStat pValue
________ _______ ______ __________
(Intercept) 10.164 0.85652 11.866 2.3351e-06
x1 5.0984 0.13804 36.934 3.1669e-10
Number of observations: 10, Error degrees of freedom: 8
Root Mean Squared Error: 1.25
R-squared: 0.994, Adjusted R-Squared 0.993
F-statistic vs. constant model: 1.36e+03, p-value = 3.17e-10
star
star 2016년 6월 28일
these two methods (polyparci and fitlm) find the same trend values. But, the results of the confidence intervals are different in these two methods. Polyparci seems to be more optimistic. For a given set of data, polyparci results in confidence interval with 95% (3 sigma) between CI =
4.8911 7.1256
5.5913 11.4702
So, this means we have a trend value between 4.8911 and 5.5913 in 95% confidence interval. What we found from this result is that 1 sigma is 0.1167.
However, for the same data set fitlm results in SE
Estimate SE tStat pValue
________ _______ ______ __________
(Intercept) 9.2979 1.1682 7.9592 4.5304e-05
x1 5.2412 0.18827 27.838 2.9924e-09
this indicates 0.18827 for one sigma. So, the trend values are same. But, the sigma values of estimated trends are different.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Dimensionality Reduction and Feature Extraction에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by