Misc

Miscellaneous helper functions.

 

kurt

Computes the excess kurtosis.


def kurt(y:Iterable)->float:
"""
Computes excess kurtosis.
"""

Example


import scisuit.stats as stat
import numpy as np

lst = [88, 95, 92, 97, 96, 97, 94, 86, 91, 95, 97, 88, 85, 76, 68]

kurt = stat.kurt(lst)

print(kurt)
#0.6393842

 

Notice that there are different ways of computing kurtosis. Above results are in-line with the following approach of R:


library(e1071) 
x=c(88, 95, 92, 97, 96, 97, 94, 86, 91, 95, 97, 88, 85, 76, 68) kurtosis(x,,3)
0.6393842

For further info

 

 

mode

Finds the most frequently occuring element.


def mode(y:Iterable)->tuple[list[Real], int]:
"""
Computes mode

Returns the most frequently occuring number(s) and 
the number of times it occurs.
"""

 

Examples


import scisuit.stats as stat
import numpy as np

t=[1, 3.1, 5, 7, 9, 3.1, 5, 7, 3.1, 6]
result = stat.mode(t)
print(result)
#([3.1], 3)

arr = np.array([1, 3, 5, 5, 7, 9, 3, 5, 7, 3, 6])
result = stat.mode(arr)
print(result)
#([3, 5], 3)

 

 

rolling

Computes descriptive statistics of a rolling window data.


class rolling:
     
	def __init__(self, 
		x:Iterable, 
		y:Iterable, 
		period:int = 2):
			

	def mean(self)->list[Real]:
	"""computes mean"""

	def median(self)->list[Real]:
	"""computes median"""

	def min(self)->list[Real]:
	"""computes minimum"""

	def max(self)->list[Real]:
	"""computes maximum"""

 

Example


import scisuit.stats as stat
import numpy as np

x = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
y = [0.178953, 0.831553, 0.278056, 0.464573, 0.322863, 0.717121, 0.731123, 0.532001, 0.468909, 0.812336]

c = stat.rolling(x,y, period = 3)

print(c.mean())
#[0.4295206, 0.52472733, 0.355164, 0.501519, 0.590369, 0.6600816, 0.5773443, 0.60441533]

print(c.median())
#[0.278056, 0.464573, 0.322863, 0.464573, 0.717121, 0.717121, 0.532001, 0.532001]

 

 

moveavg

Computes the moving average, equivalent to rolling.mean()


def moveavg(x, y, period=2)->tuple[list[Real], list[Real]]:
"""
Computes the moving average, similar to rolling.mean()
returns corresponding x and mean values
"""

 

Example


import scisuit.stats as stat

x = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
y = [0.178953, 0.831553, 0.278056, 0.464573, 0.322863, 0.717121, 0.731123, 0.532001, 0.468909, 0.812336]

print(stat.moveavg(x,y,2))
"""
(
   [2, 3, 4, 5, 6, 7, 8, 9, 10], 
   [0.505253, 0.5548045, 0.3713145, 0.393718, 0.519992, 0.72412199, 0.631562, 0.500455, 0.6406225]
)
"""

 

 

skew

Computes the adjusted Fisher-Pearson coefficient of skewness.


def skew(y:Iterable)->float:
"""
Computes the skewness of a distribution
"""

 

Examples


v = stat.rnorm(n=5000) 
sk_norm = stat.skew(v)
print(sk_norm)
#0.025650
	
x = stat.rchisq(n=500, df=1)
sk_chi = stat.skew(x)
print(sk_chi)
#1.9309