Confidence interval for linear regression

5 views (last 30 days)
Hello, every body. I have a question here. I have a data set (attached excel file) I'm using the following code to estimate 95 and 99% confidence bound on poly fit. But it is not giving me the desired results because the real answer for this data gives confidence bound like hyperbolic form an example attached (in pdf) but this routine produces straight lines bounds. I have seen polyparci.m from the great star but couldn't follow it exactly (perhaps an example in same code would be beneficial). I'm interested in obtaining results similar to Figure on page 3 of attached pdf using equation given on the same page. I would really appreciate any help or guidance for this. Thank you in advance
fitresult = fit(x,y,'poly1');
p11 = predint(fitresult,x,0.95,'observation','off'); plot(fitresult,x,y), hold on, plot(x,p11,'m--'), xlim([3 6])

Accepted Answer

Star Strider
Star Strider on 13 Apr 2016
I appreciate the compliment! The polyparci function calculates the confidence intervals on the parameter estimates (for a linear model they would be the slope and intercept), not the fitted values. (The ‘delta’ output from polyval gives something, but I’ve not been able to decipher exactly what.)
See if this does what you want:
D = xlsread('amberly hadden test.xlsx');
x = D(:,1);
y = D(:,2);
[B,S] = polyfit(x, y, 1);
CI = polyparci(B,S);
fprintf(1, '\n\tParameter Estimates and Confidence Intervals:\n\t\t\t\t\t\tSlope\t\tIntercept')
fprintf(1, '\n\t\tUpper 95%%CI\t%.4f\t\t%.4f',CI(1,:))
fprintf(1, '\n\t\tParameter \t%.4f\t\t%.4f',B)
fprintf(1, '\n\t\tLower 95%%CI\t%.4f\t\t%.4f\n',CI(2,:))
I get this output:
Parameter Estimates and Confidence Intervals:
Slope Intercept
Upper 95% CI 1.2249 11586.5662
Parameter 1.2644 12624.5120
Lower 95% CI 1.3039 13662.4577
  6 Comments
amberly hadden
amberly hadden on 14 Apr 2016
Thank you star and sorry for being late in saying thanks becuase matlab service was down for some reason
Star Strider
Star Strider on 14 Apr 2016
My pleasure!
No worries, Amberly!
Answers was down to incorporate some upgrades, among which were to add the number of views a Question had, and the ability for those with 500 or more Reputation Points to ‘Unaccept’ an Answer after 7 days, and Accept another Answer. (The person who had the first accepted Answer retains the points from the original acceptance.) That’s a distinction without a difference for most people here.

Sign in to comment.

More Answers (0)

Categories

Find more on MATLAB 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!