Learn R Programming

EnvStats (version 3.0.0)

cv: Sample Coefficient of Variation.

Description

Compute the sample coefficient of variation.

Usage

cv(x, method = "moments", sd.method = "sqrt.unbiased", 
    l.moment.method = "unbiased", plot.pos.cons = c(a = 0.35, b = 0), 
    na.rm = FALSE)

Value

A numeric scalar -- the sample coefficient of variation.

Arguments

x

numeric vector of observations.

method

character string specifying what method to use to compute the sample coefficient of variation. The possible values are "moments" (product moment ratio estimator; the default), or "l.moments" (L-moment ratio estimator).

sd.method

character string specifying what method to use to compute the sample standard deviation when method="moments". The possible values are "sqrt.ubiased" (the square root of the unbiased estimate of variance; the default), or "moments" (the method of moments estimator).

l.moment.method

character string specifying what method to use to compute the \(L\)-moments when method="l.moments". The possible values are "ubiased" (method based on the \(U\)-statistic; the default), or "plotting.position" (method based on the plotting position formula).

plot.pos.cons

numeric vector of length 2 specifying the constants used in the formula for the plotting positions when method="l.moments" and
l.moment.method="plotting.position". The default value is
plot.pos.cons=c(a=0.35, b=0). If this vector has a names attribute with the value c("a","b") or c("b","a"), then the elements will be matched by name in the formula for computing the plotting positions. Otherwise, the first element is mapped to the name "a" and the second element to the name "b".

na.rm

logical scalar indicating whether to remove missing values from x. If
na.rm=FALSE (the default) and x contains missing values, then a missing value (NA) is returned. If na.rm=TRUE, missing values are removed from x prior to computing the coefficient of variation.

Author

Steven P. Millard (EnvStats@ProbStatInfo.com)

Details

Let \(\underline{x}\) denote a random sample of \(n\) observations from some distribution with mean \(\mu\) and standard deviation \(\sigma\).

Product Moment Coefficient of Variation (method="moments")
The coefficient of variation (sometimes denoted CV) of a distribution is defined as the ratio of the standard deviation to the mean. That is: $$CV = \frac{\sigma}{\mu} \;\;\;\;\;\; (1)$$ The coefficient of variation measures how spread out the distribution is relative to the size of the mean. It is usually used to characterize positive, right-skewed distributions such as the lognormal distribution.

When sd.method="sqrt.unbiased", the coefficient of variation is estimated using the sample mean and the square root of the unbaised estimator of variance: $$\widehat{CV} = \frac{s}{\bar{x}} \;\;\;\;\;\; (2)$$ where $$\bar{x} = \frac{1}{n} \sum_{i=1}^n x_i \;\;\;\;\;\; (3)$$ $$s = [\frac{1}{n-1} \sum_{i=1}^n (x_i - \bar{x})^2]^{1/2} \;\;\;\;\;\; (4)$$ Note that the estimator of standard deviation in equation (4) is not unbiased.

When sd.method="moments", the coefficient of variation is estimated using the sample mean and the square root of the method of moments estimator of variance: $$\widehat{CV} = \frac{s_m}{\bar{x}} \;\;\;\;\;\; (5)$$ $$s = [\frac{1}{n} \sum_{i=1}^n (x_i - \bar{x})^2]^{1/2} \;\;\;\;\;\; (6)$$

L-Moment Coefficient of Variation (method="l.moments")
Hosking (1990) defines an \(L\)-moment analog of the coefficient of variation (denoted the \(L\)-CV) as: $$\tau = \frac{l_2}{l_1} \;\;\;\;\;\; (7)$$ that is, the second \(L\)-moment divided by the first \(L\)-moment. He shows that for a positive-valued random variable, the \(L\)-CV lies in the interval (0, 1).

When l.moment.method="unbiased", the \(L\)-CV is estimated by: $$t = \frac{l_2}{l_1} \;\;\;\;\;\; (8)$$ that is, the unbiased estimator of the second \(L\)-moment divided by the unbiased estimator of the first \(L\)-moment.

When l.moment.method="plotting.position", the \(L\)-CV is estimated by: $$\tilde{t} = \frac{\tilde{l_2}}{\tilde{l_1}} \;\;\;\;\;\; (9)$$ that is, the plotting-position estimator of the second \(L\)-moment divided by the plotting-position estimator of the first \(L\)-moment.

See the help file for lMoment for more information on estimating \(L\)-moments.

References

Berthouex, P.M., and L.C. Brown. (2002). Statistics for Environmental Engineers, Second Edition. Lewis Publishers, Boca Raton, FL.

Gilbert, R.O. (1987). Statistical Methods for Environmental Pollution Monitoring. Van Nostrand Reinhold, NY.

Ott, W.R. (1995). Environmental Statistics and Data Analysis. Lewis Publishers, Boca Raton, FL.

Taylor, J.K. (1990). Statistical Techniques for Data Analysis. Lewis Publishers, Boca Raton, FL.

Vogel, R.M., and N.M. Fennessey. (1993). \(L\) Moment Diagrams Should Replace Product Moment Diagrams. Water Resources Research 29(6), 1745--1752.

Zar, J.H. (2010). Biostatistical Analysis. Fifth Edition. Prentice-Hall, Upper Saddle River, NJ.

See Also

Summary Statistics, summaryFull, var, sd, skewness, kurtosis.

Examples

Run this code
  # Generate 20 observations from a lognormal distribution with 
  # parameters mean=10 and cv=1, and estimate the coefficient of variation. 
  # (Note: the call to set.seed simply allows you to reproduce this example.)

  set.seed(250) 
  dat <- rlnormAlt(20, mean = 10, cv = 1) 

  cv(dat) 
  #[1] 0.5077981

  cv(dat, sd.method = "moments") 
  #[1] 0.4949403
 
  cv(dat, method = "l.moments") 
  #[1] 0.2804148

  #----------
  # Clean up
  rm(dat)

Run the code above in your browser using DataLab