Skip to content

Commit 469f88f

Browse files
committed
Update vignette
1 parent ea39643 commit 469f88f

26 files changed

+109
-13
lines changed

docs/apple-touch-icon-120x120.png

0 Bytes
Loading

docs/apple-touch-icon-152x152.png

0 Bytes
Loading

docs/apple-touch-icon-180x180.png

0 Bytes
Loading

docs/apple-touch-icon-60x60.png

0 Bytes
Loading

docs/apple-touch-icon-76x76.png

0 Bytes
Loading

docs/apple-touch-icon.png

0 Bytes
Loading

docs/articles/accept_reject.html

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/articles/inspect.html

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/articles/it_works_for_any_univariate_distribution.html

+58-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/articles/yes.gif

5.76 MB
Loading

docs/favicon-16x16.png

0 Bytes
Loading

docs/favicon-32x32.png

0 Bytes
Loading

docs/pkgdown.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ articles:
66
inspect: inspect.html
77
it_works_for_any_univariate_distribution: it_works_for_any_univariate_distribution.html
88
qqplot: qqplot.html
9-
last_built: 2024-05-22T13:50Z
9+
last_built: 2024-05-22T15:56Z
1010

docs/search.json

+1-1
Large diffs are not rendered by default.
0 Bytes
Loading
0 Bytes
Loading
0 Bytes
Loading
0 Bytes
Loading
0 Bytes
Loading

pkgdown/favicon/apple-touch-icon.png

0 Bytes
Loading

pkgdown/favicon/favicon-16x16.png

0 Bytes
Loading

pkgdown/favicon/favicon-32x32.png

0 Bytes
Loading

vignettes/it_works_for_any_univariate_distribution.Rmd

+46-2
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,12 @@ options(tibble.print_min = 6, tibble.print_max = 6)
2020
modern_r <- getRversion() >= "4.1.0"
2121
```
2222

23-
2423
# It works for any univariate distribution
2524

2625
Although most examples presented on this site and in the function documentation involve densities implemented in R, the `accept_reject()` function is capable of generating samples from any univariate distribution, whether it is in R or not, or even one that has not yet been invented. In other words, as long as you have a density, just write the density and pass it to the `accept_reject()` function.
2726

27+
## Modified Beta Weibull distribution
28+
2829
The [**AcceptReject**](https://CRAN.R-project.org/package=AcceptReject) package is designed to be generic and timeless. Consider, for example, the family of Modified beta distributions, proposed in the paper [Modified beta distributions](https://link.springer.com/article/10.1007/s13571-013-0077-0). This is a family of probability distributions, as it is possible to generate various probability density functions through the proposed density generator, whose general density function is defined by:
2930

3031
$$f_X(x) = \frac{\beta^a}{B(a,b)} \times \frac{g(x)G(x)^{a - 1}(1 - G(x))^{b - 1}}{[1 - (1 - \beta)G(x)]^{a + b}},$$ with $x \geq 0$ and $\beta, a, b > 0$, where $g(x)$ is a probability density function, $G(x)$ is the cumulative distribution function of $g(x)$, and $B(a,b)$ is the beta function.
@@ -88,7 +89,7 @@ integrate(
8889

8990
Notice that the `pdf_mbw()` integrates to 1, being a probability density function. Thus, the `generator()` function generates probability density functions from another distribution $G_X(x)$. In the case of the code above, the Weibull cumulative distribution function was assigned to the `generator()` function, which could be any other. Note also that I am deriving numerically so that the user does not need to implement the probability density, which involves a somewhat larger expression.
9091

91-
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?
92+
**Note**: 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? 🤔
9293

9394
<br>
9495

@@ -129,3 +130,46 @@ Did you notice how easy it is to use the [**AcceptReject**](https://CRAN.R-proje
129130
<br>
130131

131132
![](wow.gif)
133+
134+
## Modified Beta Gamma distribution
135+
136+
In a very simple way, we can generate data for any random variable $X \sim MBG$. Here, we will generate data for a sequence of i.i.d random variables where the base distribution is the gamma distribution. So,
137+
138+
```{r}
139+
# Probability density function - Modified Beta Gamma
140+
pdf_mbg <- function(x, a, b, beta, shape, scale)
141+
generator(
142+
x = x,
143+
G = pgamma,
144+
a = a,
145+
b = b,
146+
beta = beta,
147+
shape = shape,
148+
scale = scale
149+
)
150+
151+
# True parameters
152+
a <- 1.5
153+
b <- 3.1
154+
beta <- 1.9
155+
shape <- 3.5
156+
scale <- 2.7
157+
158+
set.seed(0)
159+
x <-
160+
accept_reject(
161+
n = 1000L,
162+
f = pdf_mbw,
163+
args_f = list(a = a, b = b, beta = beta, shape = shape, scale = scale),
164+
xlim = c(0, 3.5)
165+
)
166+
167+
# Plots
168+
plot(x)
169+
qqplot(x)
170+
171+
```
172+
173+
<br>
174+
175+
![Did you like it?](yes.gif){width="343"}

vignettes/yes.gif

5.76 MB
Loading

0 commit comments

Comments
 (0)