qexp(0.5, rate = 1)
## [1] 0.6931472
Appendix B covers a number of common probability distributions that are relevant for the purposes of this course. Appendix C furthermore provides additional theoretical background on the exponential family, an important class of probability distributions widely used in statistics.
R has built-in functions for most common probability distributions. Further distributions are covered in additional packages. If mydist
is the name of a probability distribution, then R routinely offers four functions for mydist
, distinguished by the first letter:
dmydist(x, ...)
the density function gives the probability (mass/density) \(f(x)\) for x
pmydist(x, ...)
the cumulative probability function gives the cumulative distribution function \(F(x)\) for x
qmydist(p, ...)
the quantile function gives the value x
for which p = pmydist(x, ...)
rmydist(n, ...)
the random sample function returns n
samples from the distributionFor example, the family of functions for the normal distribution has the following functions:
# density of standard normal at x = 1
dnorm(x = 1, mean = 0, sd = 1)
## [1] 0.2419707
# cumulative density of standard normal at q = 0
pnorm(q = 0, mean = 0, sd = 1)
## [1] 0.5
# point where the cumulative density of standard normal is p = 0.5
qnorm(p = 0.5, mean = 0, sd = 1)
## [1] 0
# n = 3 random samples from a standard normal
rnorm(n = 3, mean = 0, sd = 1)
## [1] 0.8625486 -2.6191819 -0.8560546
Exercise 7.6
qexp
in R.qexp(0.5, rate = 1)
## [1] 0.6931472
\[ \int_{-1}^{2} \mathcal{N}(x, \mu = 0, \sigma = 1) \text{d}x \]
pnorm(2, mean = 0, sd = 1) - pnorm(-1, mean = 0, sd = 1)
## [1] 0.8185946