R Programming/Probability Functions
From Wikibooks, the open-content textbooks collection
Contents |
[edit] Overview
R has lots of probability functions.
ris the generic prefix for random variable generator such asrunif(),rnorm()dis the generic prefix for the probability density function (therefore pdf).pis the generic prefix for the cumulative density function (therefore cdf)qis the generic prefix for the quantile function (or inverse cdf).
| Distribution | Keyword | Package | CDF | Quantile | Random Deviates | |
|---|---|---|---|---|---|---|
| Student | TDist | stats | pt | qt | dt | rt |
| Beta | Beta | stats | pbeta | qbeta | dbeta | rbeta |
| Cauchy | Cauchy | stats | pcauchy | qcauchy | dcauchy | rcauchy |
| Gamma | GammaDist | stats | ||||
| Logistic | stats | plogis | qlogis | dlogis | rlogis | |
| Weibull | stats | |||||
| Dirichlet | gtools | |||||
| Dirichlet | MCMCpack | |||||
| InvGamma | MCMCpack | |||||
| InvWishart | MCMCpack | |||||
| Burr | Burr | actuar | dburr | pburr | qburr | rburr |
| Pareto | actuar | dpareto | ppareto | rpareto | qpareto | |
| Gumbel | evd | dgumbel | ||||
| Frechet | evd | dfrechet | ||||
| Generalized Pareto | evd | dgpd | ||||
| Generalized Extreme Value | evd | dgev |
-
- Geometric
- Hypergeometric
- Tukey
- Wilcoxon
- See also the "SuppDists" package.
[edit]
- The mvtnorm package includes functions for multivariate normal distributions.
- TDist
- Chisquare
- FDist
- Lognormal
- Normal
[edit]
- The Gumbel Distribution
- The logistic distribution : distribution of the difference of two gumbel distributions.
[edit] Discrete distributions
-
- Binomial
- Poisson
- Multinomial
- NegBinomial
[edit] Distribution for circular statistics
- Functions for circular statistics are included in the CircStats package.
- dvm() Von Mises density function
- dtri() triangular density function
- dmixedvm() Mixed Von Mises density
- dwrpcauchy() wrapped cauchy density
- dwrpnorm() wrapped normal density.
[edit] Getting the quantile
Some quantile are very useful, especially when you have to construct confidence interval or to test an hypothesis.
Quantile of the normal distribution
> qnorm(.95) [1] 1.644854 > qnorm(.975) [1] 1.959964 > qnorm(.99) [1] 2.326348
Quantile of the Student t distribution
> qt(.975,30) [1] 2.042272 > qt(.975,100) [1] 1.983972 > qt(.975,1000) [1] 1.962339
Quantile of the χ2 distribution
> qchisq(.95,1) [1] 3.841459 > qchisq(.95,10) [1] 18.30704 > qchisq(.95,100) [1] 124.3421