bundles / scipy latest / scipy / stats / _morestats / boxcox
function
scipy.stats._morestats:boxcox
source: /scipy/stats/_morestats.py :1072
Signature
def boxcox ( x , lmbda = None , alpha = None , optimizer = None ) Summary
Return a dataset transformed by a Box-Cox power transformation.
Parameters
x: ndarrayInput array to be transformed.
If
lmbdais not None, this is an alias ofscipy.special.boxcox. Returns nan ifx < 0; returns -inf ifx == 0 and lmbda < 0.If
lmbdais None, array must be positive, 1-dimensional, and non-constant.lmbda: scalar, optionalIf
lmbdais None (default), find the value oflmbdathat maximizes the log-likelihood function and return it as the second output argument.If
lmbdais not None, do the transformation for that value.alpha: float, optionalIf
lmbdais None andalphais not None (default), return the100 * (1-alpha)%confidence interval forlmbdaas the third output argument. Must be between 0.0 and 1.0.If
lmbdais not None,alphais ignored.optimizer: callable, optionalIf
lmbdais None,optimizeris the scalar optimizer used to find the value oflmbdathat minimizes the negative log-likelihood function.optimizeris a callable that accepts one argument:fun
fun
and returns an object, such as an instance of scipy.optimize.OptimizeResult, which holds the optimal value of
lmbdain an attributex.See the example in boxcox_normmax or the documentation of scipy.optimize.minimize_scalar for more information.
If
lmbdais not None,optimizeris ignored.
Returns
boxcox: ndarrayBox-Cox power transformed array.
maxlog: float, optionalIf the
lmbdaparameter is None, the second returned argument is thelmbdathat maximizes the log-likelihood function.(min_ci, max_ci): tuple of float, optionalIf
lmbdaparameter is None andalphais not None, this returned tuple of floats represents the minimum and maximum confidence limits givenalpha.
Notes
The Box-Cox transform is given by:
boxcox requires the input data to be positive. Sometimes a Box-Cox transformation provides a shift parameter to achieve this; boxcox does not. Such a shift parameter is equivalent to adding a positive constant to x before calling boxcox.
The confidence limits returned when alpha is provided give the interval where:
with the log-likelihood function and the chi-squared function.
Array API Standard Support
boxcox has experimental support for Python Array API Standard compatible backends in addition to NumPy. Please consider testing these features by setting an environment variable SCIPY_ARRAY_API=1 and providing CuPy, PyTorch, JAX, or Dask arrays as array arguments. The following combinations of backend and device (or other capability) are supported.
==================== ==================== ==================== Library CPU GPU ==================== ==================== ==================== NumPy ✅ n/a CuPy n/a ⛔ PyTorch ⛔ ⛔ JAX ⛔ ⛔ Dask ⛔ n/a ==================== ==================== ====================
See
dev-arrayapifor more information.
Examples
from scipy import stats import matplotlib.pyplot as plt✓
fig = plt.figure() ax1 = fig.add_subplot(211) x = stats.loggamma.rvs(5, size=500) + 5 prob = stats.probplot(x, dist=stats.norm, plot=ax1)✓
ax1.set_xlabel('') ax1.set_title('Probplot against normal distribution')✗
ax2 = fig.add_subplot(212) xt, _ = stats.boxcox(x) prob = stats.probplot(xt, dist=stats.norm, plot=ax2)✓
ax2.set_title('Probplot after Box-Cox transformation')
✗plt.show()
✓
See also
Aliases
-
scipy.stats.boxcox