Graphics Programs Reference
In-Depth Information
Plotting the residuals does not show obvious patterned behavior. Thus no
more complex model than a straight line should be fi tted to the data.
plot(meters,res,'o')
An alternative way to plot the residuals is a stem plot using
stem
.
subplot(2,1,1)
plot(meters,age,'o'), hold
plot(meters,p(1) * meters + p(2),'r')
subplot(2,1,2)
stem(meters,res);
Let us explore the distribution of the residuals. We choose six classes and
calculate the corresponding frequencies.
[n_exp,x] = hist(res,6)
n_exp =
5 4 8 7 4 2
x =
-16.0907 -8.7634 -1.4360 5.8913 13.2186 20.5460
By basing the bin centers in the locations defi ned by the function
hist
, a
more practical set of classes can be defi ned.
v = -13 : 7 : 23
n_exp = hist(res,v);
Subsequently, the mean and standard deviation of the residuals are com-
puted. These are then used for generating a theoretical frequency distribu-
tion that can be compared with the distribution of the residuals. The mean
is close to zero, whereas the standard deviation is 11.5612. The function
normpdf
is used for creating the frequency distribution
n_syn
similar to
our example. The theoretical distribution is scaled according to our original
sample data and displayed.
n_syn = normpdf(v,0,11.5612);
n_syn = n_syn ./ sum(n_syn);
n_syn = sum(n_exp) * n_syn;
The fi rst line normalizes
n_syn
to a total of one. The second command
scales
n_syn
to the sum of
n_exp
. We plot both distributions for compari-
son.