# nearZeroVar

##### Identification of near zero variance predictors

This function diagnoses predictors that have one unique value (i.e. are zero variance predictors) or predictors that are have both of the following characteristics: they have very few unique values relative to the number of samples and the ratio of the frequency of the most common value to the frequency of the second most common value is large.

- Keywords
- utilities

##### Usage

`nearZeroVar(x, freqCut = 95/5, uniqueCut = 10, saveMetrics = FALSE)`

##### Arguments

- x
- a numeric vector or matrix, or a data frame with all numeric data
- freqCut
- the cutoff for the ratio of the most common value to the second most common value
- uniqueCut
- the cutoff for the percentage of distinct values out of the number of total samples
- saveMetrics
- a logical. If false, the positions of the zero- or near-zero predictors is returned. If true, a data frame with predictor information is returned.

##### Details

For example, an example of near zero variance predictor is one that, for 1000 samples, has two distinct values and 999 of them are a single value.

To be flagged, first the frequency of the most prevalent value over the
second most frequent value (called the ``frequency ratio'') must be
above `freqCut`

. Secondly, the ``percent of unique values,'' the
number of unique values divided by the total number of samples (times
100), must also be below `uniqueCut`

.

In the above example, the frequency ratio is 999 and the unique value percentage is 0.0001.

##### Value

- If
`saveMetrics = FALSE`

, a vector of integers corresponding to the column positions of the problematic predictors. If`saveMetrics = TRUE`

, a data frame with columns: freqRatio the ratio of frequencies for the most common value over the second most common value percentUnique the percentage of unique data points out of the total number of data points zeroVar a vector of logicals for whether the predictor has only one distinct value nzv a vector of logicals for whether the predictor is a near zero variance predictor

##### Examples

```
nearZeroVar(iris[, -5], saveMetrics = TRUE)
data(BloodBrain)
nearZeroVar(bbbDescr)
```

*Documentation reproduced from package caret, version 4.48, License: GPL-2*

### Community examples

**Sratho12@its.jnj.com**at Aug 12, 2019 caret v6.0-84

Hello, I have question on example given in this article, [ For example, an example of near zero variance predictor is one that, for 1000 samples, has two distinct values and 999 of them are a single value. To be flagged, first the frequency of the most prevalent value over the second most frequent value (called the ``frequency ratio'') must be above freqCut. Secondly, the ``percent of unique values,'' the number of unique values divided by the total number of samples (times 100), must also be below uniqueCut. In the above example, the frequency ratio is 999 and the* unique value percentage is 0.0001.* ] How is unique value percentage derived as 0.0001? As per my understanding it would be ([Number of unique values = 2] / [Total Number if samples =1000]) * 100 Which would be : (2 /1000 ) * 100 -> 0.002* 100 -> 0.02 I feel `percent of unique values' should be 0.02 and not 0.0001. Could you please explain. nzv thanks, Shilpa