You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
27
26
27
+
## Modified Beta Weibull distribution
28
+
28
29
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:
29
30
30
31
$$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(
88
89
89
90
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.
90
91
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? 🤔
92
93
93
94
<br>
94
95
@@ -129,3 +130,46 @@ Did you notice how easy it is to use the [**AcceptReject**](https://CRAN.R-proje
129
130
<br>
130
131
131
132

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),
0 commit comments