Predictive interval for non linear function
2 views (last 30 days)
Show older comments
Hi all,
I need to find and plot the confidence and predictive intervals of scattered data.
The best fit line should be somewhere in the range of 46/(Heigth^-1).
I'm currently using the fit function, with a user define fittype.
The first figure below showns both the simultaneous abd nonsinultaneous bounds for the functional and observation intervals.
This is not how I expect the bounds to be. The bottom figure is what I expect the shape of the bounds should look like.
Can someone please give me some insight to what I am doing wrong?
My code is given below.
Thanks in advance.
KT
clear all
close all
clc
X = [0.162623482 0.446687012 0.240012321 0.267679329 0.243416859 0.244260959 0.242748071 0.25221498 0.286563366 0.559924138 0.403590285 0.497802691 0.723320296 0.432871905 0.399027815 0.692595048 0.76184806 0.816537097 0.524837706 0.853558466 0.596510472 0.973961787 0.443347405 0.671659199 0.887387406 0.702821647 0.535536135 0.844526594 0.800813025 1.190564395 0.971070203 1.124148859 0.952318192 1.329323649 1.125466954 1.428966433 1.177563088 1.745410946 1.332068057 0.676715143 1.203838412 0.865743811 1.027746121 1.293098763 1.504229871 0.586697266 0.915415862 0.917707918 1.151263955 2.057102526 1.284636118 0.487091276 2.003129892 0.585825029 1.049796616 1.297001104 1.099245738 1.411651557 1.543567105 1.294116012 2.402084119 1.277173406 1.731487621 2.515381848 2.683528775 1.418512576 1.828414134 2.173789641 1.109219107 2.293608584 1.526814963 0.791456499 2.077785145 1.796582898 2.267251014 0.896555633 2.599289738 2.161770953 2.043912919 1.769136655 2.753277425 1.634338179 1.317346083 3.063315434 2.272577503 2.937838855 1.785536007 3.021002205 1.153330918 1.936932956 3.366490259 2.279626822 2.780751805 2.919727494 3.277442015 2.966159499 1.947923574 4.019206983 2.878693402 2.763393641 3.289443389 5.016879329 3.728109284 3.968076154 5.485709903 5.880517218];
x = zeros(length(X),1);
Y = [200.0955649 190.2445769 184.1126369 174.4818231 162.1917298 151.9656788 135.1053479 131.6474409 121.0675773 103.4164242 102.7323504 101.9658917 99.27399215 92.94236146 81.19891362 80.08856822 73.43037596 71.27244382 70.11120572 68.77761818 67.38727264 65.42059423 64.99969166 64.82350723 63.61588818 62.83124711 62.39532036 59.12189942 57.29941701 57.09237211 53.01964686 51.24503428 50.53176934 50.32084432 49.49807883 49.10695391 49.03282561 48.93180719 48.03504875 47.43363046 47.03154196 46.47118073 46.39935343 46.26977553 45.5688277 44.61147626 41.83155219 40.48533171 40.44075547 40.00058766 38.1835645 37.898827 37.66168863 37.50806302 36.71512031 35.31241253 34.43230251 33.85790969 33.63593085 33.10309139 31.22245233 30.53711521 30.2288263 30.11837829 30.05977046 29.94896151 29.77764979 29.27715968 29.05725625 28.66865792 28.52888344 28.42412025 27.5076454 26.78404851 26.53675867 26.39635254 26.34866318 26.15213069 25.59190482 25.25740255 25.13481789 24.30068276 24.29017034 23.6221584 23.46117862 21.98903478 21.42889914 21.23629189 21.20434859 19.63817956 19.28914941 18.46245869 17.85625793 17.5399832 14.4208195 14.02825081 12.63294233 12.61250404 10.97383095 10.86094658 10.84930623 10.7618231 10.42479425 8.846082516 7.448157212 6.895420867];
y = zeros(length(X),1);
for i=1:1:length(X)
x(i,1)=X(i);
y(i,1)=Y(i);
end
figure
plot(x,y,'o')
grid on
xlabel('Frequency');
ylabel('Heigth');
fo = fitoptions('Method','NonlinearLeastSquares',...
'Lower',[0,0],...
'Upper',[Inf,max(Y)],...
'StartPoint',[1 1]);
ft = fittype('a*(x^n)','problem','n');
fitresult = fit(x,y,ft,'problem',-1)
%Compute 95% observation and functional prediction intervals, both simultaneous and nonsimultaneous. Non-simultaneous bounds are for individual elements of x; simultaneous bounds are for all elements of x.
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');
%Plot the data, fit, and prediction intervals. Observation bounds are wider than functional bounds because they measure the uncertainty of predicting the fitted curve plus the random variation in the new observation.
figure
subplot(2,2,1)
plot(fitresult,x,y), hold on, plot(x,p11,'m--'), xlim([0 6]), ylim([0 200])
title('Nonsimultaneous Observation Bounds','FontSize',9)
legend off
xlabel('Frequency');
ylabel('Heigth');
subplot(2,2,2)
plot(fitresult,x,y), hold on, plot(x,p12,'m--'), xlim([0 6]), ylim([0 200])
title('Simultaneous Observation Bounds','FontSize',9)
legend off
xlabel('Frequency');
ylabel('Heigth');
subplot(2,2,3)
plot(fitresult,x,y), hold on, plot(x,p21,'m--'), xlim([0 6]), ylim([0 200])
title('Nonsimultaneous Functional Bounds','FontSize',9)
legend off
xlabel('Frequency');
ylabel('Heigth');
subplot(2,2,4)
plot(fitresult,x,y), hold on, plot(x,p22,'m--'), xlim([0 6]), ylim([0 200])
title('Simultaneous Functional Bounds','FontSize',9)
legend({'Data','Fitted curve', 'Prediction intervals'},...
'FontSize',8,'Location','northeast')
xlabel('Frequency');
ylabel('Heigth');
0 Comments
Answers (0)
See Also
Categories
Find more on Linear and Nonlinear Regression 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!