Weibull Distribution in R (4 Examples) | dweibull, pweibull, qweibull & rweibull Functions


In this tutorial you’ll learn how to apply the weibull functions in R.

Table of contents:

Let’s get started:


Example 1: Weibull Density in R (dweibull Function)

In Example 1, we will create a plot representing the weibull density.

First, we need to create some x-values, for which we want to return the corresponding values of the weibull density:

x_dweibull <- seq(- 5, 30, by = 1)                    # Specify x-values for dweibull function

Now, we can apply the dweibull function of the R programming language to return the corresponding value of the weibull density with a shape of 0.1 and a scale of 1 for each of our input values:

y_dweibull <- dweibull(x_dweibull, shape = 0.1)       # Apply dweibull function

We can create a graphic showing these values with the plot function:

plot(y_dweibull)                                      # Plot dweibull values


weibull density in r

Figure 1: Weibull Density in R Plot.


Figure 1 illustrates the weibull density for a range of input values between -5 and 30 for a shape of 0.1 and a scale of 1.


Example 2: Weibull Distribution Function (pweibull Function)

In the second example, we’ll create the cumulative distribution function (CDF) of the weibull distribution.

Again, we need to specify a vector of input values:

x_pweibull <- seq(- 5, 30, by = 1)                    # Specify x-values for pweibull function

Now, we can apply the pweibull R command in order to return the corresponding CDF value for each input value…

y_pweibull <- pweibull(x_pweibull, shape = 0.1)       # Apply pweibull function

…and then we can draw a plot containing these values in R:

plot(y_pweibull)                                      # Plot pweibull values


weibull cdf in r

Figure 2: Cumulative Distribution Function According to Weibull Distribution.


Example 3: Weibull Quantile Function (qweibull Function)

Next, we will create a plot representing the weibull quantile function.

Let’s create a sequence of values between 0 and 1, for which we want to return the corresponding value of the quantile function:

x_qweibull <- seq(0, 1, by = 0.02)                    # Specify x-values for qweibull function

Now, we can use the qweibull R function to return the values of the quantile function:

y_qweibull <- qweibull(x_qweibull, shape = 0.1)       # Apply qweibull function

The following R code produces the corresponding scatterplot:

plot(y_qweibull)                                      # Plot qweibull values


weibull quantile function in r

Figure 3: Weibull Quantile Function.


Example 4: Random Number Generation (rweibull Function)

We can also draw random values according to the weibull density.

First, we need to specify a seed and a sample size of random numbers:

set.seed(13579)                                       # Set seed for reproducibility
N <- 100                                              # Specify sample size

Now, we can use the rweibull command to draw a set of random numbers:

y_rweibull <- rweibull(N, shape = 0.1)                # Draw N weibull distributed values
y_rweibull                                            # Print values to RStudio console
# 2.924615e+03 1.248956e-09 3.362811e+03 1.392134e-10 4.235278e-01 3.332413e+00 2.545625e+04

The RStudio console output is showing the result of the previous R syntax.

We can also produce a density plot of these numbers:

plot(density(y_rweibull),                             # Plot of randomly drawn weibull density
     main = "Weibull Distribution in R")


random numbers weibull function rweibull

Figure 4: Random Weibull Numbers.



Video, Further Resources & Summary

Do you need more information on the R code of this tutorial? Then you may want to have a look at the following video of my YouTube channel. I’m explaining the R programming codes of this tutorial in the video:


The YouTube video will be added soon.


You could also read the other pages on distributions and the generation of random numbers in R:


Additionally, you may have a look at some of the related articles of this homepage.


In this post you learned some basics of the weibull distribution in R. Don’t hesitate to let me know in the comments section, in case you have additional questions.


Subscribe to the Statistics Globe Newsletter

Get regular updates on the latest tutorials, offers & news at Statistics Globe.
I hate spam & you may opt out anytime: Privacy Policy.

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.