Normal Distribution in R – Basic Probability Distribution

1. Objective

In this tutorial, we will be going to learn about Normal Distribution in R. Moreover, we will cover different functions which will help in generating the normal distribution. Along with this, we will include graphs for easy representation and understanding.

So, let’s start Normal Distribution in R.

Normal Distribution in R - Basic Probability distribution

Normal Distribution in R – Basic Probability distribution

2. What is Normal Distribution in R?

Generally, it is observed that the collection of random data from independent sources is distributed normally.We get a bell shape curve on plotting a graph with the value of the variable on the horizontal axis and the count of the values in the vertical axis. The center of the curve represents the mean of the dataset.
It has four inbuilt functions. They are described below:

  • dnorm(x, mean, sd)
  • qnorm(p, mean, sd)
  • pnorm(x, mean, sd)
  • rnorm(n, mean, sd)

Description of the parameters used in above functions −

  • x is a vector of numbers.
  • p is a vector of probabilities.
  • n is a number of observations(sample size).
  • here mean is the mean value of the sample data. Also, its default value is zero.
  • sd is the standard deviation. Its default value is 1.

i. Functions to generate Normal Distribution

a. dnorm()

The height of the probability distribution at each point for a given mean and standard deviation is provided by this function.
Purpose: Probability Density Function (PDF)
Syntax: dnorm(x, mean, sd)
For Example:
Create a sequence of numbers between -10 and 10 incrementing by 0.1.
x <- seq(-10, 10, by = .1)

# Choose the mean as 2.5 and standard deviation as 0.5.
y <- dnorm(x, mean = 2.5, sd = 0.5)

# Give the chart file a name.
png(file = “dnorm.png”)

plot(x,y)

# Save the file.
dev.off()
When we execute the above code, it produces the following result −

Normal Distribution in R - Basic Probability distribution

Normal Distribution in R – Basic Probability distribution

b. pnorm()

Purpose: Cumulative Distribution Function (CDF)
Syntax:pnorm(q, mean, sd)
For Example:
Create a sequence of numbers between -10 and 10 incrementing by 0.2.
x <- seq(-10,10,by = .2)

# Choose the mean as 2.5 and standard deviation as 2.
y <- pnorm(x, mean = 2.5, sd = 2)

# Give the chart file a name.
png(file = “pnorm.png”)

# Plot the graph.
plot(x,y)

# Save the file.
dev.off()
When we execute the above code, it produces the following result −

Normal Distribution in R - Basic Probability distribution

Normal Distribution in R – Basic Probability distribution

c. qnorm()

Purpose:Quantile Function – inverse of pnorm
Syntax: qnorm(p, mean, sd)
For Example:
Create a sequence of probability values incrementing by 0.02.
x <- seq(0, 1, by = 0.02)

# Choose the mean as 2 and standard deviation as 3.
y <- qnorm(x, mean = 2, sd = 1)

# Give the chart file a name.
png(file = “qnorm.png”)

# Plot the graph.
plot(x,y)

# Save the file.
dev.off()
When we execute the above code, it produces the following result −

Normal Distribution in R - Basic Probability distribution

Normal Distribution in R – Basic Probability distribution

d. rnorm()

Purpose: Generates random numbers from normal distribution
Syntax: rnorm(n, mean, sd)
For Example:
Create a sample of 50 numbers which are normally distributed.
y <- rnorm(50)

# Give the chart file a name.
png(file = “rnorm.png”)

# Plot the histogram for this sample.
hist(y, main = “Normal DIstribution”)

# Save the file.
dev.off()
When we execute the above code, it produces the following result −

Normal Distribution in R - Basic Probability distribution

Normal Distribution in R – Basic Probability distribution

So, this was all in Normal Distribution in R. Hope you like our explanation.

3. Conclusion

Hence, we have studied Normal distribution in R in detail. Moreover, we have learned different functions which are used in generating Normal Distribution. In the above-mentioned information, we have used graphs as well as syntax and examples also which helps you a lot in an understanding of R Normal distribution and their functions. Still, if you have any query regarding Normal distributions in R, ask in the comment tab.

Reference for R

No Responses

  1. goppisetti nagapujitha says:

    it is short so extanded the information

Leave a Reply

Your email address will not be published. Required fields are marked *