Accelerating the pace of engineering and science

# coefTest

Class: LinearModel

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.

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

## Input Arguments

 mdl Linear model, as constructed by fitlm or stepwiselm. H Numeric matrix having one column for each coefficient in the model. When H is an input, the output p is the p-value for an F test that H*B = 0, where B represents the coefficient vector. C 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

 p p-value of the F test (see Definitions). F Value of the test statistic for the F test (see Definitions). r Numerator degrees of freedom for the F test (see Definitions). The F statistic has r degrees of freedom in the numerator and mdl.DFE degrees of freedom in the denominator.

## Definitions

### Test Statistics

The p-value, F statistic, and numerator degrees of freedom are valid under these assumptions:

• The data comes from a model represented by the formula mdl.Formula.

• The observations are independent conditional on the predictor values.

Suppose these assumptions hold. Let β represent the (unknown) coefficient vector of the linear regression. Suppose H is a full-rank matrix of size r-by-s, where s is the number of terms in β. Let v be a vector the same size as β. The following is a test statistic for the hypothesis that  = v:

$F={\left(H\stackrel{^}{\beta }-v\right)}^{\prime }{\left(HC{H}^{\prime }\right)}^{-1}\left(H\stackrel{^}{\beta }-v\right).$

Here $\stackrel{^}{\beta }$ is the estimate of the coefficient vector β in mdl.Coefs, and C is the estimated covariance of the coefficient estimates in mdl.CoefCov. When the hypothesis is true, the test statistic F has an F Distribution with r and u degrees of freedom.

## Examples

expand all

### Test Linear Regression Model

Make a linear 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```

There is no doubt that the model contains more than the intercept term.

### Test a Particular Coefficient

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 =

'(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```

## Alternatives

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

anova provides a test for each model term.