plotResiduals

Class: GeneralizedLinearModel

Plot residuals of generalized linear regression model

Syntax

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

Description

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.

Tips

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

Input Arguments

mdl

Generalized linear model, as constructed by fitglm or stepwiseglm.

plottype

String specifying the type of plot:

'caseorder'Residuals vs. case (row) order
'fitted'Residuals vs. fitted values
'histogram'Histogram
'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.

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

'Color'

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

'LineStyle'

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

'LineWidth'

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

Default: 0.5

'MarkerEdgeColor'

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

'MarkerFaceColor'

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

'MarkerSize'

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

'ResidualType'

String giving 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

h

Vector of handles to lines or patches in the plot.

Definitions

Deviance

Deviance is twice the log likelihood of the model. Because this overall log likelihood is a sum of log likelihoods for each observation, the residual plot of deviance type shows the log likelihood per observation.

Examples

expand all

Residual Plots for Generalized Linear Models

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.

plotResiduals(mdl)

Create a probability plot.

plotResiduals(mdl,'probability')

The residuals do not match a normal distribution in the tails—they are more spread out.

Create a plot of the fitted residuals of Anscombe type.

Was this topic helpful?