Skip to content

Commit

Permalink
Update vignette
Browse files Browse the repository at this point in the history
  • Loading branch information
prdm0 committed May 22, 2024
1 parent 21a06f4 commit 7ae26cc
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions vignettes/it_works_for_any_univariate_distribution.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,12 @@ $$f_X(x) = \frac{\beta^a}{B(a,b)} \times \frac{g(x)G(x)^{a - 1}(1 - G(x))^{b - 1

The authors present a quantile function in closed form that depends on the quantile of the base distribution, that is, $G^{-1}(u) = x$ is known. But here, this is not the case. We will use the `accept_reject()` function to generate samples from the Modified Beta - $G$ distribution, which is a distribution that is not natively in R and could eventually be implemented by the package user.

<br>

![Got the idea?](ok.gif)

<br>

The following code implements the density (derived in $x$ from the Modified Beta - $G$), for any $G$. It is important to note that the user could implement it in another way. What matters is that the user has a function that implements the probability density function.

The user could, if desired, implement it directly for a specific $G$, for example, Weibull. Here, it will be implemented for any $G$.
Expand Down Expand Up @@ -86,13 +90,16 @@ Notice that the `pdf_mbw()` integrates to 1, being a probability density functio

You need to understand that all the code above is a programming strategy, but if you don't understand it very well, that's okay, you just need to implement the probability density function that needs to generate the observations, in the way you already know how to do. Ok?

<br>

![](attention.gif)

<br>

Now that we have the probability density function with the Modified Beta Weibull density function - `pdf_mbw()`, let's use the `accept_reject()` function to generate observations of a sequence of independent and identically distributed (i.i.d.) random variables with the Modified Beta Weibull distribution.

```{r, echo = TRUE, eval = TRUE}
library(AcceptReject)
library(cowplot)
# True parameters
a <- 10.5
Expand All @@ -111,12 +118,14 @@ x <-
)
# Plots
p1 <- plot(x)
p2 <- qqplot(x)
plot_grid(p1, p2, nrow = 1L, labels = "AUTO")
plot(x)
qqplot(x)
```

Did you notice how easy it is to use the [**AcceptReject**](https://CRAN.R-project.org/package=AcceptReject) package? Just implement the probability density function and pass it to the `accept_reject()` function. It doesn't matter how you implemented it; what matters is that you have the function to pass to the f argument of `accept_reject()`.
<br>

Did you notice how easy it is to use the [**AcceptReject**](https://CRAN.R-project.org/package=AcceptReject) package? Just implement the probability density function and pass it to the `accept_reject()` function. It doesn't matter how you implemented it; what matters is that you have the function to pass to the `f` argument of `accept_reject()`.

<br>

![](wow.gif)

0 comments on commit 7ae26cc

Please sign in to comment.