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])

 채택된 답변

Star Strider
Star Strider 2016년 4월 13일

1 개 추천

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

Thank you star it is so impressive to listen answer for each question from you. I'm able to get the CI bound (values) but I want to plot it to my fitted results when I'm doing so I should expect a hyperbolic trend of bounds but its just a straight curve e.g., one attached here. Could you please guide what I'm missing here to get hyperbolic bounds e.g., one given below
x = (0:0.2:5)'; y = 2*exp(-0.2*x) + 0.5*randn(size(x)); fitresult = fit(x,y,'poly1');
p11 = predint(fitresult,x,0.95,'observation','off'); p12 = predint(fitresult,x,0.95,'observation','on'); p21 = predint(fitresult,x,0.95,'functional','off'); p22 = predint(fitresult,x,0.95,'functional','on');
subplot(2,2,1) plot(fitresult,x,y), hold on, plot(x,p11,'m--'), xlim([3 6]) title('Nonsimultaneous observation bounds','Color','m') subplot(2,2,2) plot(fitresult,x,y), hold on, plot(x,p12,'m--'), xlim([3.5 6]) title('Simultaneous observation bounds','Color','m') subplot(2,2,3) plot(fitresult,x,y), hold on, plot(x,p21,'m--'), xlim([0 5]) title('Nonsimultaneous functional bounds','Color','m') subplot(2,2,4) plot(fitresult,x,y), hold on, plot(y,p22,'m--'), xlim([0 5]) title('Simultaneous functional bounds','Color','m')
I don’t have the Curve Fitting Toolbox, so I can’t help you with its functions. I do have the Statistics, etc. Toolbox, so I would use the fitlm and predict functions:
mdl = fitlm(x, y, 'linear');
xnew = linspace(min(x), max(x), 1000)';
[ypred, yci] = predict(mdl, xnew);
figure(1)
plot(x, y, 'b.')
hold on
plot(xnew, ypred, '-r')
plot(xnew, yci(:,1), '-g')
plot(xnew, yci(:,2), '-g')
hold off
grid
Undefined function 'polyparci' for input arguments of type 'struct'.
how to remove this error in star above code plz
I have no idea what you’re passing to it, since you did not post your code. See the example in my code in my original Answer here for an illustration on how to use it.
My polyparci function takes two arguments, the parameter vector as the first argument, and the ‘S’ structure returned by the polyfit function as the second argument, in that order. You cannot switch them, and you cannot omit either of them.
Thank you star and sorry for being late in saying thanks becuase matlab service was down for some reason
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.

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

추가 답변 (0개)

질문:

2016년 4월 13일

댓글:

2016년 4월 14일

Community Treasure Hunt

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

Start Hunting!

Translated by