# coefTest

Linear hypothesis test on nonlinear regression model coefficients

## Syntax

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

## Description

example

````p = coefTest(mdl)` computes the p-value for an F-test that all coefficient estimates in `mdl` are zero.```
````p = coefTest(mdl,H)` performs an F-test that H × B = 0, where B represents the coefficient vector. Use `H` to specify the coefficients to include in the F-test.```
````p = coefTest(mdl,H,C)` performs an F-test that H × B = C. ```
``````[p,F] = coefTest(___)``` also returns the F-test statistic `F` using any of the input argument combinations in previous syntaxes.```
``````[p,F,r] = coefTest(___)``` also returns the numerator degrees of freedom `r` for the test.```

## Examples

collapse all

Make a nonlinear model of mileage as a function of the weight from the `carsmall` data set. Test the coefficients to see if all should be zero.

Create an exponential model of car mileage as a function of weight from the `carsmall` data. Scale the weight by a factor of 1000 so all the variables are roughly equal in size.

```load carsmall X = Weight; y = MPG; modelfun = 'y ~ b1 + b2*exp(-b3*x/1000)'; beta0 = [1 1 1]; mdl = fitnlm(X,y,modelfun,beta0);```

Test the model for significant differences from a constant model.

`p = coefTest(mdl)`
```p = 1.3708e-36 ```

There is no doubt that the model contains nonzero terms.

## Input Arguments

collapse all

Nonlinear regression model object, specified as a `NonLinearModel` object created by using `fitnlm`.

Hypothesis matrix, specified as a numeric index matrix with one column for each coefficient in the model.

• If you specify `H`, then the output `p` is the p-value for an F-test that H × B = 0, where B represents the coefficient vector.

• If you specify `H` and `C`, then the output `p` is the p-value for an F-test that H × B = C.

Data Types: `single` | `double`

Hypothesized value for testing the null hypothesis, specified as a numeric vector with the same number of rows as `H`.

If you specify `H` and `C`, then the output `p` is the p-value for an F-test that H × B = C, where B represents the coefficient vector.

Data Types: `single` | `double`

## Output Arguments

collapse all

p-value for 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.

collapse all

### Test Statistics

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

• The data comes from a normal distribution.

• The entries are independent.

Suppose these assumptions hold. Let β represent the unknown coefficient vector of the linear regression. Suppose H is a full-rank numeric index matrix of size r-by-s, where r is the number of linear combinations of coefficients being tested, and s is the number of terms in β. Let c be a vector the same size as β. The following is a test statistic for the hypothesis that  = c:

`$F={\left(H\stackrel{^}{\beta }-c\right)}^{\prime }{\left(HV{H}^{\prime }\right)}^{-1}\left(H\stackrel{^}{\beta }-c\right)/r.$`

Here $\stackrel{^}{\beta }$ is the estimate of the coefficient vector β in `mdl.Coefs`, and V 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.

## Alternatives

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

## Version History

Introduced in R2012a