polypredci
POLYPREDCI takes the actual (x,y) data and polynomial order as arguments, uses ‘polyfit’ and ‘polyval’ to do the regression, then calculates and returns the fitted curve and the one-sided prediction confidence intervals on the fit. It uses the one-tailed t-statistic to calculate the confidence intervals. That calculation is entirely contained within POLYPREDCI, so the Statistics and Machine Learning Toolbox is not required. (It does not calculate confidence intervals for the parameters. See the related function ‘polyparci’ for that.) It is extensively internally documented.
POLYPREDCI follows published equations (in several references) to calculate the confidence intervals. They are close to but not the same as those calculated by ‘nlpredci’. I have no idea how ‘nlpredci’ calculates its confidence intervals, since they do not appear in the documentation that I can find.
POLYPREDCI has three required arguments and two optional arguments. The three required arguments are: ‘x’ (the independent data vector), ‘y’ (the dependent data vector), and ‘n’ (the polynomial order). The two optional arguments are ‘alfa’ (the desired level of statistical significance), and ‘xv’ (high-resolution vector for polynomial fit and confidence interval calculations). The default value for ‘alfa’ is 0.95.
POLYPREDCI was stimulated by a Question from ‘pocketHands’ on 2016 06 10, who thought ‘polyparci’ would do this. (It won’t!)
POLYPREDCI was created with R2016a but should work on all recent releases.
Example on using POLYPREDCI:
x = linspace(0, 2.5, 15); % Create Data
y = 2 + 3*x.^2 + 5*randn(size(x)); % Create Data
n = 3; % Polynomial Order
alfa = 0.99; % Desired Significance
xv = linspace(min(x), max(x))'; % Optional High-Resolution Vector
[ p, yhat, ci ] = polypredci( x, y, n, alfa, xv ); % Define Both ‘alfa’ & ‘xv’
% [ p, yhat, ci ] = polypredci( x, y, n, alfa ); % Use ‘alfa’
% [ p, yhat, ci ] = polypredci( x, y, n ); % Use Defaults
figure(1)
plot(x, y, 'bp')
hold on
if length(yhat) == length(x)
plot(x, yhat, '--r')
plot(x, yhat+ci, '--g')
plot(x, yhat-ci, '--g')
elseif length(yhat) == length(xv)
plot(xv, yhat, '--r')
plot(xv, yhat+ci, '--g')
plot(xv, yhat-ci, '--g')
end
hold off
grid
Cite As
Star Strider (2024). polypredci (https://www.mathworks.com/matlabcentral/fileexchange/57630-polypredci), MATLAB Central File Exchange. Retrieved .
MATLAB Release Compatibility
Platform Compatibility
Windows macOS LinuxCategories
Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Discover Live Editor
Create scripts with code, output, and formatted text in a single executable document.
Version | Published | Release Notes | |
---|---|---|---|
1.0.0.0 |