rsim: Simulate n independent trials from a random variable X:

Description Usage Arguments Examples

View source: R/discreteRV-Simulations.r

Description

Simulate n independent trials from a random variable X:

Usage

1
rsim(X, n)

Arguments

X

A random variable

n

The number of independent trials to simulate

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
X.Bern <- RV(c(1,0), c(.5,.5))
X.Bern.sim100 <- rsim(X.Bern, 100)

X.loaded.die <- RV(1:6, odds = c(1,1,1,1,2,4))
X.loaded.die.sim100 <- rsim(X.loaded.die, 100)

# The function 'rsim()' attaches the probabilities as names to the random draws.
# To get the values only, use 'as.vector()':
as.vector(X.Bern.sim100)
as.vector(X.loaded.die.sim100)

Example output

Attaching package: 'discreteRV'

The following object is masked from 'package:base':

    %in%

  [1] 1 1 0 1 1 1 1 0 0 1 1 1 1 0 0 1 0 0 0 0 1 0 0 0 1 0 0 1 0 0 0 1 0 1 1 0 0
 [38] 1 1 1 1 0 0 1 0 0 1 0 0 0 1 0 1 1 1 1 1 0 1 0 1 1 0 0 0 0 1 1 1 1 0 0 1 1
 [75] 1 1 0 0 0 0 1 0 0 1 1 0 0 1 0 1 0 1 1 1 0 0 0 1 1 1
  [1] 6 3 3 6 1 6 1 2 2 6 2 2 1 4 6 1 2 5 3 6 1 6 6 6 5 2 5 6 5 5 5 6 6 5 2 3 5
 [38] 2 6 6 3 3 3 6 3 2 1 1 4 6 5 4 6 6 1 4 6 1 3 4 2 5 3 6 4 4 3 6 4 6 6 5 2 4
 [75] 5 3 1 6 6 6 3 3 4 6 6 6 5 5 5 6 5 6 5 6 3 1 3 3 5 2

discreteRV documentation built on May 30, 2017, 2:21 a.m.