rvbeta
generates a random vector from the beta sampling model;
rvbeta(n = 1, shape1, shape2)
integer, number of random variables to generate
positive number or rv, 1st shape parameter
positive number or rv, 2nd shape parameter
rvnbeta(n, a, b)
("neutral" Beta distribution) is equivalent to
rvbeta(n, 1/3+a, 1/3+b)
.
Kerman, J. and Gelman, A. (2007). Manipulating and Summarizing Posterior Simulations Using Random Variable Objects. Statistics and Computing 17:3, 235-244.
See also vignette("rv")
.
n <- 12 # sample size
y <- (0:(n-1)) # observations
a <- b <- 1/3 # the neutral beta prior
rvbeta(1, shape1=a+y, shape2=b+n-y)
#> mean sd 1% 2.5% 25% 50% 75% 97.5% 99% sims
#> [1] 0.026 0.044 4.6e-08 1.7e-07 0.00089 0.0078 0.031 0.14 0.20 200
#> [2] 0.109 0.089 1.6e-03 5.4e-03 0.04036 0.0871 0.153 0.32 0.37 200
#> [3] 0.174 0.098 1.3e-02 2.7e-02 0.10311 0.1609 0.238 0.41 0.46 200
#> [4] 0.265 0.112 6.8e-02 8.1e-02 0.18209 0.2495 0.346 0.51 0.53 200
#> [5] 0.348 0.138 1.1e-01 1.2e-01 0.24703 0.3449 0.437 0.64 0.66 200
#> [6] 0.450 0.146 1.3e-01 1.6e-01 0.34363 0.4524 0.565 0.71 0.75 200
#> [7] 0.499 0.144 2.1e-01 2.3e-01 0.39287 0.5069 0.605 0.74 0.81 200
#> [8] 0.573 0.131 2.8e-01 3.0e-01 0.49150 0.5712 0.663 0.81 0.83 200
#> [9] 0.665 0.131 3.8e-01 3.9e-01 0.56898 0.6758 0.761 0.89 0.91 200
#> [10] 0.742 0.121 4.6e-01 4.8e-01 0.65342 0.7565 0.843 0.92 0.95 200
#> [11] 0.820 0.103 5.7e-01 5.9e-01 0.75447 0.8467 0.896 0.96 0.98 200
#> [12] 0.892 0.083 6.6e-01 7.0e-01 0.84922 0.9111 0.953 0.99 1.00 200
rvnbeta(1, shape1=y, shape2=n-y)
#> mean sd 1% 2.5% 25% 50% 75% 97.5% 99% sims
#> [1] 0.025 0.042 3.9e-07 6.3e-07 0.00087 0.0069 0.026 0.16 0.19 200
#> [2] 0.111 0.082 4.8e-03 6.6e-03 0.04721 0.0955 0.153 0.31 0.37 200
#> [3] 0.178 0.103 3.6e-02 4.5e-02 0.09907 0.1541 0.241 0.41 0.44 200
#> [4] 0.245 0.114 4.5e-02 5.8e-02 0.15306 0.2402 0.315 0.48 0.52 200
#> [5] 0.338 0.123 9.0e-02 1.3e-01 0.24947 0.3384 0.413 0.59 0.64 200
#> [6] 0.430 0.126 1.8e-01 2.0e-01 0.34091 0.4325 0.512 0.67 0.70 200
#> [7] 0.503 0.131 2.1e-01 2.8e-01 0.40981 0.4936 0.591 0.77 0.78 200
#> [8] 0.584 0.130 2.8e-01 3.3e-01 0.49441 0.5942 0.672 0.82 0.84 200
#> [9] 0.653 0.134 3.5e-01 3.8e-01 0.56318 0.6698 0.753 0.88 0.90 200
#> [10] 0.729 0.126 4.1e-01 4.4e-01 0.64277 0.7454 0.834 0.92 0.95 200
#> [11] 0.813 0.117 4.9e-01 5.2e-01 0.75030 0.8393 0.902 0.97 0.98 200
#> [12] 0.895 0.083 5.5e-01 7.0e-01 0.85852 0.9141 0.954 0.99 1.00 200