The probability density function (density()), cumulative distribution
function (cdf()), and quantile function / inverse CDF (quantile()) of
an rvar.
# S3 method for rvar
density(x, at, ...)
# S3 method for rvar_factor
density(x, at, ...)
# S3 method for rvar
cdf(x, q, ...)
# S3 method for rvar_factor
cdf(x, q, ...)
# S3 method for rvar_ordered
cdf(x, q, ...)
# S3 method for rvar
quantile(x, probs, ...)
# S3 method for rvar_factor
quantile(x, probs, ...)
# S3 method for rvar_ordered
quantile(x, probs, ...)(rvar) An rvar object.
Additional arguments passed onto underlying methods:
For density(), these are passed to stats::density().
For cdf(), these are ignored.
For quantile(), these are passed to stats::quantile().
(numeric vector) One or more quantiles.
(numeric vector) One or more probabilities in [0,1].
If x is a scalar rvar, returns a vector of the same length as the input
(q, at, or probs) containing values from the corresponding function
of the given rvar.
If x has length greater than 1, returns an array with dimensions
c(length(y), dim(x)) where y is q, at, or probs, where each
result[i,...] is the value of the corresponding function,f(y[i]), for
the corresponding cell in the input array, x[...].
set.seed(1234)
x = rvar(rnorm(100))
density(x, seq(-2, 2, length.out = 10))
#> [1] 0.05268921 0.15669674 0.33325128 0.42911534 0.38825093 0.27760481
#> [7] 0.20794004 0.14720607 0.10387881 0.07011558
cdf(x, seq(-2, 2, length.out = 10))
#> [1] 0.02 0.04 0.15 0.34 0.54 0.68 0.81 0.89 0.92 0.96
quantile(x, ppoints(10))
#> [1] -1.371156446 -1.107797288 -0.877775358 -0.574614497 -0.476119783
#> [6] -0.187048613 -0.007696628 0.448815321 0.902987295 1.646284259
x2 = c(rvar(rnorm(100, mean = -0.5)), rvar(rnorm(100, mean = 0.5)))
density(x2, seq(-2, 2, length.out = 10))
#> [,1] [,2]
#> [1,] 0.08849633 0.001641837
#> [2,] 0.20332937 0.024310255
#> [3,] 0.33447478 0.081654865
#> [4,] 0.41944017 0.167732070
#> [5,] 0.40333595 0.241892638
#> [6,] 0.28289139 0.309987338
#> [7,] 0.15847776 0.462678904
#> [8,] 0.12750072 0.466875791
#> [9,] 0.07751964 0.234727355
#> [10,] 0.02149798 0.109987934
cdf(x2, seq(-2, 2, length.out = 10))
#> [,1] [,2]
#> [1,] 0.07 0.01
#> [2,] 0.11 0.01
#> [3,] 0.25 0.03
#> [4,] 0.43 0.08
#> [5,] 0.63 0.16
#> [6,] 0.79 0.31
#> [7,] 0.86 0.43
#> [8,] 0.91 0.69
#> [9,] 0.97 0.87
#> [10,] 0.99 0.93
quantile(x2, ppoints(10))
#> [,1] [,2]
#> [1,] -2.0034466 -0.6872996
#> [2,] -1.3541896 -0.2346473
#> [3,] -1.0276966 0.1308444
#> [4,] -0.8207823 0.3500387
#> [5,] -0.5789329 0.6861700
#> [6,] -0.3647747 0.8192384
#> [7,] -0.1451222 0.9367486
#> [8,] 0.1230689 1.1749908
#> [9,] 0.4371228 1.4569163
#> [10,] 1.1776442 2.1500961