R Normal Distribution - r - learn r - r programming
- In a random collection of data from independent sources, it is generally observed that the distribution of data is normal.
- Which means, on plotting a graph with the value of the variable in the horizontal axis and the count of the values in the vertical axis we get a bell shape curve.
- The center of the curve represents the mean of the data set.
- In the graph, fifty percent of values lie to the left of the mean and the other fifty percent lie to the right of the graph.
- This is referred as normal distribution in statistics.
- R has four in built functions to generate normal distribution.
r programming normal distribution
- Following is the description of the parameters used in above functions −
- x is a vector of numbers.
- p is a vector of probabilities.
- n is number of observations (sample size).
- mean is the mean value of the sample data. It's default value is zero.
- sd is the standard deviation. It's default value is 1.
dnorm()
- This function gives height of the probability distribution at each point for a given mean and standard deviation.
- When we execute the above code, it produces the following result −
pnorm()
- This function gives the probability of a normally distributed random number to be less that the value of a given number.
- It is also called "Cumulative Distribution Function".
- When we execute the above code, it produces the following result −
qnorm()
- This function takes the probability value and gives a number whose cumulative value matches the probability value.
- When we execute the above code, it produces the following result −
rnorm()
- This function is used to generate random numbers whose distribution is normal. It takes the sample size as input and generates that many random numbers. We draw a histogram to show the distribution of the generated numbers.