Normal Distribution in R Programming

In statistics, the normal distribution is a type of probability function. Normal distribution tells the user about the distribution of data values in the dataset. It is a very important probability function among all other probability functions because of its advantages. Real case scenarios of the normal distribution are rolling dice, identifying the size of a shoe, the IQ level of any individual, the height of the population, etc.

In most cases, we can say that the data is normally distributed when the random collection of data is from independent sources. When you plot a normal distribution curve, you get a bell-shaped curve. We can say that the distribution of normal distribution is symmetric.

A Bell-shaped curve means that the peak of the graph represents the mean of our dataset. And the values of the graph are divided into 2 sections, half of the values on the left-hand side of the mean and half on the right-hand side of the mean.

The values are shaped properly and follow a continuous probability distribution all over the curve in the normal distribution. In most cases, all the data values are close to the center peak of the distribution.

There are 4 in-built functions provided in R to generate normal distribution. They are as follows:

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


Description of above parameters:
x = vector of numbers
p = vector of probabilities
n = number of observations
mean = mean value of our data(The default value of mean is 0)
sd = sd stands for standard deviation(The default value of sd is 1)

Let’s discuss all the in-built functions of normal distribution one by one.

a) dnorm:

  • dnorm is the distribution of data in terms of probability density.
  • Syntax of dnorm is as follows:

In the below example, we are creating a sequence of numbers from -10 to10.

dnorm(x, mean, sd)


where, 
x = vector of numbers
mean = mean value of our data
sd = standard deviation of our data

CODE:

# NORMAL DISTRIBUTION
# dnorm
# We are Creating a sequence of numbers between -10 and 10.
# And we are incrementing by 0.1.


x <- seq(-10, 10, by = .1)


# Choosing the mean as 2.5 and standard deviation as 0.5 in the 
# above example


y <- dnorm(x, mean = 2.5, sd = 0.5)


# Plotting the normal distribution curve by using the plot() function.
plot(x,y)

OUTPUT:

NORMAL DISTRIBUTION IN R PROGRAMMING

b) pnorm:

  • pnorm is used to get the cumulative distribution in terms of the probability of the data values.
  • Syntax of pnorm is as follows:
pnorm(x, mean, sd)


where, 
x = vector of numbers
mean = mean value of our data
sd = standard deviation of our data

CODE:

# NORMAL DISTRIBUTION
# pnorm
# We are Creating a sequence of numbers between -10 and 10.
# And we are incrementing by 0.2.


x <- seq(-10,10,by = .2)


# Choosing the mean as 2.5 and standard deviation as 0.5 in the 
# above example


y <- pnorm(x, mean = 2.5, sd = 2)




# Plotting the normal distribution curve of the pnorm() function.
plot(x,y)

OUTPUT:

NORMAL DISTRIBUTION IN R PROGRAMMING

c) qnorm:

  • qnorm() function takes the probability value, giving the output corresponding to its probability value.
  • Syntax of qnorm() function is as follows:
qnorm(p, mean, sd)


where, 
p = vector of probabilities
mean = mean value of our data(Default value of mean is 0)
sd = sd stands for standard deviation(The default value of sd is 1)

CODE:

# NORMAL DISTRIBUTION
# qnorm
# We are Creating a sequence of numbers between -10 and 10.
# And we are incrementing by 0.02.


# Here, we are creating a sequence of probability values 
# And we are incrementing by 0.2.
x <- seq(0, 1, by = 0.02)


y <- qnorm(x, mean(x), sd(x))


# Plotting the normal distribution curve of the qnorm() function.
plot(x, y)


OUTPUT:

NORMAL DISTRIBUTION IN R PROGRAMMING

d) rnorm:

  • rnorm() function will give us random numbers from our dataset with the specified mean and standard deviation, normally distributed in nature.
  • Syntax of rnorm() is as follows:
rnorm(n, mean, sd)


where, 
n = number of observations
mean = mean value of our data(the default value of mean is 0)
sd = sd stands for standard deviation(the default value of sd is 1)

