Various Distribution Functions in R
Description
In R, functions related to specific distributions are made up of a combination of prefixes and suffixes.
Prefixes
Let the probability distribution function of distribution $X$ be called $f(x)$.
- r-: for random sampling, think of sampling $x_{1}, \cdots , x_{n}$ from distribution $X$.
- d-: for the density function, $f(x)$.
- p-: for the cumulative distribution function, $F(x) = \displaystyle \int_{\infty}^{x} f(t) dt$.
- q-: for the quantile function, $F^{-1}(\alpha)$.
Suffixes
Almost all known distributions are available, but particularly commonly used distributions include:
- -norm: normal distribution
- -t: t-distribution
- -f: F-distribution
- -chisq: chi-squared distribution
To learn about various distributions, you can type
?distribution
in the console.
The first argument of the random sampling function is always about how many to sample, and the adjustment of specific parameters varies by distribution. The density function returns just the function value for a given $x$, so using plot()
like below would draw the graph of the probability density function. The cumulative distribution function returns the integrated value up to a given $x$, so as you well know, it returned $0.975$ for $x=1.96$. The quantile function returns the quantile for a given $\alpha$, so as you well know, it returned $1.65$ for $\alpha = 95%$.
Code
Below is an example code.
set.seed(150421)
rnorm(4)
pnorm(1.96)
qnorm(0.95)
dnorm(0)
win.graph()
plot(dnorm,xlim=c(-3,3))