e-Mathematics > Probability and Statistics
for 3470-001 student.

Normal Distributions

The normal density function is calculated by
pdf = dnorm(x, mu, sigma)
with mean parameter $ \mu$ and standard deviation $ \sigma$, and its cumulative distribution function is obtained by pnorm(). As special cases,
pnorm(x, mu, sigma)
returns 0 or 1 when x=-Inf or x=+Inf is specified respectively. Some of arguments typically have their default values. The values mu = 0 and sigma = 1 are set by default for dnorm() and pnorm(), and
y = dnorm(x)
returns the values of the standard normal density function at x. Standard normal distribution table contains the area under the standard normal curve $ N(0,1)$ from $ Z=0$ to $ Z=z$. This table can be used to compute the probability involving a normal random variable.

mu = 10
sigma = 5
intval = c(5,20);
range = c(mu-3.5*sigma,mu+3.5*sigma);
x = seq(range[1], range[2], length=100);
y = dnorm(x,mu,sigma);
plot(x, y, type='l', lwd=1, frame.plot=F, main='Normal Distribution');
x = seq(max(c(range[1],intval[1])),
        min(c(range[2],intval[2])), length = 50);
y = dnorm(x,mu,sigma);
polygon(c(x,max(x),min(x)), c(y,0,0), col = 'green');
prob = pnorm(intval[2],mu,sigma) - pnorm(intval[1],mu,sigma);
text((min(x)+max(x))/2, 0, round(prob,digits=4), pos=3);
prob

Programming Note. The function text(x,y,string) displays the string at the coordinate $ (x,y)$ on the graphics. The option pos=n specified the position (1) below, (2) to the left, (3) above and (4) to the right of the coordinates.

Sample R code. You can download normal.R, and run it.

Quantile function. The quantile function of normal distribution is obtained by qnorm().

c = qnorm(p,mu,sigma)
returns the value $ c$ so that $ P(X < c) = p$.

p = 0.95;
range = c(-5,5);
x = seq(range[1], range[2], length=100);
y = dnorm(x);
plot(x, y, type='l', lwd=1, frame.plot=F);
cvalue = qnorm(p);
x = seq(min(c(range[1],cvalue)), cvalue, length = 50);
y = dnorm(x);
polygon(c(x,max(x),min(x)), c(y,0,0), col = 'green');
text(x[50]-2, 0.05, p);
text(x[50],0.2*y[50], round(cvalue,digits=4), pos=4);
cvalue

Sample R code. You can download qnorm.R, and run it.


© TTU Mathematics