CODE:

# NORMAL DISTRIBUTION
# rnorm
# we are plotting histogram in this example.
x <- rnorm(50)
hist(x, main = "Normal Distribution", col = "lightpink")

OUTPUT:

NORMAL DISTRIBUTION IN R PROGRAMMING

Related Topics

R Variables, Constants and Reserved Words

R Variables Variables are very similar to an open box, where you can put any value of your wish. We can change the values as well. Variables are used to store...

4 minutes read.

How to create Histograms in R

R Histograms A Histogram is the graphical representation of the distribution of numeric data. It takes only one numeric variable as input. The variable is cut into several bars (also called...

2 minutes read.

Clustering in R Programming

The clustering technique is an unsupervised machine learning in R programming. Before discussing clustering techniques, let's have a look at what unsupervised machine learning is?  Unsupervised learning is training the model with...

3 minutes read.

Bubble Chart in R Programming

In this article, we will talk about another type of chart in R programming, i.e., the Bubble chart. A bubble chart is a type of data visualization chart that helps display multiple...

4 minutes read.

Measures of Central Tendency in R Programming

Central Tendency or CT is one of the features of descriptive statistics. The Central tendency will let us know how the various groups of data are clustered around the central...

4 minutes read.

Linear Regression in R Programming

Linear Regression is an unsupervised machine learning algorithm in R programming. Linear Regression is a type of regression analysis that shows the relationship between two or more variables. And one...

3 minutes read.

R Functions

In programming, a function is a group of instructions that you want to use repeatedly, because of their complexity, are better self-contained in sub-program and called when needed. Hence, we can...

4 minutes read.

Decision Tree in R Programming

The decision tree uses the branching method to show every possible output for the specific input. We can draw a decision tree by hand or create it using specialized software...

2 minutes read.

R Operators

A symbol that tells the compiler to perform specific mathematical or logical operations is called operator. R language supports mainly 5 different types of operators, which are listed below: Arithmetic...

3 minutes read.

R Date and Time

R provides very large range of capabilities to deal with times and dates. Generally, dates are internally stored as integers, and depending on the operations we will need, we could...

3 minutes read.

First R Program

First  Hello World R Program As a convention, our first R program will be the “Hello World!” program. We can run our R program either at R command prompt or we...

3 minutes read.

Scatter Plot in R Programming

A Scatter plot is a type of dispersion graph built to represent the various data points of variables. A Scatter plot is also known as a scatter graph or scattergram.  A scatter plot is used...

4 minutes read.

Poisson Distribution in R Programming

Poisson distribution is a type of distribution that deals with the probability distribution of the data values by taking the mean into consideration. Poisson distribution will estimate the probability value for...

3 minutes read.

Logistic Regression in R Programming

Logistic Regression is a classification supervised machine learning algorithm in R programming. Logistic Regression can also be termed Binomial Logistic Regression, Binary Logistic Regression, or Logit Model. Logistic Regression is...

4 minutes read.

Various types of Charts in R Programming

As we know, R Language is mostly used for analyzing the data and statistics purposes to represent our data graphically & pictorially in R studio. Charts and graphs are plotted in...

4 minutes read.

R If Else Statement

If statement It is the most simple decision-making statement. It checks the condition if the condition is true then only it will execute the block of statements written in the ‘if...

2 minutes read.

How to make Boxplots in R

R Boxplots Boxplot is a measure of how well the data is distributed in a data set. It is used to give a summary of one or several numeric variables. The...

3 minutes read.

Pie Charts in R Programming

R programming has various libraries to plot various types of charts and graphs. A pie chart is a circular statistical chart or graph, which is divided into slices to represent the numerical...

4 minutes read.

R Switch Statement

It is an alternate way to a nested if…else statement. A switch statement permits an expression to be tested against a list of case values. In short, we can say...

1 minute read.

Binomial Distribution in R Programming

In this article, we will talk about the Binomial distribution in R programming. The binomial distribution is a type of probability distribution. As it is a discrete distribution, it will...

3 minutes read.