# Documentation

### This is machine translation

Translated by
Mouse over text to see original. Click the button below to return to the English verison of the page.

# lillietest

Lilliefors test

## Syntax

• ``h = lillietest(x)``
example
• ``h = lillietest(x,Name,Value)``
example
• ``````[h,p] = lillietest(___)``````
example
• ``````[h,p,kstat,critval] = lillietest(___)``````
example

## Description

example

````h = lillietest(x)` returns a test decision for the null hypothesis that the data in vector `x` comes from a distribution in the normal family, against the alternative that it does not come from such a distribution, using a Lilliefors test. The result `h` is `1` if the test rejects the null hypothesis at the 5% significance level, and `0` otherwise.```

example

````h = lillietest(x,Name,Value)` returns a test decision with additional options specified by one or more name-value pair arguments. For example, you can test the data against a different distribution family, change the significance level, or calculate the p-value using a Monte Carlo approximation.```

example

``````[h,p] = lillietest(___)``` also returns the p-value `p`, using any of the input arguments from the previous syntaxes. ```

example

``````[h,p,kstat,critval] = lillietest(___)``` also returns the test statistic `kstat` and the critical value `critval` for the test.```

## Examples

collapse all

Load the sample data. Test the null hypothesis that car mileage, in miles per gallon (`MPG`), follows a normal distribution across different makes of cars.

```load carbig.mat; [h,p,k,c] = lillietest(MPG) ```
```Warning: P is less than the smallest tabulated value, returning 0.001. h = 1 p = 1.0000e-003 k = 0.0789 c = 0.0451```

The test statistic `k` is greater than the critical value `c`, so `lillietest` returns a result of `h = 1` to indicate rejection of the null hypothesis at the default 5% significance level. The warning indicates that the returned p-value is the smallest value in the table of precomputed values. To find a more accurate p-value, use `MCTol` to run a Monte Carlo approximation.

Load the sample data. Create a vector containing the first column of the students' exam grades data.

```load examgrades; x = grades(:,1);```

Test the null hypothesis that the sample data comes from a normal distribution at the 1% significance level.

`[h,p] = lillietest(x,'Alpha',0.01)`
```h = 0 p = 0.0348```

The returned value of `h = 0` indicates that `lillietest` does not reject the null hypothesis at the 1% significance level.

Load the sample data. Test the null hypothesis that car mileage, in miles per gallon (`MPG`), follows an exponential distribution across different makes of cars.

```load carbig.mat; h = lillietest(MPG,'Distr','exp')```
```h = 1```

The returned value of `h = 1` indicates that `lillietest` rejects the null hypothesis at the default 5% significance level.

Load the sample data. Test the null hypothesis that car mileage, in miles per gallon (`MPG`), follows a normal distribution across different makes of cars. Determine the p-value using a Monte Carlo approximation with a maximum Monte Carlo standard error of `1e-4`.

```load carbig.mat; [h,p] = lillietest(MPG,'MCTol',1e-4)```
```h = 1 p = 0```

The returned value of `h = 1` indicates that `lillietest` rejects the null hypothesis that the data comes from a normal distribution at the 5% significance level.

## Input Arguments

collapse all

Sample data, specified as a vector.

Data Types: `single` | `double`

### Name-Value Pair Arguments

Specify optional comma-separated pairs of `Name,Value` arguments. `Name` is the argument name and `Value` is the corresponding value. `Name` must appear inside single quotes (`' '`). You can specify several name and value pair arguments in any order as `Name1,Value1,...,NameN,ValueN`.

Example: `'Distr','exp','Alpha',0.01` tests the null hypothesis that the population distribution belongs to the exponential distribution family at the 1% significance level.

collapse all

Significance level of the hypothesis test, specified as the comma-separated pair consisting of `'Alpha'` and a scalar value in the range (0,1).

• If `MCTol` is not used, `Alpha` must be in the range [0.001,0.50].

• If `MCTol` is used, `Alpha` must be in the range (0,1).

Example: `'Alpha',0.01`

Data Types: `single` | `double`

Distribution family for the hypothesis test, specified as the comma-separated pair consisting of `'Distr'` and one of the following.

 `'norm'` Normal distribution `'exp'` Exponential distribution `'ev'` Extreme value distribution

