Skip to content

Instantly share code, notes, and snippets.

@airicbear
Last active March 8, 2019 19:53
Show Gist options
  • Save airicbear/79ade02320e4a1f86ee339dfb43aec30 to your computer and use it in GitHub Desktop.
Save airicbear/79ade02320e4a1f86ee339dfb43aec30 to your computer and use it in GitHub Desktop.
using Distributions
# Parameters:
# - d: Distribution
# - N: Sample Size
# Returns the sample standard deviation of distribution d given N sample size
_samplestd(d, N) = std(d) / sqrt(N)
# Parameters:
# - μ: The mean of the distribution
# - σ: The standard deviation of the distribution
# - X: The x value of interest
# Returns the z-score of distribution d at x-value X
_zscore(μ, σ, X) = (X - μ) / σ
_samplezscore(d, N, X) = _zscore(mean(d), _samplestd(d, N), X)
# Parameters:
# - d: Distribution
# - z: The z-score of interest
# Returns the probability of distribution d from z-scores -∞ to z
_leftarea(d, z) = (cdf(d, mean(d) + (std(d) * z)))
# Returns the probability of distribution d from z-scores z to ∞
_rightarea(d, z) = 1 - _leftarea(d, z)
# Returns the probability of distribution d between the two z-scores
_intervalarea(d, zs) = _leftarea(d, maximum(zs)) - _leftarea(d, minimum(zs))
sampleleftarea(d, N, X) = _leftarea(d, _samplezscore(d, N, X))
samplerightarea(d, N, X) = 1 - _sampleleftarea(d, N, X)
sampleintervalarea(d, N, Xs) = _sampleleftarea(d, N, maximum(Xs)) - _sampleleftarea(d, N, minimum(Xs))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment