P-REx Console: Documentation & Reference

1. Combinatorics

choose

Calculates the binomial coefficient (n choose k)

ARGUMENTS

(1) n: total items (number[])
(2) k: items to choose (number[])

EXAMPLE

choose(5, 2)

factorial

Calculates the factorial of a number (n!)

ARGUMENTS

(1) x: single number (number[])

EXAMPLE

factorial(5)

2. Distribution

dbinom

Binomial Distribution Probability Density Function (PDF)

ARGUMENTS

(1) x: vector of quantiles (number[])
(2) size: number of trials (zero or more)
(3) prob: probability of success on each trial

EXAMPLE

dbinom(3, 10, 0.5)

df

F-Distribution Probability Density Function (PDF)

ARGUMENTS

(1) x: vector of quantiles (number[])
(2) df1: [numerator] degrees of freedom (non-negative, but can be non-integer)
(3) df2: [denominaotor] degrees of freedom (non-negative, but can be non-integer)

EXAMPLE

df(2.5, 5, 10)

dnorm

Normal Distribution Probability Density Function (PDF)

ARGUMENTS

(1) x: vector of quantiles (number[])
(2) mean: vector of means (default is 0)
(3) sd: vector of standard deviations (default is 1)

EXAMPLE

dnorm(0, 0, 1)

dpois

Poisson Distribution Probability Density Function (PDF)

ARGUMENTS

(1) x: vector of (non-negative integer) quantiles (number[])
(2) lambda: vector of (non-negative) means (default is 1)

EXAMPLE

dpois(3, 2)

dunif

Uniform Distribution Probability Density Function (PDF)

ARGUMENTS

(1) x: vector of quantiles (number[])
(2) min: lower limit of the distribution (default is 0)
(3) max: upper limit of the distribution (default is 1)

EXAMPLE

dunif(0.5, 0, 1)

pbinom

Binomial Distribution Cumulative Distribution Function (CDF)

ARGUMENTS

(1) q: vector of quantiles (number[])
(2) size: number of trials (zero or more)
(3) prob: probability of success on each trial

EXAMPLE

pbinom(3, 10, 0.5)

pf

F-Distribution Cumulative Distribution Function (CDF)

ARGUMENTS

(1) q: vector of quantiles (number[])
(2) df1: [numerator] degrees of freedom (non-negative, but can be non-integer)
(3) df2: [denominaotor] degrees of freedom (non-negative, but can be non-integer)

EXAMPLE

pf(2.5, 5, 10)

pnorm

Normal Distribution Cumulative Distribution Function (CDF)

ARGUMENTS

(1) q: vector of quantiles (number[])
(2) mean: vector of means (default is 0)
(3) sd: vector of standard deviations (default is 1)

EXAMPLE

pnorm(1.96, 0, 1)

ppois

Poisson Distribution Cumulative Distribution Function (CDF)

ARGUMENTS

(1) q: vector of quantiles (number[])
(2) lambda: vector of (non-negative) means (default is 1)

EXAMPLE

ppois(3, 2)

punif

Uniform Distribution Cumulative Distribution Function (CDF)

ARGUMENTS

(1) q: vector of quantiles (number[])
(2) min: lower limit of the distribution (default is 0)
(3) max: upper limit of the distribution (default is 1)

EXAMPLE

punif(0.5, 0, 1)

qbinom

Binomial Distribution Quantile Function (Inverse CDF)

ARGUMENTS

(1) p: vector of probabilities (number[])
(2) size: number of trials (zero or more)
(3) prob: probability of success on each trial

EXAMPLE

qbinom(0.95, 10, 0.5)

qf

F-Distribution Quantile Function (Inverse CDF)

ARGUMENTS

(1) p: vector of probabilities (number[])
(2) df1: [numerator] degrees of freedom (non-negative, but can be non-integer)
(3) df2: [denominaotor] degrees of freedom (non-negative, but can be non-integer)

EXAMPLE

qf(0.95, 5, 10)

qnorm

Normal Distribution Quantile Function (Inverse CDF)

ARGUMENTS

