Math Library - Extended Mathematical¶
This library contains extended mathematical functions beyond the core PEBLMath namespace.
Bound()¶
Returns val, bounded by min and max.
Description:
This makes sure number is between min and max; if min>max, it will return max, soyou need to check if that isn’t the right behavior.
Usage:
define Bound(number,min,max)
CumNormInv()¶
Returns accurate numerical approximation of cumulative normal inverse.
Description:
This function takes a probability and returns the corresponding z-score for the cumulative standard normal distribution. It uses an accurate numerical approximation from: http://home.online.no/~pjacklam/notes/invnorm
Usage:
define CumNormInv(...)
Example:
Print(CumNormInv(0)) #= NA
Print(CumNormInv(.01)) #= -2.32634
Print(CumNormInv(.5)) #= 0
Print(CumNormInv(.9)) #= 1.28
Print(CumNormInv(1)) #= NA
See Also:
CumSum()¶
Returns the cumulative sums of a set of numbers
Description:
Returns the cumulative sum of <list>.
Usage:
define CumSum(...)
Example:
sum <- CumSum([1,2,3,3,4,7])
# == [1,3,6,9,13,20]
See Also:
Dist()¶
Returns distance between two points.
Description:
Returns Euclidean distance between two points. Each point should be [x,y], and any additional items in the list are ignored.
Usage:
define Dist(...)
Example:
p1 <- [0,0]
p2 <- [3,4]
d <- Dist(p1,p2) #d is 5
Filter()¶
Filters a list based on a 0/1 list produced by Match.
Description:
Returns a subset of <list>, depending on whether the <filter> list is zero or nonzero. Both arguments must be lists of the same length.
Usage:
define Filter(...)
Example:
x <- [1,2,3,3,2,2,1]
Print(Filter(x,[1,1,1,0,0,0,0])) ##==[1,2,3]
Print(Filter(x,Match(x,1))) ##== [1,1]
See Also:
Match()¶
Returns a list of 0/1s, indicating which elements of list match item.
Description:
Returns a list of 0/1, indicating which elements of <list> match <target>
Usage:
define Match(...)
Example:
x <- [1,2,3,3,2,2,1]
Print(Match(x,1)) ##== [1,0,0,0,0,0,1]
Print(Match(x,2)) ##== [0,1,0,0,1,1,0]
Print( Match(x,3) ##== [0,0,1,1,0,0,0]
See Also:
NormalDensity()¶
Returns density of standard normal distribution.
Description:
Computes density of normal standard distribution
Usage:
define NormalDensity(...)
Example:
Print(NormalDensity(-100)) # 1.8391e-2171
Print(NormalDensity(-2.32635)) #5.97
Print(NormalDensity(0)) #0.398942
Print(NormalDensity(1.28155)) #.90687
Print(NormalDensity(1000)) #inf
See Also:
Order()¶
Description:
Returns a list of indices describing the order of values by position, from min to max.
Usage:
define Order(...)
Example:
n <- [33,12,1,5,9]
o <- Order(n)
Print(o) #should print [3,4,5,2,1]
See Also:
Rank()¶
Description:
Returns a list of numbers describing the rank of each position, from min to max. The same as calling Order(Order(x)).
Usage:
define Rank(...)
Example:
n <- [33,12,1,5,9]
o <- Rank(n)
Print(o) #should print [5,4,1,2,3]
See Also:
SDTBeta()¶
Computes SDT beta.
Description:
SDTBeta computes beta, as defined by signal detection theory. This is a measure of decision bias based on hit rate and false alarm rate.
Usage:
define SDTBeta(...)
Example:
Print(SDTBeta(.1,.9))
Print(SDTBeta(.1,.5))
Print(SDTBeta(.5,.5))
Print(SDTBeta(.8,.9))
Print(SDTbeta(.9,.95))
See Also:
SDTDPrime()¶
Computes SDT dprime.
Description:
SDTDPrime computes d-prime, as defined by signal detection theory. This is a measure of sensitivy based jointly on hit rate and false alarm rate.
Usage:
define SDTDPrime(...)
Example:
Print(SDTDPrime(.1,.9)) #2.56431
Print(SDTDPrime(.1,.5)) #1.28155
Print(SDTDPrime(.5,.5)) #0
Print(SDTDPrime(.8,.9)) #.43993
Print(SDTDPrime(.9,.95)) #.363302
See Also:
Sum()¶
Description:
Returns the sum of <list>.
Usage:
define Sum(...)
Example:
sum <- Sum([3,5,99,12,1.3,15]) # == 135.3
See Also:
SummaryStats()¶
Description:
Computes summary statistics for a data list, aggregated by labels in a condition list. For each condition (distinct label in the <cond> list), it will return a list with the following entries: <cond> <N> <median> <mean> <sd>
Usage:
define SummaryStats(...)
Example:
dat <- [1.1,1.2,1.3,2.1,2.2,2.3]
cond <- [1,1,1,2,2,2]
Print(SummaryStats(dat,cond))
Result:
[[1, 3, 1.1, 1.2, 0.0816497]
, [2, 3, 2.1, 2.2, 0.0816497]
]
See Also:
VecSum()¶
Returns the pairwise sums of two lists of numbers
Description:
Returns the pairwise sums of <list1> and <list2>.
Usage:
define VecSum(...)
Example:
sum <- VecSum([1,1,1,1,2],[2,3,4,3,2])
## == [3,4,5,4,4]
See Also:
VecTimes(), CumSum(), Median(), Quantile()
VecTimes()¶
Returns the pairwise products of two lists of numbers
Description:
Returns the pairwise sums of <list1> and <list2>.
Usage:
define VecTimes(...)
Example:
prod <- VecTimes([1,1,2,2,3],[2,3,4,3,2])
## == [2,3,8,6,6]
See Also:
Max()¶
Returns the largest value in a list
Description:
Max returns the largest value in a list. This is a PEBL function that wraps the compiled Max function, adding error checking to ensure the argument is a list.
Usage:
define Max(list)
Example:
numbers <- [3, 7, 2, 9, 4]
max_value <- Max(numbers) # Returns 9
See Also:
Median()¶
Returns the median value of a list
Description:
Median returns the median value of a list. If the list has an even number of elements, it returns the average of the two middle values. This is a PEBL function that provides error checking and handles edge cases.
Usage:
define Median(list)
Example:
numbers1 <- [3, 7, 2, 9, 4]
med1 <- Median(numbers1) # Returns 4
numbers2 <- [1, 2, 3, 4]
med2 <- Median(numbers2) # Returns 2.5
See Also:
Min()¶
Returns the smallest value in a list
Description:
Min returns the smallest value in a list. This is a PEBL function that wraps the compiled Min function, adding error checking to ensure the argument is a list.
Usage:
define Min(list)
Example:
numbers <- [3, 7, 2, 9, 4]
min_value <- Min(numbers) # Returns 2
See Also:
StdDev()¶
Returns the standard deviation of a list
Description:
StdDev computes the standard deviation of a list of numbers. It uses the formula: sqrt(n * sum(x^2) - (sum(x))^2) / n. Returns 0 for empty lists. This is a PEBL function implemented in Math.pbl.
Usage:
define StdDev(list)
Example:
data <- [2, 4, 4, 4, 5, 5, 7, 9]
sd <- StdDev(data) # Calculates standard deviation
See Also:
Mean(), Median(), Min(), Max(), Sum(), SummaryStats()
GCD()¶
Computes the greatest common divisor of two integers
Description:
GCD computes the greatest common divisor (GCD) of two integers using the Euclidean algorithm. The GCD is the largest positive integer that divides both numbers without a remainder. The function works with both positive and negative integers by taking their absolute values.
Usage:
define GCD(a, b)
Example:
Print(GCD(48, 18)) # Returns 6
Print(GCD(100, 25)) # Returns 25
Print(GCD(17, 19)) # Returns 1 (coprime)
Print(GCD(-24, 36)) # Returns 12
See Also: