Plot cumulative distribution function in base R
To plot a CDF function in base R, we first calculate the CDF by using the ecdf() function. Then we use the plot() function to plot the CDF plot in the R Language. The plot function takes the result of the ecdf() function as an argument to plot the CDF plot.
Syntax: plot( CDF )
Parameter:
- CDF: determines the cumulative distribution function calculated using the ecdf() function.
Cumulative distribution function in base R
Here, is an example of a basic Cumulative Distribution Function Plot in the R Language.
# create sample data
sample_Data = rnorm(500)
# calculate CDF
CDF <- ecdf(sample_Data )
# draw the cdf plot
plot( CDF )
Output:
Cumulative distribution function in base R using iris dataset
data(iris)
plot(ecdf(iris$Petal.Length))
Output:
Plot Cumulative Distribution Function in R
In this article, we will discuss how to plot a cumulative distribution function (CDF) in the R Programming Language.
The cumulative distribution function (CDF) of a random variable evaluated at x, is the probability that x will take a value less than or equal to x. To calculate the cumulative distribution function in the R Language, we use the ecdf() function. The ecdf() function in R Language is used to compute and plot the value of the Empirical Cumulative Distribution Function of a numeric vector. The ecdf() function takes the data vector as an argument and returns the CDF data.
Syntax: ecdf( data_vector )
Parameter:
- data_vector: determines the vector that contains data for CDF calculation.
Table of Content
- Plot cumulative distribution function in base R
- Plot CDF of Known Distribution
- Plot CDF of Known Distribution using ggplot2 Package