`plotDiagnostics(mdl)`

plotDiagnostics(mdl,plottype)

h = plotDiagnostics(___)

h = plotDiagnostics(mdl,plottype,Name,Value)

`plotDiagnostics(`

plots
diagnostics from the `mdl`

)`mdl`

linear model using the
leverage values.

`plotDiagnostics(`

plots
diagnostics in a plot of type `mdl`

,`plottype`

)`plottype`

.

returns
handles to the lines in the plot, using any of the previous syntaxes.`h`

= plotDiagnostics(___)

plots
with additional options specified by one or more `h`

= plotDiagnostics(`mdl`

,`plottype`

,`Name,Value`

)`Name,Value`

pair
arguments.

For many plots, the Data Cursor tool in the figure window displays the

*x*and*y*values for any data point, along with the observation name or number.

The *hat matrix* *H* is
defined in terms of the data matrix *X*:

*H* = *X*(*X ^{T}X*)

The diagonal elements *h _{ii}* satisfy

$$\begin{array}{l}0\le {h}_{ii}\le 1\\ {\displaystyle \sum _{i=1}^{n}{h}_{ii}}=p,\end{array}$$

where *n* is the number of observations (rows
of *X*), and *p* is the number of
coefficients in the regression model.

The *leverage* of observation *i* is
the value of the *i*th diagonal term, *h*_{ii},
of the hat matrix *H*. Because the sum of the leverage
values is *p* (the number of coefficients in the
regression model), an observation *i* can be considered
to be an outlier if its leverage substantially exceeds *p*/*n*,
where *n* is the number of observations.

Cook's distance is the scaled change in fitted values.
Each element in `CooksDistance`

is the normalized
change in the vector of coefficients due to the deletion of an observation.
The Cook's distance, *D*_{i},
of observation *i* is

$${D}_{i}=\frac{{\displaystyle \sum _{j=1}^{n}{\left({\widehat{y}}_{j}-{\widehat{y}}_{j(i)}\right)}^{2}}}{p\text{\hspace{0.17em}}MSE},$$

where

$${\widehat{y}}_{j}$$ is the

*j*th fitted response value.$${\widehat{y}}_{j(i)}$$ is the

*j*th fitted response value, where the fit does not include observation*i*.*MSE*is the mean squared error.*p*is the number of coefficients in the regression model.

Cook's distance is algebraically equivalent to the following expression:

$${D}_{i}=\frac{{r}_{i}^{2}}{p\text{\hspace{0.17em}}MSE}\left(\frac{{h}_{ii}}{{\left(1-{h}_{ii}\right)}^{2}}\right),$$

where *r*_{i} is
the *i*th residual, and *h*_{ii} is
the *i*th leverage value.

`CooksDistance`

is an *n*-by-1
column vector in the `Diagnostics`

table of the `LinearModel`

object.

[1] Neter, J., M. H. Kutner, C. J. Nachtsheim, and W. Wasserman. *Applied
Linear Statistical Models*, Fourth Edition. Irwin, Chicago,
1996.

The `mdl.Diagnostics`

property contains the
information that `plotDiagnostics`

uses to create
plots.

Was this topic helpful?