This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.


Class: GeneralizedLinearModel

Plot residuals of generalized linear regression model


h = plotResiduals(...)
h = plotResiduals(mdl,plottype,Name,Value)


plotResiduals(mdl) gives a histogram plot of the residuals of the mdl nonlinear model.

plotResiduals(mdl,plottype) plots residuals in a plot of type plottype.

h = plotResiduals(...) returns handles to the lines in the plot.

h = plotResiduals(mdl,plottype,Name,Value) plots with additional options specified by one or more Name,Value pair arguments.

Input Arguments


Generalized linear model, as constructed by fitglm or stepwiseglm.


Character vector specifying the type of plot:

'caseorder'Residuals vs. case (row) order
'fitted'Residuals vs. fitted values
'lagged'Residuals vs. lagged residual (r(t) vs. r(t–1))
'probability'Normal probability plot
'symmetry'Symmetry plot

Default: 'histogram'

Name-Value Pair Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside single quotes (' '). You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.


The plot property name-value pairs apply to the first returned handle h(1).


Color of the line or marker, a ColorSpec specification. For details, see linespec.


Type of line, a Line Properties specification. For details, see linespec.


Width of the line or edges of filled area, in points, a positive scalar. One point is 1/72 inch.

Default: 0.5


Color of the marker or edge color for filled markers, a ColorSpec specification. For details, see linespec.


Color of the marker face for filled markers, a ColorSpec specification. For details, see linespec.


Size of the marker in points, a strictly positive scalar. One point is 1/72 inch.


Type of residual used in the plot.

'Raw'Observed minus fitted values
'LinearPredictor'Residuals on the linear predictor scale, equal to the adjusted response value minus the fitted linear combination of the predictors
'Pearson'Raw residuals divided by RMSE
'Anscombe'Residuals defined on transformed data with the transformation chosen to remove skewness
'Deviance'Residuals based on the contribution of each observation to the deviance

Default: 'Raw'

Output Arguments


Vector of handles to lines or patches in the plot.


expand all

Create residual plots of a fitted generalized linear model.

Generate artificial data for the model, Poisson random numbers with two underlying predictors X(1) and X(2).

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 default residuals plot.


Create a probability plot. The residuals do not match a normal distribution in the tails because they are more spread out.


Create a plot of the fitted residuals of Anscombe type.



expand all


  • 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.

Was this topic helpful?