Description Usage Arguments Value Examples

View source: R/discreteRV-Probabilities.r

Make a random variable consisting of possible outcome values and their probabilities or odds

1 2 3 |

`outcomes` |
Vector of possible outcomes |

`probs` |
Vector of probabilities or function defining probabilities |

`odds` |
Vector of odds |

`fractions` |
If TRUE, return the probabilities as fractions when printing |

`range` |
If TRUE, outcomes specify a range of values in the form c(lower, upper) |

`verifyprobs` |
If TRUE, verify that the probs sum to one |

`id` |
Set the id of the random variable |

`...` |
Additional parameters passed to the function defining outcome probabilities |

random variable as RV object.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | ```
# Make a 50:50 Bernoulli random variable:
X.Bern <- RV(c(1,0), c(.5,.5))
# An equivalent method
X.Bern <- RV("bernoulli")
# Make a fair coin flip game with payoffs +$1 and -$1:
X.fair.coin <- RV(c(1,-1), c(.5,.5))
# Make a biased coin flip game with odds 1:2 and with fair payoffs +$2 and -$1
X.biased.coin <- RV(c(2,-1), odds = c(1,2))
# Make a fair die
X.fair.die <- RV(1:6, 1/6)
# Make a loaded die, specifying odds 1:1:1:1:2:4 rather than probabilities:
X.loaded.die <- RV(1:6, odds = c(1,1,1,1,2,4))
# Make a Poisson random variable
pois.func <- function(x, lambda) { lambda^x * exp(-lambda) / factorial(x) }
X.pois <- RV(c(0, Inf), pois.func, lambda = 5)
# An equivalent method
X.pois <- RV("poisson")
``` |

```
Attaching package: 'discreteRV'
The following object is masked from 'package:base':
%in%
```

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.