The PDF is the acronym for Probability Distribution Function and CDF is the acronym for Cumulative Distribution Function. In general, there are many probability distribution functions in R programming Language.
1. PDF
The Probability Density Function (PDF) represents how probability is distributed for a continuous random variable.
Syntax:
dnorm(x, mean, sd)
Parameter:
x: A numeric vector of values for which the density is to be computed.
mean: Mean of the distribution; can be calculated from data or manually assigned.
sd: Standard deviation of the distribution; can be calculated from data or manually assigned.
2. CDF
The Cumulative Distribution Function (CDF) gives the probability that a variable takes a value less than or equal to a given number.
Syntax:
ecdf(x)
Parameter:
x: A numeric vector of values for which the density is to be computed.
1. Plotting PDF Using plot Function
We generate a normal distribution using dnorm and then plot it using the base R plot function.
seq : Generates a sequence of numbers
dnorm : Computes the density values of the normal distribution
mean : Calculates the average of a numeric vector
sd : Calculates the standard deviation of a numeric vector
plot : Creates a line plot based on the provided x and y values