(1) p: vector of probabilities (number[])
(2) mean: vector of means (default is 0)
(3) sd: vector of standard deviations (default is 1)

EXAMPLE

qnorm(0.975, 0, 1)

qpois

Poisson Distribution Quantile Function (Inverse CDF)

ARGUMENTS

(1) p: vector of probabilities (number[])
(2) lambda: vector of (non-negative) means (default is 1)

EXAMPLE

qpois(0.95, 2)

qunif

Uniform Distribution Quantile Function (Inverse CDF)

ARGUMENTS

(1) p: vector of probabilities (number[])
(2) min: lower limit of the distribution (default is 0)
(3) max: upper limit of the distribution (default is 1)

EXAMPLE

qunif(0.5, 0, 1)

rbinom

Binomial Distribution Random Number Generation

ARGUMENTS

(1) n: number of observations (number[])
(2) size: number of trials (zero or more)
(3) prob: probability of success on each trial

EXAMPLE

rbinom(5, 10, 0.5)

rf

F-Distribution Random Number Generation

ARGUMENTS

(1) n: number of observations (number[])
(2) df1: [numerator] degrees of freedom (non-negative, but can be non-integer)
(3) df2: [denominaotor] degrees of freedom (non-negative, but can be non-integer)

EXAMPLE

rf(5, 5, 10)

rnorm

Normal Distribution Random Number Generation

ARGUMENTS

(1) n: number of observations (number[])
(2) mean: vector of means (default is 0)
(3) sd: vector of standard deviations (default is 1)

EXAMPLE

rnorm(5, 0, 1)

rpois

Poisson Distribution Random Number Generation

ARGUMENTS

(1) n: number of observations (number[])
(2) lambda: vector of (non-negative) means (default is 1)

EXAMPLE

rpois(5, 2)

runif

Uniform Distribution Random Number Generation

ARGUMENTS

(1) n: number of observations (number[])
(2) min: lower limit of the distribution (default is 0)
(3) max: upper limit of the distribution (default is 1)

EXAMPLE

runif(5, 0, 1)

3. Math

abs

Returns the absolute value of a number

ARGUMENTS

(1) x: vector of numbers (number[])

EXAMPLE

abs(-9)

ceiling

Rounds a number up to the nearest integer

ARGUMENTS

(1) x: vector of numbers (number[])

EXAMPLE

ceiling(8.1)

floor

Rounds a number down to the nearest integer

ARGUMENTS

(1) x: vector of numbers (number[])

EXAMPLE

floor(9.9)

round

Rounds each number to the specified number of decimal places

ARGUMENTS

(1) x: vector of numbers (number[])
(2) digits: number of decimal places (number[])

EXAMPLE

round(c(3.14159, 2.71828), 2)

sqrt

Calculates the square root of a number

ARGUMENTS

(1) x: vector of numbers (number[])

EXAMPLE

sqrt(81)

sum

Returns the sum of all elements in a vector of numbers

ARGUMENTS

(1) x: vector of numbers (number[])

EXAMPLE

sum(c(4, 5))

trunc

Returns the integer part of each number by removing any fractional digits

ARGUMENTS

(1) x: vector of numbers (number[])

EXAMPLE

trunc(c(3.7, -2.9))

4. Other

acos

Calculates the arc-cosine (inverse of cosine) of a number

ARGUMENTS

(1) x: vector of numbers (number[])

EXAMPLE

acos(0)

asin

Calculates the arc-sine (inverse of sine) of a number

ARGUMENTS

(1) x: vector of numbers (number[])

EXAMPLE

asin(1)

atan

Calculates the arc-tangent (inverse of tangent) of a number

ARGUMENTS

(1) x: vector of numbers (number[])

EXAMPLE

atan(1)

cos

Calculates the cosine of a number (in radians)

ARGUMENTS

(1) x: vector of numbers (number[])

EXAMPLE

cos(0)

dbeta

Beta Distribution Probability Density Function (PDF)

ARGUMENTS

(1) x: vector of quantiles (number[])
(2) shape1: first shape parameter (α)
(3) shape2: second shape parameter (β)

EXAMPLE

dbeta(0.5, 2, 5)

dcauchy

