Confidence intervals around trend

조회 수: 10 (최근 30일)
Peter
Peter 2013년 7월 30일
답변: star 2014년 10월 23일
I am trying to compute confidence intervals around a trend line, such as that seen in the website below:
I am not confident that using polyconf with ployfit is the right way to go. Can anyone suggest how I might achieve this? Many thanks

답변 (3개)

Wayne King
Wayne King 2013년 7월 30일
편집: Wayne King 2013년 7월 30일
Do you have the Statistics Toolbox?
One way:
load carsmall;
X = ones(length(Horsepower),2);
X(:,2) = Horsepower;
Y = Acceleration;
[b,bint] = regress(Y,X);
x = min(Horsepower):0.01:max(Horsepower);
yfit = b(1)+b(2)*x;
plot(Horsepower,Y,'k*')
hold on;
ylower = bint(1,1)+ bint(2,1)*x;
yupper = bint(1,2)+bint(2,2)*x;
plot(x,yfit,'r','linewidth',2)
plot(x,ylower,'b-.')
plot(x,yupper,'b-.')
Another way using LinearModel.fit
mdl = LinearModel.fit(Horsepower,Y);
ci = coefCI(mdl);
Note that ci is the same matrix as bint. The nice thing about LinearModel.fit is that there is a plot() method that will give you the plot with the confidence intervals
plot(mdl)

Shashank Prasanna
Shashank Prasanna 2013년 7월 30일
You can use polyconf
Alternatively you can fit your model using LinearModel.fit and use predict to collect the second argument which is the prediction confidence interval.
Set the 'Prediction' to 'Curve' to predict confidence bounds for the fitted mean (trend) values.

star
star 2014년 10월 23일
I should say that before trying to compute the confidence interval, it is better if you try to figure out where does it come from? Then, you can calculate through any software. Software are just languages.

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by