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
factorial
Calculates the factorial of a number (n!
)
ARGUMENTS
(1) x: single number (number[])
EXAMPLE
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
rpois
Poisson Distribution Random Number Generation
ARGUMENTS
(1) n: number of observations (number[])
(2) lambda: vector of (non-negative) means (default is 1)
EXAMPLE
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
3. Math
abs
Returns the absolute value of a number
ARGUMENTS
(1) x: vector of numbers (number[])
EXAMPLE
ceiling
Rounds a number up to the nearest integer
ARGUMENTS
(1) x: vector of numbers (number[])
EXAMPLE
floor
Rounds a number down to the nearest integer
ARGUMENTS
(1) x: vector of numbers (number[])
EXAMPLE
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
sqrt
Calculates the square root of a number
ARGUMENTS
(1) x: vector of numbers (number[])
EXAMPLE
sum
Returns the sum of all elements in a vector of numbers
ARGUMENTS
(1) x: vector of numbers (number[])
EXAMPLE
trunc
Returns the integer part of each number by removing any fractional digits
ARGUMENTS
(1) x: vector of numbers (number[])
EXAMPLE
4. Other
acos
Calculates the arc-cosine (inverse of cosine) of a number
ARGUMENTS
(1) x: vector of numbers (number[])
EXAMPLE
asin
Calculates the arc-sine (inverse of sine) of a number
ARGUMENTS
(1) x: vector of numbers (number[])
EXAMPLE
atan
Calculates the arc-tangent (inverse of tangent) of a number
ARGUMENTS
(1) x: vector of numbers (number[])
EXAMPLE
cos
Calculates the cosine of a number (in radians)
ARGUMENTS
(1) x: vector of numbers (number[])
EXAMPLE
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
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
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
dexp
Exponential Distribution Probability Density Function (PDF)
ARGUMENTS
(1) x: vector of quantiles (number[])
(2) rate: rate parameter (λ) (non-negative)
EXAMPLE
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
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
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
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
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
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
dweibull
Weibull Probability Density Function (PDF)
ARGUMENTS
(1) x: vector of quantiles (number[])
(2) shape: shape parameter (λ)
(3) scale: scale parameter (θ)
EXAMPLE
exp
Calculates the exponential of a number, e^x
ARGUMENTS
(1) x: vector of numbers (number[])
EXAMPLE
log
Calculates the natural logarithm (base e) of a number
ARGUMENTS
(1) x: vector of numbers (number[])
EXAMPLE
log10
Calculates the base 10 logarithm of a number
ARGUMENTS
(1) x: vector of numbers (number[])
EXAMPLE
log2
Calculates the base 2 logarithm of a number
ARGUMENTS
(1) x: vector of numbers (number[])
EXAMPLE
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
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
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
pexp
Exponential Distribution Cumulative Distribution Function (CDF)
ARGUMENTS
(1) q: vector of quantiles (number[])
(2) rate: rate parameter (λ) (non-negative)
EXAMPLE
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
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
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
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
pmax
Returns the parallel maxima of one or more input vectors
ARGUMENTS
...vectors
EXAMPLE
pmin
Returns the parallel minima of one or more input vectors
ARGUMENTS
...vectors
EXAMPLE
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
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
pweibull
Weibull Cumulative Distribution Function (CDF)
ARGUMENTS
(1) q: vector of quantiles (number[])
(2) shape: shape parameter (λ)
(3) scale: scale parameter (θ)
EXAMPLE
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
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
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
qexp
Exponential Distribution Quantile Function (Inverse CDF)
ARGUMENTS
(1) p: vector of probabilities (number[])
(2) rate: rate parameter (λ) (non-negative)
EXAMPLE
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
qgeom
Geometric Distribution Quantile Function (Inverse CDF)
ARGUMENTS
(1) p: vector of probabilities (number[])
(2) prob: probability of success in each trial
EXAMPLE
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
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
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
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
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
qweibull
Weibull Quantile Function (Inverse CDF)
ARGUMENTS
(1) p: vector of probabilities (number[])
(2) shape: shape parameter (λ)
(3) scale: scale parameter (θ)
EXAMPLE
rbeta
Beta Distribution Random Number Generation
ARGUMENTS
(1) n: number of observations (number[])
(2) shape1: first shape parameter (α)
(3) shape2: second shape parameter (β)
EXAMPLE
rcauchy
Cauchy Distribution Random Number Generation
ARGUMENTS
(1) n: number of observations (number[])
(2) location: location parameter
(3) scale: scale parameter (non-negative)
EXAMPLE
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
rexp
Exponential Distribution Random Number Generation
ARGUMENTS
(1) n: number of observations (number[])
(2) rate: rate parameter (λ) (non-negative)
EXAMPLE
rgamma
Gamma Distribution Random Number Generation
ARGUMENTS
(1) n: number of observations (number[])
(2) shape: shape parameter
(3) rate: rate parameter (1/scale)
EXAMPLE
rgeom
Geometric Distribution Random Number Generation
ARGUMENTS
(1) n: number of observations (number[])
(2) prob: probability of success in each trial
EXAMPLE
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
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
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
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
rweibull
Weibull Random Number Generation
ARGUMENTS
(1) n: number of observations (number[])
(2) shape: shape parameter (λ)
(3) scale: scale parameter (θ)
EXAMPLE
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
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
sin
Calculates the sine of a number (in radians)
ARGUMENTS
(1) x: vector of numbers (number[])
EXAMPLE
sort
Returns a sorted vector of numbers in ascending order
ARGUMENTS
(1) x: vector of numbers (number[])
EXAMPLE
tan
Calculates the tangent of a number (in radians)
ARGUMENTS
(1) x: vector of numbers (number[])
EXAMPLE
5. Statistical
max
Returns the maximum value from an vector of numbers
ARGUMENTS
(1) x: vector of numbers (number[])
EXAMPLE
mean
Calculates the arithmetic mean (average) of a set of numbers
ARGUMENTS
(1) x: vector of numbers (number[])
EXAMPLE
median
Calculates the median value of a set of numbers
ARGUMENTS
(1) x: vector of numbers (number[])
EXAMPLE
min
Returns the minimum value from an vector of numbers
ARGUMENTS
(1) x: vector of numbers (number[])
EXAMPLE
range
Returns a vector containing the minimum and maximum values of a vector of numbers
ARGUMENTS
(1) x: vector of numbers (number[])
EXAMPLE
sd
Calculates the standard deviation of a set of numbers
ARGUMENTS
(1) x: vector of numbers (number[])
EXAMPLE
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
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
var
Calculates the variance of a set of numbers
ARGUMENTS
(1) x: vector of numbers (number[])
EXAMPLE
6. Vector/Utility
c
Combines multiple values into an vector
ARGUMENTS
...values: any[]
EXAMPLE
length
Returns the number of elements in a vector
ARGUMENTS
(1) x: vector of numbers (number[])
EXAMPLE
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