Skip to content

A simple script to implement statistical functions not provided by the Lua standard API, developed especially for use on Roblox

License

Notifications You must be signed in to change notification settings

Bytebit-Org/lua-statistics

Repository files navigation

Lua Statistics

CI status PRs Welcome License: MIT Discord server

A simple script to implement statistical functions not provided by the Lua standard API, developed especially for use on Roblox

Installation

Wally

Wally users can install this package by adding the following line to their Wally.toml under [dependencies]:

statistics = "bytebit/statistics@1.0.0"

Then just run wally install.

From model file

Model files are uploaded to every release as .rbxmx files. You can download the file from the Releases page and load it into your project however you see fit.

From model asset

New versions of the asset are uploaded with every release. The asset can be added to your Roblox Inventory and then inserted into your Place via Toolbox by getting it here.

Documentation


Series Functions

statistics.series.sum = function (series)

Given a series of numbers, this will calculate the sum

Parameters:

  • series (array<number>)
    An array of numbers

Returns:
number
A number

statistics.series.mean = function (series)

Given a series of numbers, this will calculate the mean

Parameters:

  • series (array<number>)
    An array of numbers

Returns:
number
A number

statistics.series.median = function (series)

Given a series of numbers, this will find the median

Parameters:

  • series (array<number>)
    An array of numbers

Returns:
number
A number

Complexity analysis:

  • Time: O(n lg(n))
  • Memory: O(n)
statistics.series.mode = function (series)

Given a series of values, this will find the mode If there is a tie, then all the values that tied will be returned as a sorted array. Note that this function will work regardless of data type; The data types just need to be sortable in some way and have a method of equality

Parameters:

  • series (array<any>)
    An array of values

Returns:
any
If there was a tie, then a sorted array; otherwise a number

Complexity analysis:

  • Time: O(n lg(n))
  • Memory: O(n)
statistics.series.variance = function (series)

Given a series of numbers, this will find the variance

Parameters:

  • series (array<number>)
    An array of numbers

Returns:
number
A number

statistics.series.standardDeviation = function (series)

Given a series of numbers, this will find the standard deviation

Parameters:

  • series (array<number>)
    An array of numbers

Returns:
number
A number

statistics.series.getExtremes = function (series)

Given a series of numbers, this will find the minimum and maximum values

Parameters:

  • series (array<number>)
    An array of numbers

Returns:
[t:tuple<number, number>] The minimum and maximum values as a tuple: <min, max>

statistics.series.generate = function (seriesLength, samplingFunction, ...)

Generates a series of numbers pulled from a particular sampling distribution

Parameters:

  • seriesLength (number)
    The length of the series to generate
  • samplingFunction (function)
    The sampling function to use
  • ... (any)
    Any arguments needed for the sampling function

Returns:
array<number>
An array of numbers

Distribution Functions

Continuous Distributions

statistics.distributions.standardNormal = function ()

Samples from a standard normal distribution (mean = 0, variance = 1) Implementation is based on the Box-Muller (1958) transformation

Returns:
number
A number sampled from the defined distribution

statistics.distributions.normal = function (mean, variance)

Samples from a normal distribution with a given mean and variance

Parameters:

  • mean (number)
    The mean for the distribution
  • variance (number)
    The variance for the distribution

Returns:
number
A number sampled from the defined distribution

statistics.distributions.exponential = function (rate)

Samples from an exponential distribution with a given rate

Parameters:

  • rate (number)
    The rate for the distribution

Returns:
number
A number sampled from the defined distribution

Discrete Distributions

statistics.distributions.bernoulli = function (successProbability)

Samples from a bernoulli distribution with given probability

Parameters:

  • successProbability (number)
    The probability of obtaining a 1

Returns:
number
A 0 or a 1, according to the distribution

statistics.distributions.binomial = function (numberOfTrials, successProbability)

Samples from a binomial distribution with given probability and number of trials

Parameters:

  • numberOfTrials (number)
    The number of trials for the distribution
  • successProbability (number)
    The probability of a success on any given trial

Returns:
number
A non-negative integer in the range [0, numberOfTrials], according to the defined distribution

statistics.distributions.standardDiscrete = function (distribution, values)

Samples from a given discrete distribution

Parameters:

  • distribution (array<number>)
    An array of numbers that should sum to 1
  • values (array<any>)
    An array of values of the same length as distribution

Returns:
any
A value sampled according to the given distribution

statistics.distributions.geometric = function (successProbability)

Samples from a geometric distribution with given success probability Note that this implementation allows for 0

Parameters:

  • successProbability (number)
    The success probability parameter for the distribution

Returns:
number
A non-negative integer sampled from the defined distribution

About

A simple script to implement statistical functions not provided by the Lua standard API, developed especially for use on Roblox

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published