P: Cumulative distribution function

View source: R/probability.R

PR Documentation

Cumulative distribution function

Description

P Compute the cumulative distribution function for multiple distributions

Usage

P(
  q,
  dist = "normal",
  lower.tail = TRUE,
  rounding = 5,
  porcentage = FALSE,
  gui = "plot",
  main = NULL,
  ...
)

Arguments

q

quantile. The q argument can have length 1 or 2. See Details.

dist

distribution to use. The default is 'normal'. Options: 'normal', 't-student', 'chisq', 'f', ...

lower.tail

logical; if TRUE (default), probabilities are P[X \leq x] otherwise, P[X > x]. This argument is valid only if q has length 1.

rounding

numerical; it represents the number of decimals for calculating the probability.

porcentage

logical; if FALSE (default), the result in decimal. Otherwise, probability is given in percentage.

gui

default is 'plot'; it graphically displays the result of the probability. Others options are: 'none', 'rstudio' or 'tcltk'.

main

defalt is NULL; it represents title of plot.

...

additional arguments according to the chosen distribution.

Details

The argument that can have length 2, when we use the functions that give us the probability regions, given by: %<X<%, %<=X<%, %<X<=%, %<=X<=%, %>X>%, %>X=>%, %>X=>% and %>=X=>%. The additional arguments represent the parameters of the distributions, that is:

  • If dist = "normal" (Default); the additional arguments are: mean (\mu) and sd (\sigma). The PDF is given by:

    \displaystyle{f_X(x; \mu, \sigma) = \frac {1}{\sqrt {2\pi \sigma ^{2}}}}e^{-{\frac {(x-\mu )^{2}}{2\sigma ^{2}}}}, \quad x \in \mathbb{R},~ \mu \in \mathbb{R},~\sigma^2 > 0;

  • If dist = "t-student"; the additional argument is: df (\nu). The PDF is given by:

    \displaystyle{f_X(x; \nu) = \frac {\Gamma \left({\frac {\ \nu +1\ }{2}}\right)}{{\sqrt {\pi \ \nu \ }}\ \Gamma \left({\frac {\nu }{\ 2\ }}\right)}}\left(\ 1+{\frac {~x^{2}\ }{\nu }}\ \right)^{-{\frac {\ \nu +1\ }{2}}}, \quad x \in \mathbb{R},~\nu > 1;

  • If dist = "chisq"; the additional argument is: df (\nu). The PDF is given by:

    \displaystyle{f_X(x; \nu) = \frac {1}{2^{k/2}\Gamma (k/2)}}\;x^{k/2-1}e^{-x/2}, \quad x > 0,~\nu > 0;

  • If dist = "f"; the additional argument is: df1 (\nu_1) and df2 (\nu_2). The PDF is given by:

    f_X(x; \nu_1, \nu_2) = {\displaystyle {\frac {\sqrt {\frac {(\nu_{1}x)^{\nu_{1}}\nu_{2}^{\nu_{2}}}{(\nu_{1}x+\nu_{2})^{\nu_{1}+\nu_{2}}}}}{x\,\mathrm {B} \!\left({\frac {\nu_{1}}{2}},{\frac {\nu_{2}}{2}}\right),}}\!}, \quad x > 0,~\nu_1,\nu_2 > 0;

    where, x > 0, \nu_1,~\nu_2 > 0, and B is the beta function.

The ncp parameter (\lambda \in \mathbb{R}) represents the noncentrality parameter. The PDFs presented graphically do not take this parameter into account. However, to reinforce the importance of this parameter in the three distributions (Student's t-distribution, F-distribution and Chi-squared distribution), especially when studying hypothesis testing, we present their distributions taking into account the ncp parameter, as follows:

  • The PDF for the noncentral t-distribution with \nu > 0 degrees of freedom and noncentrality parameter \lambda is based on the pt function. If Z is a standard normal random variable, and V is a chi-squared distribution random variable with \nu degrees of freedom that is independent of Z, then T = (Z + \lambda) / \sqrt{V / \nu} is a noncentral t-distributed random variable with \nu degrees of freedom and noncentrality parameter \lambda. If \lambda = 0, the PDF reduces to the probability density function of the Student's t-distribution. However, it is worth noting that the parameter \lambda \in \mathbb{R}.

Value

P returns the probability and its graphical representation. The result can be given as a percentage or not.

Examples

# Loading package
library(leem)
# Example 1 - Student's t distribution
## Not run: 
P(q = 2, dist = "t-student", df = 10)
P(q = 2, dist = "t-student", df = 10, gui = 'rstudio')
P(q = 2, dist = "t-student", df = 10, gui = 'tcltk')
P(-1 %<X<% 1, dist = "t-student", df = 10)

## End(Not run)
# Example 2 - Normal distribution
P(-2,  dist = "normal", mean = 3, sd = 2,
  main = expression(f(x) == (1 / sqrt(n * sigma^2)) *
  exp(-1/2 * (x - mu)^2/sigma^2)))

bendeivide/leem documentation built on June 10, 2025, 10:31 p.m.