Cauchy Distribution Probability Density Function (PDF)

ARGUMENTS

(1) x: vector of quantiles (number[])
(2) location: location parameter
(3) scale: scale parameter (non-negative)

EXAMPLE

dcauchy(2, 0, 1)

dchisq

Chi-Square Distribution Probability Density Function (PDF)

ARGUMENTS

(1) x: vector of quantiles (number[])
(1) df: degrees of freedom (non-negative, but can be non-integer)

EXAMPLE

dchisq(2, 3)

dexp

Exponential Distribution Probability Density Function (PDF)

ARGUMENTS

(1) x: vector of quantiles (number[])
(2) rate: rate parameter (λ) (non-negative)

EXAMPLE

dexp(2, 0.5)

dgamma

Gamma Distribution Probability Density Function (PDF)

ARGUMENTS

(1) x: vector of quantiles (number[])
(2) shape: shape parameter
(3) rate: rate parameter (1/scale)

EXAMPLE

dgamma(2.5, 3, 2)

dgeom

Geometric Distribution Probability Density Function (PDF)

ARGUMENTS

(1) x: vector of quantiles representing the number of failures in a sequence of Bernoulli trials before success occurs
(2) prob: probability of success in each trial

EXAMPLE

dgeom(3, 0.5)

dhyper

Hypergeometric Distribution Probability Density Function (PDF)

ARGUMENTS

(1) x: vector of quantiles representing the number of white balls drawn without replacement from an urn which contains both black and white balls
(2) m: the number of white balls in the urn
(3) n: the number of black balls in the urn
(4) k: the number of balls drawn from the urn, hence must be in 0,1,...,m+n

EXAMPLE

dhyper(3, 5, 7, 5)

dlnorm

Log-Normal Distribution Probability Density Function (PDF)

ARGUMENTS

(1) x: vector of quantiles (number[])
(2) meanlog: mean of the log of the distribution
(3) sdlog: standard deviation of the log of the distribution

EXAMPLE

dlnorm(2, 0, 1)

dnbinom

Negative Binomial Probability Mass Function (PMF)

ARGUMENTS

(1) x: vector of counts
(2) size: number of successes
(3) prob: probability of success on each trial

EXAMPLE

dnbinom(3, 5, 0.5)

dt

Student’s t Distribution Probability Density Function (PDF)

ARGUMENTS

(1) x: vector of quantiles (number[])
(2) df: degrees of freedom (non-negative, but can be non-integer)

EXAMPLE

dt(2, 10)

dweibull

Weibull Probability Density Function (PDF)

ARGUMENTS

(1) x: vector of quantiles (number[])
(2) shape: shape parameter (λ)
(3) scale: scale parameter (θ)

EXAMPLE

dweibull(1.5, 2, 3)

exp

Calculates the exponential of a number, e^x

ARGUMENTS

(1) x: vector of numbers (number[])

EXAMPLE

exp(9)

log

Calculates the natural logarithm (base e) of a number

ARGUMENTS

(1) x: vector of numbers (number[])

EXAMPLE

log(9)

log10

Calculates the base 10 logarithm of a number

ARGUMENTS

(1) x: vector of numbers (number[])

EXAMPLE

log10(100)

log2

Calculates the base 2 logarithm of a number

ARGUMENTS

(1) x: vector of numbers (number[])

EXAMPLE

log2(8)

pbeta

Beta Distribution Cumulative Distribution Function (CDF)

ARGUMENTS

(1) q: vector of quantiles (number[])
(2) shape1: first shape parameter (α)
(3) shape2: second shape parameter (β)

EXAMPLE

pbeta(0.5, 2, 5)

pcauchy

Cauchy Distribution Cumulative Distribution Function (CDF)

ARGUMENTS

(1) q: vector of quantiles (number[])
(2) location: location parameter
(3) scale: scale parameter (non-negative)

EXAMPLE

pcauchy(2, 0, 1)

pchisq

Chi-Square Distribution Cumulative Distribution Function (CDF)

ARGUMENTS

(1) q: vector of quantiles (number[])
(2) df: degrees of freedom (non-negative, but can be non-integer)