Example: `'Distr','exp'`

Maximum Monte Carlo standard error for `p`, the p-value of the test, specified as the comma-separated pair consisting of `'MCTol'` and a scalar value in the range (0,1).

Example: `'MCTol',0.001`

Data Types: `single` | `double`

## Output Arguments

collapse all

Hypothesis test result, returned as a logical value.

• If `h` `= 1`, this indicates the rejection of the null hypothesis at the `Alpha` significance level.

• If `h` `= 0`, this indicates a failure to reject the null hypothesis at the `Alpha` significance level.

p-value of the test, returned as a scalar value in the range (0,1). `p` is the probability of observing a test statistic as extreme as, or more extreme than, the observed value under the null hypothesis. Small values of `p` cast doubt on the validity of the null hypothesis.

• If `MCTol` is not used, `p` is computed using inverse interpolation into the table of critical values, and is returned as a scalar value in the range [0.001,0.50]. `lillietest` warns when `p` is not found within the tabulated range and returns either the smallest or largest tabulated value.

• If `MCTol` is used, `lillietest` conducts a Monte Carlo simulation to compute a more accurate p-value, and `p` is returned as a scalar value in the range (0,1).

Test statistic, returned as a nonnegative scalar value.

Critical value for the hypothesis test, returned as a nonnegative scalar value.

collapse all

### Lilliefors Test

The Lilliefors test is a two-sided goodness-of-fit test suitable when the parameters of the null distribution are unknown and must be estimated. This is in contrast to the one-sample Kolmogorov-Smirnov test, which requires the null distribution to be completely specified.

The Lilliefors test statistic is:

`${D}^{*}=\underset{x}{\mathrm{max}}|\stackrel{^}{F}\left(x\right)-G\left(x\right)|,$`

where $\stackrel{^}{F}\left(x\right)$ is the empirical cdf of the sample data and $G\left(x\right)$ is the cdf of the hypothesized distribution with estimated parameters equal to the sample parameters.

`lillietest` can be used to test whether the data vector `x` has a lognormal or Weibull distribution by applying a transformation to the data vector and running the appropriate Lilliefors test:

• To test `x` for a lognormal distribution, test if `log(x)` has a normal distribution.

• To test `x` for a Weibull distribution, test if `log(x)` has an extreme value distribution.

The Lilliefors test cannot be used when the null hypothesis is not a location-scale family of distributions.

### Monte Carlo Standard Error

The Monte Carlo standard error is the error due to simulating the p-value.

The Monte Carlo standard error is calculated as:

`$SE=\sqrt{\frac{\left(\stackrel{^}{p}\right)\left(1-\stackrel{^}{p}\right)}{\text{mcreps}}},$`

where $\text{p^}$ is the estimated p-value of the hypothesis test, and `mcreps` is the number of Monte Carlo replications performed.

The number of Monte Carlo replications, `mcreps`, is determined such that the Monte Carlo standard error for $\text{p^}$ less than the value specified for `MCTol`.

### Algorithms

To compute the critical value for the hypothesis test, `lillietest` interpolates into a table of critical values pre-computed using Monte Carlo simulation for sample sizes less than 1000 and significance levels between 0.001 and 0.50. The table used by `lillietest` is larger and more accurate than the table originally introduced by Lilliefors. If a more accurate p-value is desired, or if the desired significance level is less than 0.001 or greater than 0.50, the `MCTol` input argument can be used to run a Monte Carlo simulation to calculate the p-value more exactly.

When the computed value of the test statistic is greater than the critical value, `lillietest` rejects the null hypothesis at significance level `Alpha`.

`lillietest` treats `NaN` values in `x` as missing values and ignores them.

## References

[1] Conover, W. J. Practical Nonparametric Statistics. Hoboken, NJ: John Wiley & Sons, Inc., 1980.

[2] Lilliefors, H. W. "On the Kolmogorov-Smirnov test for the exponential distribution with mean unknown." Journal of the American Statistical Association. Vol. 64, 1969, pp. 387–389.

[3] Lilliefors, H. W. "On the Kolmogorov-Smirnov test for normality with mean and variance unknown." Journal of the American Statistical Association. Vol. 62, 1967, pp. 399–402.