RV: @title Defines a random variable.

Description Usage Arguments Value Examples

View source: R/random_variables.R

Description

A random variable is a function which maps an outcome of a probability space to a number. Simulating a random variable is a two-step process: first, a draw is taken from the underlying probability space; then, the function is applied to that draw to obtain the realized value of the random variable.

Usage

1
RV(probSpace, fun = function(x) x)

Arguments

probSpace

(ProbabilitySpace): the underlying probability space of the random variable.

fun

(function, optional): a function that maps draws from the probability space to numbers.

Value

A RV

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
# a single draw is a sequence of 0s and 1s, e.g., (0, 0, 1, 0, 1).
P = BoxModel(c(0, 1), size=5)
# X counts the number of 1s in the draw, e.g., 5
X = RV(P, sum)

# the function is the identity, so Y has a Normal(0, 1) distribution
Y = RV(Normal(0, 1)

# a single draw from BivariateNormal is a tuple of two numbers
P = BivariateNormal()
# Z is the smaller of the two numbers
Z = RV(P, min)

hayate0304/Rsymbulate documentation built on May 17, 2019, 8:20 a.m.