# R Programming/Probability Distributions

R Programming
* R Basics
** Introduction
** Sample Session
** Manage your workspace
** Settings and Installation
** Documentation
** Control Structures
** Working with functions
** Debugging
** Using C or Fortran
** Utilities
** Estimation utilities
** Packages
* Data Management
** Data types
** Working with data frames
** Importing and exporting data
** Text Processing
** Times and Dates
* Graphics
** Grammar of graphics
* Publication quality output
* Descriptive Statistics
* Mathematics
** Optimization
** Probability Distributions
** Random Number Generation
* Statistical Core Methods
** Maximum Likelihood
** Method of Moments
** Bayesian Methods
** Bootstrap
** Multiple Imputation
** Nonparametric Methods
* Regression Models
** Linear Models
** Quantile Regression
** Binomial Models
** Multinomial Models
** Tobit And Selection Models
** Count Data Models
** Duration Analysis
* Time Series
* Factor Analysis
* Classification
** Ordination
** Clustering
* Network Analysis
* High Performance Computing
** Profiling R code
** Parallel computing with R
* Appendix
** Sources
** Index
This page review the main probability distributions and describe the main R functions to deal with them.
R has lots of probability functions.
* r is the generic prefix for random variable generator such as runif, rnorm.
* d is the generic prefix for the probability density function such as dunif, dnorm.
* p is the generic prefix for the cumulative density function such as punif, pnorm.
* q is the generic prefix for the quantile function such as qunif, qnorm.

## Discrete distributions
### Benford Distribution

The Benford distribution is the distribution of the first digit of a number. It is due to Benford 1938 and Newcomb 1881.

### Bernoulli

We can draw from a Bernoulli using sample, runif or rbinom with size = 1.

### Binomial

We can sample from a binomial distribution using the rbinom function with arguments n for number of samples to take, size defining the number of trials and prob defining the probability of success in each trial.

### Hypergeometric distribution

We can sample n times from a hypergeometric distribution using the rhyper function.

### Geometric distribution

The geometric distribution.

### Multinomial

The multinomial distribution.

### Negative binomial distribution

The negative binomial distribution is the distribution of the number of failures before k successes in a series of Bernoulli events.

### Poisson distribution

We can draw n values from a Poisson distribution with a mean set by the argument lambda.

### Zipf's law

The distribution of the frequency of words is known as Zipf's Law. It is also a good description of the distribution of city size. dzipf and pzipf (VGAM)

## Continuous distributions
### Beta and Dirichlet distributions

* Beta distribution
* Dirichlet in gtools and MCMCpack

### Cauchy

We can sample n values from a Cauchy distribution with a given location parameter $x_{0}$ (default is 0) and scale parameter $\gamma$ (default is 1) using the rcauchy function.

### Chi Square distribution

Quantile of the Chi-square distribution ($\chi ^{2}$ distribution)

### Exponential

We can sample n values from a exponential distribution with a given rate (default is 1) using the rexp function

### Fisher-Snedecor

We can draw the density of a Fisher distribution (F-distribution) :

### Gamma

We can sample n values from a gamma distribution with a given shape parameter and scale parameter $\theta$ using the rgamma function. Alternatively a shape parameter and rate parameter $\beta =1/\theta$ can be given.

### Levy

We can sample n values from a Levy distribution with a given location parameter $\mu$ (defined by the argument m, default is 0) and scaling parameter (given by the argument s, default is 1) using the rlevy function.

### Log-normal distribution

We can sample n values from a log-normal distribution with a given meanlog (default is 0) and sdlog (default is 1) using the rlnorm function

### Normal and related distributions

We can sample n values from a normal or gaussian Distribution with a given mean (default is 0) and sd (default is 1) using the rnorm function
Quantile of the normal distribution
* The mvtnorm package includes functions for multivariate normal distributions.
** rmvnorm generates a multivariate normal distribution.

### Pareto Distributions

* Generalized Pareto dgpd in evd
* dpareto, ppareto, rpareto, qpareto in actuar
* The VGAM package also has functions for the Pareto distribution.

### Student's t distribution

Quantile of the Student t distribution
The following lines plot the .975th quantile of the t distribution in function of the degrees of freedom :

### Uniform distribution

We can sample n values from a uniform distribution (also known as a rectangular distribution] between two values (defaults are 0 and 1) using the runif function

### Weibull

We can sample n values from a Weibull distribution with a given shape and scale parameter $\mu$ (default is 1) using the rweibull function.

### Extreme values and related distribution

* The Gumbel distribution
* The logistic distribution : distribution of the difference of two gumbel distributions.
plogis, qlogis, dlogis, rlogis
* Frechet dfrechet evd
* Generalized Extreme Value dgev evd
* Gumbel dgumbel evd
* Burr, dburr, pburr, qburr, rburr in actuar

### Distribution in circular statistics

* Functions for circular statistics are included in the CircStats package.
** dvm Von Mises (also known as the nircular normal or Tikhonov distribution) density function
** dtri triangular density function
** dmixedvm Mixed Von Mises density
** dwrpcauchy wrapped Cauchy density
** dwrpnorm wrapped normal density.

## See also

* Packages VGAM, SuppDists, actuar, fBasics, bayesm, MCMCpack

## References

* ↑ Benford, F. (1938) The Law of Anomalous Numbers. Proceedings of the American Philosophical Society, 78, 551–572.
* ↑ Newcomb, S. (1881) Note on the Frequency of Use of the Different Digits in Natural Numbers. American Journal of Mathematics, 4, 39–40.
* ↑ Gabaix, Xavier (August 1999). "Zipf's Law for Cities: An Explanation". Quarterly Journal of Economics 114 (3): 739–67. doi:10.1162/003355399556133. ISSN 0033-5533. http://pages.stern.nyu.edu/~xgabaix/papers/zipf.pdf.