Plot diagnostics of generalized linear regression model
h = plotDiagnostics(...)
h = plotDiagnostics(mdl,plottype,Name,Value)
diagnostics from the
mdl linear model using leverage
as the plot type.
handles to the lines in the plot.
h = plotDiagnostics(...)
Character vector or string scalar specifying the type of plot:
comma-separated pairs of
the argument name and
Value is the corresponding value.
Name must appear inside quotes. You can specify several name and value
pair arguments in any order as
The plot property name-value pairs apply to the first returned
Color of the line or marker, specified as an RGB triplet, hexadecimal color code, color name, or short name for one of the color options listed in the following table.
For a custom color, specify an RGB triplet or a hexadecimal color code.
Alternatively, you can specify some common colors by name. This table lists the named color options, the equivalent RGB triplets, and hexadecimal color codes.
Here are the RGB triplets and hexadecimal color codes for the default colors MATLAB® uses in many types of plots.
Width of the line or edges of filled area, in points, a positive scalar. One point is 1/72 inch.
Marker outline color, specified as an RGB triplet, hexadecimal color code, color name, or
short name for one of the color options listed in the
Fill color for filled markers, specified as an RGB triplet, hexadecimal color code, color
name, or short name for one of the color options listed in the
Size of the marker in points, a strictly positive scalar. One point is 1/72 inch.
Vector of handles to lines or patches in the plot.
Create leverage and Cook's distance plots of a fitted generalized linear model.
Generate artificial data for the model, Poisson random numbers with two underlying predictors
rng default % for reproducibility rndvars = randn(100,2); X = [2+rndvars(:,1),rndvars(:,2)]; mu = exp(1 + X*[1;2]); y = poissrnd(mu);
Create a generalized linear regression model of Poisson data.
mdl = fitglm(X,y,'y ~ x1 + x2','distr','poisson');
Create a leverage plot.
Create a contour plot with Cook's distance.
The hat matrix H is defined in terms of the data matrix X and a diagonal weight matrix W:
H = X(XTWX)–1XTWT.
W has diagonal elements wi:
g is the link function mapping yi to xib.
is the derivative of the link function g.
V is the variance function.
μi is the ith mean.
The diagonal elements Hii satisfy
where n is the number of observations (rows of X), and p is the number of coefficients in the regression model.
Leverage is a measure of the effect of a particular observation on the regression predictions due to the position of that observation in the space of the inputs.
The leverage of observation i is the value of the ith diagonal term hii of the hat matrix H. The hat matrix H is defined in terms of the data matrix X:
H = X(XTX)–1XT.
The hat matrix is also known as the projection matrix because it projects the vector of observations y onto the vector of predictions , thus putting the "hat" on y.
Because the sum of the leverage values is p (the number of coefficients in the regression model), an observation i can be considered an outlier if its leverage substantially exceeds p/n, where n is the number of observations.
For more details, see Hat Matrix and Leverage.
The Cook’s distance Di of observation i is
is the dispersion parameter (estimated or theoretical).
ei is the linear predictor residual, , where
g is the link function.
yi is the observed response.
xi is the observation.
is the estimated coefficient vector.
p is the number of coefficients in the regression model.
hii is the ith diagonal element of the Hat Matrix H.
The data cursor displays the values of the selected plot point in a data tip (small text box located next to the data point). The data tip includes the x-axis and y-axis values for the selected point, along with the observation name or number.
 Neter, J., M. H. Kutner, C. J. Nachtsheim, and W. Wasserman. Applied Linear Statistical Models, Fourth Edition. Irwin, Chicago, 1996.