knitr::opts_chunk$set(collapse = T, comment = "#>") library(cointoss)
The package "cointoss"
is a minimal implementation for simulating tossing
a coin a given number of times, and to visualize the relative frequencies
in such a series of tosses.
coin
The first step is to create a "coin"
object with the function coin()
:
mycoin <- coin() mycoin
By default, coin()
creates a fair coin with standard sides heads
, and
tails
, and with probability values for each side of 0.5.
You can change the defatuls with arguments sides
and prob
:
loaded <- coin(sides = c('HEADS', 'tails'), prob = c(0.8, 0.2)) loaded
Once you have defined a "coin"
object, you can use the function toss()
to
toss a coin a given number of times
. The output will be an object of class
"toss"
, which will contain the vector of tosses
:
toss100 <- toss(mycoin, times = 100) toss100
The summary()
function gives you a nice table of frequencies:
summary(toss100)
You can use the function plot()
to create a graphic with the relative
frequencies of a series of coin tosses:
plot(toss100)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.