EDUCBA

EDUCBA

MENUMENU
  • Blog
  • Free Courses
  • All Courses
  • All in One Bundle
  • Login
Home Data Science Data Science Tutorials R Programming Tutorial R Normal Distribution

R Normal Distribution

By Priya PedamkarPriya Pedamkar

R Normal Distribution

Introduction to R Normal Distribution

The following article provides an outline for R Normal Distribution. Normal Distribution is one of the fundamental concepts in Statistics. It is defined by the equation of probability density function. The probability density function is defined as the normal distribution with mean and standard deviation.

The above definition is suited in statistics, but in R, “It is the collection of data from different independent sources.” The variables are assigned on the horizontal axis, and the count of those values is on the vertical axis. The center of the curve represents the mean. In the ideal normally distributed graph, half of the variable values lie to the left, half of them to the right of the mean.

Start Your Free Data Science Course

Hadoop, Data Science, Statistics & others

Plotting the Graph

Before we plot a graph, We need to generate a sequence of values to plot them.

In R, we use a function called seq() to generate a set of random values between two integers. Let’s generate random values that help us in plotting the normally distributed graph.

Code:

seq(-2,2,length=50)

In the above function, we generate 50 values that are in between -2 and 2. Below are the values generated and stored in the variable x.

Output:

R Normal distrubition1

Functions in R Normal Distribution

There are four different functions to generate a normal distribution plot.

  • dnorm
  • pnorm
  • qnorm
  • rnorm

Parameters:

  • x is a vector of numbers.
  • p is a set of probabilities.
  • n is no. of observations.
  • Mean is the mean value of the data. The default value is zero.
  • sd is the standard deviation. The default value is 1.

1. dnorm()

The function is used to give the probability distribution of a specified mean and the standard deviation.

Syntax: dnorm(x, mean, sd)

x – vector of numbers. Mean-mean value of the data. The default value is zero. sd-standard deviation. The default value is 1.

Code:

# Create a sequence of numbers between -5 and 5 incrementing it by 0.2.
x <- seq(-5, 5, by = .1)
# The mean here is 2.0 and standard deviation as 0.5.
y <- dnorm(x, mean = 2.0, sd = 0.5)
#Plot the Graph
plot(x,y)
# Saving the file.
dev.off()

Output:

R Normal distrubition2

Steps Used to Plot the Normal Distribution Plot:

  1. We have created the sequence by incrementing it by x number.
  2. We use the function with the standard set of parameters like mean and standard deviation.
  3. Plot the graph with x,y values.
  4. You can create the chart and save the file using the below commands.

To Give the Filename: png(file = “disnorm.png”)

To Save the File: dev.off()

2. pnorm()

pnorm function is used to generate the cumulative distribution function. The cumulative distribution function of a random variable X, it is the probability of the value x can take that is less or equal to X.

Syntax: pnorm(x, mean, sd)

Code:

# Create a sequence of numbers between -5 and 5 incrementing by 0.2.
x <- seq(-5,5,by = .2)
# mean is 2.0 and standard deviation as 1.
y <- pnorm(x, mean = 2.0, sd = 1)
# Plot the graph.
plot(x,y)
# Saving the file.
dev.off()

Output:
pnorm function

3. qnorm()

qnorm function takes the probability value and returns the cumulative value that matches the probability value.

Syntax: qnorm(p, mean, sd)

Code:

# Creating a sequence of probability values incrementing by 0.04.
x <- seq(0, 1, by = 0.04)
# mean is 2 and standard deviation as 1.
y <- qnorm(x, mean = 2, sd = 1)
# Plotting the graph.
plot(x,y)
# Saving the file.
dev.off()

Output:

qnorm function

4. Rnorm()

Rnorm generates random numbers that are normally distributed. We use the random numbers and plot them on the histogram to show normally distributed numbers.

Syntax: rnorm(n, mean, sd)

mean-mean value of the data. The default value is zero. sd-standard deviation. The default value is 1. p is a set of probabilities.

Code:

# Sample of 25 numbers which are normally distributed.
y <- rnorm(25)
# Plot the histogram for this sample.
hist(y, main = "Normal DIstribution Histogram")
# Save the file.
dev.off()

Output:

Rnorm generates

Let’s now tweak the histogram by adding the color by using the simple parameter col: “color.”

Color: You Can Input Any Color. The above function can be tweaked as below to change to solid colors.

Code:

hist(y, main = "Normal Distribution Histogram",col="blue" )

Output:

R Normal distrubition6

We can use the “col” parameter with any of the above four functions.

Advantages of R Normal Distribution

Given below are the advantages mentioned:

  • Most of the quantities follow the normal distribution, which fits the normal phenomenon like heights, blood pressure, IQ levels.
  • It makes it easy for statisticians to work with data when it is normally distributed.
  • It can also be used to control the quality. The bell curve is also known as the Gaussian distribution.

Recommended Articles

This is a guide to R Normal Distribution. Here we discuss the functions and advantages of R normal distribution with plotting the graph. You can also go through our other related articles to learn more –

  1. Random Number Generator in Matlab
  2. R Data Types
  3. R Data Frame
  4. Data Frames in R
All in One Excel VBA Bundle
500+ Hours of HD Videos
15 Learning Paths
120+ Courses
Verifiable Certificate of Completion
Lifetime Access
Financial Analyst Masters Training Program
1000+ Hours of HD Videos
43 Learning Paths
250+ Courses
Verifiable Certificate of Completion
Lifetime Access
All in One Data Science Bundle
1500+ Hour of HD Videos
80 Learning Paths
360+ Courses
Verifiable Certificate of Completion
Lifetime Access
All in One Software Development Bundle
3000+ Hours of HD Videos
149 Learning Paths
600+ Courses
Verifiable Certificate of Completion
Lifetime Access
Primary Sidebar
All in One Data Science Bundle1500+ Hour of HD Videos | 80 Learning Paths | 360+ Courses | Verifiable Certificate of Completion | Lifetime Access
Financial Analyst Masters Training Program1000+ Hours of HD Videos | 43 Learning Paths | 250+ Courses | Verifiable Certificate of Completion | Lifetime Access
Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Live Classes
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Database Management
  • Machine Learning
  • All Tutorials
Certification Courses
  • All Courses
  • Data Science Course - All in One Bundle
  • Machine Learning Course
  • Hadoop Certification Training
  • Cloud Computing Training Course
  • R Programming Course
  • AWS Training Course
  • SAS Training Course

ISO 10004:2018 & ISO 9001:2015 Certified

© 2023 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

EDUCBA
Free Data Science Course

Hadoop, Data Science, Statistics & others

By continuing above step, you agree to our Terms of Use and Privacy Policy.
*Please provide your correct email id. Login details for this Free course will be emailed to you
Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA Login

Forgot Password?

By signing up, you agree to our Terms of Use and Privacy Policy.

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more