Learn R Programming

posterior (version 1.6.0)

rvar-dist: Density, CDF, and quantile functions of random variables

Description

The probability density function (density()), cumulative distribution function (cdf()), and quantile function / inverse CDF (quantile()) of an rvar.

Usage

# 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, ...)

Value

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[...].

Arguments

x

(rvar) An rvar object.

...

Additional arguments passed onto underlying methods:

q, at

(numeric vector) One or more quantiles.

probs

(numeric vector) One or more probabilities in [0,1].

Examples

Run this code

set.seed(1234)
x = rvar(rnorm(100))

density(x, seq(-2, 2, length.out = 10))
cdf(x, seq(-2, 2, length.out = 10))
quantile(x, ppoints(10))

x2 = c(rvar(rnorm(100, mean = -0.5)), rvar(rnorm(100, mean = 0.5)))
density(x2, seq(-2, 2, length.out = 10))
cdf(x2, seq(-2, 2, length.out = 10))
quantile(x2, ppoints(10))

Run the code above in your browser using DataLab