So far, we have showed you how to simulate data from well-defined distributions. However, you may also wish to simulate data from an unknown distribution. The first method we will show you to simulate random variables is through **rejection sampling**. This method is based on the idea that if you want to sample a random variable from a target distribution, you just have to sample the region under the curve of its density function. For example, let's consider a triangle distribution defined by the following density function:

First, let's plot the function in R by creating a `triangle()`

function, as follows:

> triangle <- function(x) {(abs(x) ...

Start Free Trial

No credit card required