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.

coefTest

Class: CompactLinearModel

Linear hypothesis test on linear regression model coefficients

Syntax

```p = coefTest(mdl)p = coefTest(mdl,H)p = coefTest(mdl,H,C)[p,F] = coefTest(mdl,___)[p,F,r] = coefTest(mdl,___)```

Description

`p = coefTest(mdl)` computes the p-value for an F test that all coefficient estimates in `mdl` are zero, except for the intercept term.

`p = coefTest(mdl,H)` performs an F test that H × B = 0, where B represents the coefficient vector.

`p = coefTest(mdl,H,C)` performs an F test that H × B = C.

```[p,F] = coefTest(mdl,___)``` returns the F test statistic, `F`, using any of the previous syntaxes.

```[p,F,r] = coefTest(mdl,___)``` returns the numerator degrees of freedom, `r`, for the test.

Input Arguments

expand all

Linear model object, specified as a full `LinearModel` object constructed using `fitlm` or `stepwiselm`, or a compacted `CompactLinearModel` object constructed using `compact`.

Hypothesized model coefficients, specified as a numeric matrix with one column for each coefficient in the model. If `H` is an input, then the output `p` is the p-value for an F test that H × B = 0, where B represents the coefficient vector.

Hypothesized value for testing the null hypothesis, specified as a numeric vector with the same number of rows as `H`. When `C` is an input, the output `p` is the p-value for an F test that H × B = C, where B represents the coefficient vector.

Output Arguments

expand all

p-value of the F test, returned as a numeric value in the range [0,1].

Value of the test statistic for the F test, returned as a numeric value.

Numerator degrees of freedom for the F test, returned as a positive integer. The F statistic has `r` degrees of freedom in the numerator and `mdl.DFE` degrees of freedom in the denominator.

Examples

expand all

Fit a linear regression model of mileage as a function of the weight, weight squared, and model year from the `carsmall` data set. Test the coefficients to see if all should be zero.

Load the data and make a table, where the model year is an ordinal variable.

```load carsmall tbl = table(MPG,Weight); tbl.Year = ordinal(Model_Year); mdl = fitlm(tbl,'MPG ~ Year + Weight + Weight^2'); ```

Test the model for significant differences from a constant model.

```p = coefTest(mdl) ```
```p = 5.5208e-41 ```

The returned -value indicates that the fitted model contains more than the intercept term.

Test the `Weight^2` coefficient in a linear model of mileage as a function of the weight, weight squared, and model year.

Load the data and make a table, where the model year is an ordinal variable.

```load carsmall tbl = table(MPG,Weight); tbl.Year = ordinal(Model_Year); mdl = fitlm(tbl,'MPG ~ Year + Weight + Weight^2'); ```

Test the significance of the `Weight^2` coefficient. To do so, find the coefficient corresponding to `Weight^2`.

```mdl.CoefficientNames ```
```ans = 1×5 cell array '(Intercept)' 'Weight' 'Year_76' 'Year_82' 'Weight^2' ```

`Weight^2` is the fifth (final) coefficient.

Test the significance of the `Weight^2` coefficient.

```p = coefTest(mdl,[0 0 0 0 1]) ```
```p = 0.0022 ```

expand all

Alternatives

The values of commonly used test statistics are available in the `mdl.Coefficients` table.

`anova` provides a test for each model term.

See Also

Topics

Was this topic helpful?

Download now