[TOC]

polyval

Evaluating Polynomial and Standard Error of Prediction for Polynomial Regression

Standard Error of Prediction

In the following, we use to represent either the real line or the complex plane . Consider the following polynomial regression model:

where is a random variable, and are given polynomial coefficients. Let be an observation of and be its predicted value. The prediction error is the difference . We define the residual vector as

where

Let be the standard error of the prediction . Since is undefined when , we assume that . Let be the th row of . For each ,

To improve numerical stability, we obtain the inverse by QR decomposition with column pivoting , where is orthogonal, and is an permutation matrix. Note that

where is upper triangular. For convenience, let . Then, the numerator of can be obtained by

where is a column vector. Therefore, the standard error of prediction is

This formula is used by polyfit to computer delta.

Usage

y = polyval(p, x)

y = polyval(p, x, [], mu)

[y, delta] = polyval(p, x, S)

[y, delta] = polyval(p, x, S, mu)

Example

Input
r = [2 3 4 5];
% Creating a polynomial with roots r
p = poly(r);
x = linspace(1.8,5.2);
% Evaluating the polynomial
y = polyval(p,x);
plot(x,y,'-o','MarkerSize',2)
Output
Input
clear
% x and y are data points.
x=linspace(0,2);
y=x.^2+normrnd(0,0.2,[1 length(x)]);
% Get polynomial of degree 2 that fits the data.
[p,S]=polyfit(x,y,2)
scatter(x,y)
hold('on')

% Plot the polynomial and standard errors.
xx=0:0.01:2;
[yy,delta]=polyval(p,xx,S);
plot(xx,yy)
plot(xx,yy+2*delta,'k--')
plot(xx,yy-2*delta,'k--')
hold('off')
Output