File: flip.coin.Rd

package info (click to toggle)
r-cran-animation 2.7%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 1,268 kB
  • sloc: javascript: 873; sh: 15; makefile: 2
file content (75 lines) | stat: -rw-r--r-- 2,317 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/flip.coin.R
\name{flip.coin}
\alias{flip.coin}
\title{Probability in flipping coins}
\usage{
flip.coin(
  faces = 2,
  prob = NULL,
  border = "white",
  grid = "white",
  col = 1:2,
  type = "p",
  pch = 21,
  bg = "transparent",
  digits = 3
)
}
\arguments{
\item{faces}{an integer or a character vector. See details below.}

\item{prob}{the probability vector of showing each face. If \code{NULL}, each
face will be shown in the same probability.}

\item{border}{The border style for the rectangles which stand for
probabilities.}

\item{grid}{the color for horizontal grid lines in these rectangles}

\item{col}{The colors to annotate different faces of the `coin'.}

\item{type, pch, bg}{See \code{\link{points}}.}

\item{digits}{integer indicating the precision to be used in the annotation
of frequencies in the plot}
}
\value{
A list containing \item{freq}{A vector of frequencies (simulated
  probabilities)} \item{nmax}{the total number of tosses}
}
\description{
This function provides a simulation to the process of flipping coins and
computes the frequencies for `heads' and `tails'.
}
\details{
If \code{faces} is a single integer, say 2, a sequence of integers from 1 to
\code{faces} will be used to denote the faces of a coin; otherwise this
character vector just gives the names of each face.

When the \eqn{i}-th face shows up, a colored thin rectangle will be added to
the corresponding place (the \eqn{i}-th bar), and there will be corresponding
annotations for the number of tosses and frequencies.

The special argument \code{grid} is for consideration of a too large number
of flipping, in which case if you still draw horizontal lines in these
rectangles, the rectangles will be completely covered by these lines, thus we
should specify it as \code{NA}.

At last the frequency for each face will be computed and shown in the header
of the plot -- this shall be close to \code{prob} if
\code{ani.options('nmax')} is large enough.
}
\note{
You may change the colors of each face using the argument \code{col}
  (repeated if shorter than the number of faces).
}
\references{
Examples at \url{https://yihui.org/animation/example/flip-coin/}
}
\seealso{
\code{\link{points}}, \code{\link{sample}}
}
\author{
Yihui Xie
}