Uniform distribution

In R, distributions such as uniform, normal, chi-squared, etc., have a family of 4 functions associated with them. Their names start with 'd', 'p', 'q' and 'r', respectively. Thus, for the uniform distribution, the functions are:

The code below illustrates the usage of the optional parameters of the 'unif' family:

## Create a sequence
x <- seq(-2,2,0.01)

## We choose the following parameters for the
## distribution
range.min = -1
range.max = 1.5

## Setup of 3 plots, atop each other
par(mfcol=c(4,1))

## Probability density function
plot(x, dunif(x, min = range.min, max = range.max), type = 'l',
          ylab = 'density function value')

## Probability distribution function
plot(x, punif(x, min = range.min, max = range.max), type = 'l',
          ylab = 'distribution function value')

## Quantile function (the inverse of the distribution function)
y = seq(0,1,.2)
plot(y, qunif(y, min = range.min, max = range.max), type = 'p',
          ylab = 'quantiles')

## Random sample generator function.
## We submit the result to 'hist' to get a histogram.
hist(runif(500, min = range.min, max = range.max),
          ylab = 'frequencies', nclass=20)

Standard plot of the data