EXAMPLE

pchisq(2, 3)

pexp

Exponential Distribution Cumulative Distribution Function (CDF)

ARGUMENTS

(1) q: vector of quantiles (number[])
(2) rate: rate parameter (λ) (non-negative)

EXAMPLE

pexp(2, 0.5)

pgamma

Gamma Distribution Cumulative Distribution Function (CDF)

ARGUMENTS

(1) q: vector of quantiles (number[])
(2) shape: shape parameter
(3) rate: rate parameter (1/scale)

EXAMPLE

pgamma(2.5, 3, 2)

pgeom

Geometric Distribution Cumulative Distribution Function (CDF)

ARGUMENTS

(1) q: vector of quantiles representing the number of failures in a sequence of Bernoulli trials before success occurs
(2) prob: probability of success in each trial

EXAMPLE

pgeom(3, 0.5)

phyper

Hypergeometric Distribution Cumulative Distribution Function (CDF)

ARGUMENTS

(1) q: vector of quantiles representing the number of white balls drawn without replacement from an urn which contains both black and white balls
(2) m: the number of white balls in the urn
(3) n: the number of black balls in the urn
(4) k: the number of balls drawn from the urn, hence must be in 0,1,...,m+n

EXAMPLE

phyper(3, 5, 7, 5)

plnorm

Log-Normal Distribution Cumulative Distribution Function (CDF)

ARGUMENTS

(1) q: vector of quantiles (number[])
(2) meanlog: mean of the log of the distribution
(3) sdlog: standard deviation of the log of the distribution

EXAMPLE

plnorm(2, 0, 1)

pmax

Returns the parallel maxima of one or more input vectors

ARGUMENTS

...vectors

EXAMPLE

pmax(c(9, 99, 999), c(100, 50, 10))

pmin

Returns the parallel minima of one or more input vectors

ARGUMENTS

...vectors

EXAMPLE

pmin(c(9, 99, 999), c(100, 50, 10))

pnbinom

Negative Binomial Cumulative Distribution Function (CDF)

ARGUMENTS

(1) q: vector of counts
(2) size: number of successes
(3) prob: probability of success on each trial

EXAMPLE

pnbinom(3, 5, 0.5)

pt

Student’s t Distribution Cumulative Distribution Function (CDF)

ARGUMENTS

(1) q: vector of quantiles (number[])
(2) df: degrees of freedom (non-negative, but can be non-integer)

EXAMPLE

pt(2, 10)

pweibull

Weibull Cumulative Distribution Function (CDF)

ARGUMENTS

(1) q: vector of quantiles (number[])
(2) shape: shape parameter (λ)
(3) scale: scale parameter (θ)

EXAMPLE

pweibull(1.5, 2, 3)

qbeta

Beta Distribution Quantile Function (Inverse CDF)

ARGUMENTS

(1) p: vector of probabilities (number[])
(2) shape1: first shape parameter (α)
(3) shape2: second shape parameter (β)

EXAMPLE

qbeta(0.95, 2, 5)

qcauchy

Cauchy Distribution Quantile Function (Inverse CDF)

ARGUMENTS

(1) p: vector of probabilities (number[])
(2) location: location parameter
(3) scale: scale parameter (non-negative)

EXAMPLE

qcauchy(0.95, 0, 1)

qchisq

Chi-Square Distribution Quantile Function (Inverse CDF)

ARGUMENTS

(1) p: vector of probabilities (number[])
(2) df: degrees of freedom (non-negative, but can be non-integer)

EXAMPLE

qchisq(0.95, 3)

qexp

Exponential Distribution Quantile Function (Inverse CDF)

ARGUMENTS

(1) p: vector of probabilities (number[])
(2) rate: rate parameter (λ) (non-negative)

EXAMPLE

qexp(0.95, 0.5)

qgamma

Gamma Distribution Quantile Function (Inverse CDF)

ARGUMENTS

(1) p: vector of probabilities (number[])
(2) shape: shape parameter
(3) rate: rate parameter (1/scale)

EXAMPLE

qgamma(0.95, 3, 2)

qgeom

