Coverage for pybreakpoints/stats.py : 87%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
""" Commonly used, basic statistics functions """
""" Calculate Median-Absolute-Deviation (MAD) of x
Parameters ---------- x : array-like 1D array c : float Scale factor to get to ~standard normal (default: 1.4826) (i.e. 1 / 0.75iCDF ~= 1.4826)
Returns ------- float MAD 'robust' variance estimate
Reference --------- http://en.wikipedia.org/wiki/Median_absolute_deviation """
# Numba-compatible (if we have it) var/std with ddof != 0 """ Calculate variance for an array
Uses Welford's algorithm[1] for online variance calculation.
Parameters ---------- x : array-like The data ddof : int Degrees of freedom
References ---------- .. [1] https://en.wikipedia.org/wiki/Algorithms_for_calculating_variance#Online_algorithm """
# ONLY USE THESE IF WE HAVE NUMBA else: var = np.var std = np.std
# Model criteria def rmse(resid): """ Calculate RMSE from either y and yhat or residuals
Parameters ---------- resid : np.ndarray Residuals
Returns ------- float Root mean squared error """ return ((resid ** 2).sum() / y.size) ** 0.5
# INFORMATION CRITERION """ Akaike Information Criterion
Parameters ---------- loglik : float Log likelihood k : int Parameters estimated
Returns ------- float AIC, the smaller the better """ return -2 * loglik + 2 * k
""" Bayesian Information Criterion
Parameters ---------- loglik : float Log likelihood k : int Parameters estimated n : int Number of observations
Parameters ---------- float BIC, the smaller the better """ |