Clear Filters
Clear Filters

How to determine if new data lies outside old prediction intervals

9 views (last 30 days)
I have made a prediction model (using fit and predint) based on data in my table T. I know how to test if the existing data is outside the prediction interval, but I am unsure how to test new datapoints. I do not want to use the new data to make a new fit, I want to use the existing fit model and prediction intervals from the original data.
I am not sure how to generate a continuous function for the upper and lower interval.
Thanks.
load example_table.mat
T=sortrows(T,"Xdata");
x=T.Xdata;
y=T.Ydata;
fitresult = fit(x,y,'exp1');
pred = predint(fitresult,x,0.95);
plot(fitresult,x,y)
hold on
plot(x,pred,'m--')
legend({'Data','Fitted curve', 'Prediction intervals'},...
'FontSize',8,'Location','northwest')
%% See which rows fall outside of interval
outside = (y < pred(:, 1)) | (y > pred(:, 2));
rows_outside_interval = T(outside, :)
rows_outside_interval = 2x4 table
When Data1 Xdata Ydata ____________________ _____ _____ ______ 29-Feb-2024 07:07:54 -1.5 367.5 30.803 26-Feb-2024 21:05:07 18 389.4 9.4924
% Now I add a new row (that would fall outside), and want to test this against the existing
% prediction interval. Stuck here.
ht=height(T);
T(ht+1,:)=T(1,:);
T(ht+1,"Xdata")={300};
T(ht+1,"Ydata")={25};
T(ht+1,:)
ans = 1x4 table
When Data1 Xdata Ydata ____________________ _____ _____ _____ 03-May-2024 14:19:42 27 300 25
  2 Comments
Tony
Tony on 21 Jun 2024
One idea is to find the pair of x points in the prediction interval series where the new data x lies in-between, assume the prediction is interpolated linearly in that interval, find the y value of the prediction intervals via linear interpolation for the data x, and then compare with your data y
Marcus Glover
Marcus Glover on 21 Jun 2024
Thanks, that is a good idea. I'll look at that and I could even fit the prediction line series itself and see which is faster as I may have a lot of new data at times.

Sign in to comment.

Answers (0)

Products


Release

R2023b

Community Treasure Hunt

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

Start Hunting!