EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 360+ Courses All in One Bundle
  • Login

R Normal Distribution

By Priya PedamkarPriya Pedamkar

Home » Data Science » Data Science Tutorials » R Programming Tutorial » R Normal Distribution

R Normal Distribution

Introduction to R Normal Distribution

In these articles, we will learn about 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.

Popular Course in this category
R Programming Training (12 Courses, 20+ Projects)12 Online Courses | 20 Hands-on Projects | 116+ Hours | Verifiable Certificate of Completion | Lifetime Access
4.5 (5,953 ratings)
Course Price

View Course

Related Courses
Statistical Analysis Training (10 Courses, 5+ Projects)All in One Data Science Bundle (360+ Courses, 50+ projects)
  • dnorm
  • pnorm
  • qnorm
  • rnorm

Parameters

  • x is a vector of numbers.
  • p is 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 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

Below is the advantage of R Normal Distribution:

  • 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

R Programming Training (12 Courses, 20+ Projects)

12 Online Courses

20 Hands-on Projects

116+ Hours

Verifiable Certificate of Completion

Lifetime Access

Learn More

1 Shares
Share
Tweet
Share
Primary Sidebar
R programming Tutorial
  • Advanced
    • Statistical Analysis with R
    • R String Functions
    • Data Exploration in R
    • R CSV Files
    • KNN Algorithm in R
    • Sorting in R
    • lm Function in R
    • Hierarchical Clustering in R
    • R Normal Distribution
    • Binomial Distribution in R
    • Decision Tree in R
    • GLM in R
    • Linear Model in R
    • Predict Function in R
    • Survival Analysis in R
    • Standard Deviation in R
    • Statistical Analysis in R
    • T-test in R
    • Database in R
  • Basic
    • What is R Programming Language
    • Careers in R Programming
    • Install R
    • List of R Packages
    • Introduction of R Tools Technology
    • R Programming Language
    • What is RStudio?
    • R-studio-Functions
    • R Packages
    • R Data Types
    • R Operators
    • Vectors in R
  • Control statement
    • If Statement in R
    • If Else Statement in R
    • Else if in R
    • Switch Statement in R
  • Loops
    • Loops in R
    • For Loop in R
    • Nested For Loop in R
    • While Loop in R
    • Next in R
  • Chart/graphs
    • Graphs in R
    • Bar Charts in R
    • Pie Chart in R
    • Histogram in R
    • Line Graph in R
    • Plot Function in R
    • Scatterplot in R
    • R Boxplot labels
  • Regression in R
    • Simple Linear Regression in R
    • Linear Regression in R
    • Multiple Linear Regression in R
    • Logistic Regression in R
    • Poisson Regression in R
    • OLS Regression in R
    • P-Value in Regression
  • Anova in R
    • ANOVA in R
    • One Way ANOVA in R
    • Two Way ANOVA in R
  • Data Structure
    • R list
    • Arrays in R
    • Data Frames in R
    • Factors in R
  • Programs
    • R Program Functions
    • Factorial in R
    • Random Number Generator in R
  • Interview question
    • R Interview Questions

Related Courses

R Programming Certification Course

Statistical Analysis Course Training

All in One Data Science Courses

Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • 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

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

EDUCBA Login

Forgot Password?

EDUCBA
Free Data Science Course

Hadoop, Data Science, Statistics & others

*Please provide your correct email id. Login details for this Free course will be emailed to you
Book Your One Instructor : One Learner Free Class

Let’s Get Started

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

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

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

Special Offer - R Programming Training (12 Courses, 20+ Projects) Learn More