Description Usage Arguments Details Value Examples
This function implements one variables rejection sampling for rvs with bounded support and which have a bounded pdf.
1 | oneDSample1(f, N = 10000, lb = Inf, ub = Inf, continuous = TRUE)
|
f |
the pdf that we are sampling from |
N |
the number of attempted samples |
lb |
the lower bound of support |
ub |
the upper bound of support |
Here are more details about the algorithm that we are using
A vector containing samples from pdf
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | f<- function(x) {ifelse(-1< x & x < 0, 3*x^2, 0)}
w=oneDsample(f,50000,-1,0)
ggplot(w,aes(x)) + geom_density() + stat_function(fun = f, color = "red")
f<- function(x) {1/pi/(1+x^2)}
w=oneDSample1(f,50000)
ggplot(w,aes(x)) + geom_density() + stat_function(fun = f, color = "red")
f <- function(x) {dunif(x, -100, 100)}
a <- oneDSample1(f,500)
ggplot(a,aes(x)) + geom_density() + stat_function(fun = f, color = "red")
f<- function(x){dnorm(x,-5000,5000)}
w=oneDSample1(f,50000)
ggplot(w,aes(x)) + geom_density() + stat_function(fun = f, color = "red")
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.