Geometric Distribution Quantile Function (Inverse CDF)

ARGUMENTS

(1) p: vector of probabilities (number[])
(2) prob: probability of success in each trial

EXAMPLE

qgeom(0.95, 0.5)

qhyper

Hypergeometric Distribution Quantile Function (Inverse CDF)

ARGUMENTS

(1) p: vector of probabilities (number[])
(2) m: the number of white balls in the urn
(3) n: the number of black balls in the urn
(4) k: the number of balls drawn from the urn, hence must be in 0,1,...,m+n

EXAMPLE

qhyper(0.95, 5, 7, 5)

qlnorm

Log-Normal Distribution Quantile Function (Inverse CDF)

ARGUMENTS

(1) p: vector of probabilities (number[])
(2) meanlog: mean of the log of the distribution
(3) sdlog: standard deviation of the log of the distribution

EXAMPLE

qlnorm(0.95, 0, 1)

qnbinom

Negative Binomial Quantile Function (Inverse CDF)

ARGUMENTS

(1) p: vector of probabilities (number[])
(2) size: number of successes
(3) prob: probability of success on each trial

EXAMPLE

qnbinom(0.95, 5, 0.5)

qt

Student’s t-Distribution Quantile Function (Inverse CDF)

ARGUMENTS

(1) p: vector of probabilities (number[])
(2) df: degrees of freedom (non-negative, but can be non-integer)

EXAMPLE

qt(0.975, 10)

quantile

Computes sample quantiles corresponding to given probabilities

ARGUMENTS

(1) x: vector of numbers (number[])
(2) probs: vector of probabilities (number[]) between 0 and 1

EXAMPLE

quantile(c(1, 2, 3, 4, 5), c(0.25, 0.5, 0.75))

qweibull

Weibull Quantile Function (Inverse CDF)

ARGUMENTS

(1) p: vector of probabilities (number[])
(2) shape: shape parameter (λ)
(3) scale: scale parameter (θ)

EXAMPLE

qweibull(0.95, 2, 3)

rbeta

Beta Distribution Random Number Generation

ARGUMENTS

(1) n: number of observations (number[])
(2) shape1: first shape parameter (α)
(3) shape2: second shape parameter (β)

EXAMPLE

rbeta(5, 2, 5)

rcauchy

Cauchy Distribution Random Number Generation

ARGUMENTS

(1) n: number of observations (number[])
(2) location: location parameter
(3) scale: scale parameter (non-negative)

EXAMPLE

rcauchy(5, 0, 1)

rchisq

Chi-Square Distribution Random Number Generation

ARGUMENTS

(1) n: number of observations (number[])
(2) df: degrees of freedom (non-negative, but can be non-integer)

EXAMPLE

rchisq(5, 3)

rexp

Exponential Distribution Random Number Generation

ARGUMENTS

(1) n: number of observations (number[])
(2) rate: rate parameter (λ) (non-negative)

EXAMPLE

rexp(5, 0.5)

rgamma

Gamma Distribution Random Number Generation

ARGUMENTS

(1) n: number of observations (number[])
(2) shape: shape parameter
(3) rate: rate parameter (1/scale)

EXAMPLE

rgamma(5, 3, 2)

rgeom

Geometric Distribution Random Number Generation

ARGUMENTS

(1) n: number of observations (number[])
(2) prob: probability of success in each trial

EXAMPLE

rgeom(5, 0.5)

rhyper

Hypergeometric Distribution Random Number Generation

ARGUMENTS

(1) nn: number of observations (number[])
(2) m: the number of white balls in the urn
(3) n: the number of black balls in the urn
(4) k: the number of balls drawn from the urn, hence must be in 0,1,...,m+n

EXAMPLE

rhyper(5, 5, 7, 5)

rlnorm

Log-Normal Distribution Random Number Generation

ARGUMENTS

(1) n: number of observations (number[])
(2) meanlog: mean of the log of the distribution
(3) sdlog: standard deviation of the log of the distribution

EXAMPLE

rlnorm(5, 0, 1)

rnbinom

Negative Binomial Random Number Generation

ARGUMENTS

