# removeTerms

Class: GeneralizedLinearModel

Remove terms from generalized linear model

## Syntax

`mdl1 = removeTerms(mdl,terms)`

## Description

`mdl1 = removeTerms(mdl,terms)` returns a linear model the same as `mdl` but with fewer terms.

## Input Arguments

 `mdl` Generalized linear model, as constructed by `fitglm` or `stepwiseglm`. `terms` Terms to remove from the `mdl` regression model. Specify as either a: Text string representing one or more terms to remove. For details, see Wilkinson Notation.Row or rows in the terms matrix (see `modelspec` in `fitglm`). For example, if there are three variables `A`, `B`, and `C`:```[0 0 0] represents a constant term or intercept [0 1 0] represents B; equivalently, A^0 * B^1 * C^0 [1 0 1] represents A*C [2 0 0] represents A^2 [0 1 2] represents B*(C^2)```

## Output Arguments

 `mdl1` Generalized linear model, the same as `mdl` but without the terms given in `terms`. You can set `mdl1` equal to `mdl` to overwrite `mdl`.

## Definitions

### Wilkinson Notation

Wilkinson notation describes the factors present in models. The notation relates to factors present in models, not to the multipliers (coefficients) of those factors.

Wilkinson NotationFactors in Standard Notation
`1`Constant (intercept) term
`A^k`, where `k` is a positive integer`A`, `A2`, ..., `Ak`
`A + B``A`, `B`
`A*B``A`, `B`, `A*B`
`A:B``A*B` only
`-B`Do not include `B`
`A*B + C``A`, `B`, `C`, `A*B`
`A + B + C + A:B``A`, `B`, `C`, `A*B`
`A*B*C - A:B:C``A`, `B`, `C`, `A*B`, `A*C`, `B*C`
`A*(B + C)``A`, `B`, `C`, `A*B`, `A*C`

Statistics and Machine Learning Toolbox™ notation always includes a constant term unless you explicitly remove the term using `-1`.

For details, see Wilkinson and Rogers [1].

## Examples

expand all

### Remove a Term from a Generalized Linear Regression Model

This example makes a model using two predictors, then removes one.

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')`
```mdl = Generalized Linear regression model: log(y) ~ 1 + x1 + x2 Distribution = Poisson Estimated Coefficients: Estimate SE tStat pValue (Intercept) 1.0405 0.022122 47.034 0 x1 0.9968 0.003362 296.49 0 x2 1.987 0.0063433 313.24 0 100 observations, 97 error degrees of freedom Dispersion: 1 Chi^2-statistic vs. constant model: 2.95e+05, p-value = 0```

Remove the second predictor from the model.

`mdl1 = removeTerms(mdl,'x2')`
```mdl1 = Generalized Linear regression model: log(y) ~ 1 + x1 Distribution = Poisson Estimated Coefficients: Estimate SE tStat pValue (Intercept) 2.7784 0.014043 197.85 0 x1 1.1732 0.0033653 348.6 0 100 observations, 98 error degrees of freedom Dispersion: 1 Chi^2-statistic vs. constant model: 1.25e+05, p-value = 0```

## References

[1] Wilkinson, G. N., and C. E. Rogers. Symbolic description of factorial models for analysis of variance. J. Royal Statistics Society 22, pp. 392–399, 1973.

## Alternatives

`step` adds or removes terms from a model using a greedy one-step algorithm.