Skip to content

Commit

Permalink
Version 0.1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
prdm0 committed Apr 26, 2024
1 parent af564a6 commit b394087
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 18 deletions.
14 changes: 7 additions & 7 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ plot_grid(a, b, c, d, nrow = 2L, labels = c("a", "b", "c", "d"))

## Generating continuous observations

To expand beyond examples of generating pseudo-random observations of discrete random variables, consider now that we want to generate observations from a random variable $X \sim \mathcal{N}(\mu = 0, \sigma^2 = 1)$. We chose the normal distribution because we are familiar with its form, but you can choose another distribution if desired. Below, we will generate `n = 2000` observations using the acceptance-rejection method. Note that `continuous = TRUE`.
To expand beyond examples of generating pseudo-random observations of discrete random variables, consider now that we want to generate observations from a random variable $X \sim \mathcal{N}(\mu = 0, \sigma^2 = 1)$. We chose the normal distribution because we are familiar with its form, but you can choose another distribution if desired.

```{r}
library(AcceptReject)
Expand All @@ -105,10 +105,10 @@ simulation <- function(n){
)
}
# Inspecting
a <- plot(simulation(n = 250L))
b <- plot(simulation(n = 2500L))
c <- plot(simulation(n = 25000L))
d <- plot(simulation(n = 250000L))
a <- plot(simulation(n = 100L))
b <- plot(simulation(n = 150L))
c <- plot(simulation(n = 250L))
d <- plot(simulation(n = 2500L))
plot_grid(a, b, c, d, nrow = 2L, labels = c("a", "b", "c", "d"))
Expand Down Expand Up @@ -177,7 +177,7 @@ set.seed(0)
tic()
case_1 <- accept_reject(
n = 200e3L,
n = 2000,
continuous = TRUE,
f = dweibull,
args_f = list(shape = 2.1, scale = 2.2),
Expand All @@ -188,7 +188,7 @@ toc()
# Specifying the base probability density function
tic()
case_2 <- accept_reject(
n = 200e3L,
n = 2000,
continuous = TRUE,
f = dweibull,
args_f = list(shape = 2.1, scale = 2.2),
Expand Down
20 changes: 9 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,7 @@ discrete random variables, consider now that we want to generate
observations from a random variable
$X \sim \mathcal{N}(\mu = 0, \sigma^2 = 1)$. We chose the normal
distribution because we are familiar with its form, but you can choose
another distribution if desired. Below, we will generate `n = 2000`
observations using the acceptance-rejection method. Note that
`continuous = TRUE`.
another distribution if desired.

``` r
library(AcceptReject)
Expand All @@ -169,10 +167,10 @@ simulation <- function(n){
)
}
# Inspecting
a <- plot(simulation(n = 250L))
b <- plot(simulation(n = 2500L))
c <- plot(simulation(n = 25000L))
d <- plot(simulation(n = 250000L))
a <- plot(simulation(n = 100L))
b <- plot(simulation(n = 150L))
c <- plot(simulation(n = 250L))
d <- plot(simulation(n = 2500L))

plot_grid(a, b, c, d, nrow = 2L, labels = c("a", "b", "c", "d"))
```
Expand Down Expand Up @@ -277,19 +275,19 @@ set.seed(0)

tic()
case_1 <- accept_reject(
n = 200e3L,
n = 2000,
continuous = TRUE,
f = dweibull,
args_f = list(shape = 2.1, scale = 2.2),
xlim = c(0, 10)
)
toc()
#> 0.371 sec elapsed
#> 0.009 sec elapsed

# Specifying the base probability density function
tic()
case_2 <- accept_reject(
n = 200e3L,
n = 2000,
continuous = TRUE,
f = dweibull,
args_f = list(shape = 2.1, scale = 2.2),
Expand All @@ -300,7 +298,7 @@ case_2 <- accept_reject(
c = 1.2
)
toc()
#> 0.145 sec elapsed
#> 0.006 sec elapsed

# Visualizing the results
p1 <- plot(case_1)
Expand Down
Binary file modified man/figures/README-unnamed-chunk-2-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified man/figures/README-unnamed-chunk-3-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified man/figures/README-unnamed-chunk-5-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit b394087

Please sign in to comment.