(1) n: number of observations (number[])
(2) size: number of successes
(3) prob: probability of success on each trial

EXAMPLE

rnbinom(5, 5, 0.5)

rt

Student’s t-Distribution Random Number Generation

ARGUMENTS

(1) n: number of observations (number[])
(2) df: degrees of freedom (non-negative, but can be non-integer)

EXAMPLE

rt(5, 10)

rweibull

Weibull Random Number Generation

ARGUMENTS

(1) n: number of observations (number[])
(2) shape: shape parameter (λ)
(3) scale: scale parameter (θ)

EXAMPLE

rweibull(5, 2, 3)

seq

Generates a sequence of numbers based on specified parameters. The sequence can be defined by a start, end, and step value

ARGUMENTS

(1) from: starting value of the sequence (number[])
(2) to: end value of the sequence (number[])
(3) by: increment of the sequence (number[])

EXAMPLE

seq(1, 10, 2)

signif

Rounds each number to the specified number of significant digits

ARGUMENTS

(1) x: vector of numbers (number[])
(2) digits: number of significant digits (number[])

EXAMPLE

signif(c(123.456, 0.0123456), 4)

sin

Calculates the sine of a number (in radians)

ARGUMENTS

(1) x: vector of numbers (number[])

EXAMPLE

sin(pi/2)

sort

Returns a sorted vector of numbers in ascending order

ARGUMENTS

(1) x: vector of numbers (number[])

EXAMPLE

sort(c(9, 27, 18))

tan

Calculates the tangent of a number (in radians)

ARGUMENTS

(1) x: vector of numbers (number[])

EXAMPLE

tan(pi/4)

5. Statistical

max

Returns the maximum value from an vector of numbers

ARGUMENTS

(1) x: vector of numbers (number[])

EXAMPLE

max(c(9, 99, 999))

mean

Calculates the arithmetic mean (average) of a set of numbers

ARGUMENTS

(1) x: vector of numbers (number[])

EXAMPLE

mean(c(3, 6, 9))

median

Calculates the median value of a set of numbers

ARGUMENTS

(1) x: vector of numbers (number[])

EXAMPLE

median(c(9, 19, 29))

min

Returns the minimum value from an vector of numbers

ARGUMENTS

(1) x: vector of numbers (number[])

EXAMPLE

min(c(9, 99, 999))

range

Returns a vector containing the minimum and maximum values of a vector of numbers

ARGUMENTS

(1) x: vector of numbers (number[])

EXAMPLE

range(c(3, 6, 9))

sd

Calculates the standard deviation of a set of numbers

ARGUMENTS

(1) x: vector of numbers (number[])

EXAMPLE

sd(c(3, 6, 9))

summary

Generates a six-number summary of a numeric array, including the minimum, 1st quartile, median, mean, 3rd quartile, and maximum. Useful for quickly assessing the distribution of values.

ARGUMENTS

(1) x: numeric array (number[])

EXAMPLE

summary(rnorm(108, 0, 1))

t.test

Performs a one-sample or Welch two-sample t-test and returns a printed test summary. For one-sample tests, the mean is compared to 0. For two-sample tests, the null hypothesis is that the two population means are equal.

ARGUMENTS

(1) x: numeric array (number[]) for one-sample t-test
(2) y: optional second numeric array (number[]) for two-sample t-test

EXAMPLE

t.test(rnorm(108, 0, 1))

var

Calculates the variance of a set of numbers

ARGUMENTS

(1) x: vector of numbers (number[])

EXAMPLE

var(c(9, 18, 27))

6. Vector/Utility

c

Combines multiple values into an vector

ARGUMENTS

...values: any[]

EXAMPLE

data <- c(9, 18, 27, 36, 45)

length

Returns the number of elements in a vector

ARGUMENTS

(1) x: vector of numbers (number[])

EXAMPLE

length(c(4, 8, 15, 16, 23, 42))

rep

Replicates the values in a vector multiple times, either by a specific number of times or based on the length of the result

ARGUMENTS

(1) x: number or vector of numbers (number[]) to be replicated
(2) times: number of times to repeat each element

EXAMPLE

rep(3, 4)
Back to top