B Using R with distributions
In R, standard distributions have four associated functions:
- Computing the probability function: All begin with
p
(such aspnorm()
for the normal distribution). - Computing the distribution function: All begin with
d
(such asdnorm()
). - Computing the quantile function: All begin with
q
(such asqnorm()
). - Generating random numbers: All begin with
r
(such asrnorm()
).
For example, the fours function above are called, for the normal distribution (denoted norm
in R):
B.1 Univariate distributions
Common parameters:
-
x
: Values where to evaluate the probability function -
q
: Quantiles -
p
: Probabilities -
n
: The number of random observations to generate
Most distributions have other parameters also; check the help (e.g., ?punif
).
Distribution | Probability function | Distribution function | Quantile function | Random numbers |
---|---|---|---|---|
Discrete uniform | sample() |
|||
Binomial | dbinom() |
pbinom() |
qbinom() |
rbinom(n, ) |
Poisson | dpois() |
ppois() |
qpois() |
rpois(n, ) |
Geometric | dgeom() |
pgeom() |
qgeom() |
rgeom(n, ) |
Negative binomial | dnbinom() |
pnbinom() |
qnbinom() |
rnbinom(n, ) |
Continuous uniform | dunif() |
punif() |
qunif() |
runif(n, ) |
Normal | dunif() |
punif() |
qunif() |
runif(n, ) |
Gamma | dgamma() |
pgammma() |
qgamma() |
rgamma(n, ) |
\(t\) | dt() |
pt() |
qt() |
rt(n, ) |
\(\chi\)-squared | dchisq() |
pchisq() |
qchisq() |
rchisq(n, ) |
\(F\) | df() |
pf() |
qf() |
rf(n, ) |