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.

removeTerms

Class: LinearModel

Remove terms from linear model

Syntax

```mdl1 = removeTerms(mdl,terms) ```

Description

`mdl1 = removeTerms(mdl,terms)` returns a linear regression model `mdl1` that is the same as the input model `mdl`, but with terms removed as specified by `terms`.

Input Arguments

expand all

Full, fitted linear regression model, specified as a `LinearModel` object constructed using `fitlm` or `stepwiselm`.

Terms to remove from the regression model `mdl`, specified as one of the following:

• Formula representing one or more terms to remove. For details, see Wilkinson Notation.

• Row or rows in the terms matrix (see the `modelspec` argument description in the fitting function `fitlm`). 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

expand all

Regression model with fewer terms, returned as a `LinearModel` object. `mdl1` is the same as `mdl` but with `terms` removed. To overwrite `mdl`, set `mdl1` equal to `mdl`.

Examples

expand all

Construct a default linear model of the Hald data. Remove terms with high -values.

```load hald X = ingredients; % predictor variables y = heat; % response ```

Fit a default linear model to the data.

```mdl = fitlm(X,y) ```
```mdl = Linear regression model: y ~ 1 + x1 + x2 + x3 + x4 Estimated Coefficients: Estimate SE tStat pValue ________ _______ ________ ________ (Intercept) 62.405 70.071 0.8906 0.39913 x1 1.5511 0.74477 2.0827 0.070822 x2 0.51017 0.72379 0.70486 0.5009 x3 0.10191 0.75471 0.13503 0.89592 x4 -0.14406 0.70905 -0.20317 0.84407 Number of observations: 13, Error degrees of freedom: 8 Root Mean Squared Error: 2.45 R-squared: 0.982, Adjusted R-Squared 0.974 F-statistic vs. constant model: 111, p-value = 4.76e-07 ```

Remove the `x3` and `x4` terms because their -values are so high.

```terms = 'x3 + x4'; % terms to remove mdl1 = removeTerms(mdl, terms) ```
```mdl1 = Linear regression model: y ~ 1 + x1 + x2 Estimated Coefficients: Estimate SE tStat pValue ________ ________ ______ __________ (Intercept) 52.577 2.2862 22.998 5.4566e-10 x1 1.4683 0.1213 12.105 2.6922e-07 x2 0.66225 0.045855 14.442 5.029e-08 Number of observations: 13, Error degrees of freedom: 10 Root Mean Squared Error: 2.41 R-squared: 0.979, Adjusted R-Squared 0.974 F-statistic vs. constant model: 230, p-value = 4.41e-09 ```

The new model has the same adjusted R-Squared value (0.974) as the previous model, meaning it is about as good a fit. All the terms in the new model have extremely low -values.

expand all

Alternatives

Use `stepwiselm` to select a model from a starting model, continuing until no single step is beneficial.

Use `addTerms` to add particular terms.

Use `step` to optimally improve the model by adding or removing terms.

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.