# Documentation

### This is machine translation

Translated by
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.

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

## Input Arguments

`mdl`

Generalized linear model, as constructed by `fitglm` or `stepwiseglm`.

`plottype`

Character vector 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 `ColorSpec` specification. For details, see `linespec`. `'LineStyle'` Type of line, a 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 `ColorSpec` specification. For details, see `linespec`. `'MarkerFaceColor'` Color of the marker face for filled markers, a `ColorSpec` specification. For details, see `linespec`. `'MarkerSize'` Size of the marker in points, a strictly positive scalar. One point is 1/72 inch.

`'ResidualType'`

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.

## Examples

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.

```plotResiduals(mdl) ```

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

```plotResiduals(mdl,'probability') ```

Create a plot of the fitted residuals of Anscombe type.

```plotResiduals(mdl,'fitted','ResidualType','Anscombe') ```

expand all

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

## See Also

### Topics

Was this topic helpful?

Download now