Normal (Gaussian) Distribution

DESCRIPTION:
Density, cumulative probability, quantiles and random generation for the normal (also called Gaussian) distribution.

USAGE:
dnorm(x, mean=0, sd=1)
pnorm(q, mean=0, sd=1)
qnorm(p, mean=0, sd=1)
rnorm(n, mean=0, sd=1)

REQUIRED ARGUMENTS:
x:
vector of quantiles. Missing values (NAs) are allowed.
q:
vector of quantiles. Missing values (NAs) are allowed.
p:
vector of probabilities. Missing values (NAs) are allowed.
n:
sample size. If length(n) is larger than 1, then length(n) random values are returned.

OPTIONAL ARGUMENTS:
mean:
vector of means. This is replicated to be the same length as p or q or the number of deviates generated.
sd:
vector of (positive) standard deviations. This is replicated to be the same length as p or q or the number of deviates generated.

VALUE:
density (dnorm), probability (pnorm), quantile (qnorm), or random sample (rnorm) for the normal distribution with mean and standard deviation parameters mean and sd.

SIDE EFFECTS:
The function rnorm causes creation of the dataset .Random.seed if it does not already exist, otherwise its value is updated.

DETAILS:
Elements of q or p that are missing will cause the corresponding elements of the result to be missing.

The ratio of uniform deviates is used by rnorm to generate normal deviates (Kinderman and Monahan, 1977). The average number of uniform deviates used per normal deviate is 8/sqrt(exp(1)*pi) which is about 2.74.


BACKGROUND:
The Gaussian or normal distribution is the most widely used in Statistics. It is real valued and symmetric about mean. There are two major reasons for the dominance of the Gaussian distribution. The first is that the mathematics tend to be relatively simple, and the second is that often the random mechanism can be specified as approximately Gaussian due to the Central Limit Theorem. The simplest Central Limit Theorem states that the average of independent and identically distributed random variables whose variances exist approaches the Gaussian distribution as the number of random variables in the average goes to infinity. The result can still be true when these assumptions are loosened in various ways.

REFERENCES:
Johnson, N. L. and Kotz, S. (1970). Continuous Univariate Distributions, vol. 1. Houghton-Mifflin, Boston.

Kinderman, A. J. and Monahan, J. F. (1977). Computer generation of random variables using the ratio of uniform deviates. ACM Transactions on Mathematical Software. 3 257-260.


SEE ALSO:
set.seed , Chisquare , F , Lognormal , dnrange , qqnorm .

EXAMPLES:
rnorm(20, 0, 10) #sample of 20, mean 0, standard dev. 10

# a function to generate random multivariate Gaussians rmultnorm <- function(n, mu, vmat, tol = 1e-07) { p <- ncol(vmat) if(length(mu)!=p) stop("mu vector is the wrong length") if(max(abs(vmat - t(vmat))) > tol) stop("vmat not symmetric") vs <- svd(vmat) vsqrt <- t(vs$v %*% (t(vs$u) * sqrt(vs$d))) ans <- matrix(rnorm(n * p), nrow = n) %*% vsqrt ans <- sweep(ans, 2, mu, "+") dimnames(ans) <- list(NULL, dimnames(vmat)[[2]]) ans }