Aim

  1. To calculate probability mass density, probability distribution and quantiles using Normal distribution

Packages used and syntax of R methods

Functions from stat package (which is loaded by default).

The probability mass at a point \(x\) can be evaluated using the syntax:

dnorm(x=x,mean=m,sd=s).

The probability distribution \(P(X\leq x)\) is calculated using the pnorm() function. Syntax is:

pnorm(x,mean=m,sd=s)

The quantile for probability \(p\) can be evaluated using the qnorm() function. Syntax is:

qnorm(prob,mean=m,sd=s)

Algorithm

Case: Generate and draw the cdf and pdf of a normal distribution with mean=10 and standard deviation=3. Use values of \(x\) from 0 to 20 in intervals of 1.

R code

# create input parameters
t=seq(0,20,1); mu=10;sd=3

Prbability distribution

#calculating probability mass distribution and cumulative distribution
pmval=dnorm(t,mean = mu,sd=sd)
pmval
##  [1] 0.000514093 0.001477283 0.003798662 0.008740630 0.017996989 0.033159046
##  [7] 0.054670025 0.080656908 0.106482669 0.125794409 0.132980760 0.125794409
## [13] 0.106482669 0.080656908 0.054670025 0.033159046 0.017996989 0.008740630
## [19] 0.003798662 0.001477283 0.000514093

Cumulative probability distribution

#calculating cumulative density
cdval=pnorm(t,mean = mu,sd=sd)
cdval
##  [1] 0.0004290603 0.0013498980 0.0038303806 0.0098153286 0.0227501319
##  [6] 0.0477903523 0.0912112197 0.1586552539 0.2524925375 0.3694413402
## [11] 0.5000000000 0.6305586598 0.7475074625 0.8413447461 0.9087887803
## [16] 0.9522096477 0.9772498681 0.9901846714 0.9961696194 0.9986501020
## [21] 0.9995709397

Plotting the pmf and cdf

par(mfrow=c(1,2))
plot(t,pmval,xlab="t",ylab="P(X=t)", main="The Normal Distribution")
plot(t,cdval,xlab="t",ylab=expression(P(X<=t)),main="Cumulative Distribution Function")

Results & discussions

The pmf and cf of the Normal distribution for given input parameters are evaluated and create respective plots.