knitr::opts_chunk$set(prompt=FALSE, comment="")
You may skip this section on a first read through, and come back to it later when you need these.
R has a family of functions for each probability distribution. The distributions we'll likely use in this course are:
dbinom
, pbinom
, qbinom
, rbinom
.dnorm
, pnorm
, qnorm
, rnorm
.dexp
, pexp
, qexp
, rexp
.dpois
, ppois
, qpois
, rpois
.dchisq
, pchisq
, qchisq
, rchisq
.Note that each of these distributions has four R functions. For example, for
the Poisson distribution (which has one parameter, lambda
) these are:
dpois(x, lambda)
: the probability density.ppois(x, lambda)
: the probability distribution, e.g. the density
integrated (or summed) from -Infinity to x, giving the probability of values
less extreme than x
.qpois(p, lambda)
: the quantile function, which returns the quantile for a supplied probability p
.rpois(n, lambda)
: return n
random samples from a Poisson distribution.When sampling random variables, it's sometimes useful to set the random seed. Random numbers are sampled from a pseudo random number generator; the pseudo means these aren't truly random as setting the seed ensures the same sequence of random numbers can be generated. For example:
set.seed(3) rnorm(10) set.seed(3) rnorm(10) set.seed(4) # set seed for different sequence of numbers rnorm(10)
Note the same sequence is returned once we set the seed to the same seed.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.