bundles / scipy 1.17.1 / scipy / stats / _morestats / boxcox_llf
function
scipy.stats._morestats:boxcox_llf
source: /scipy/stats/_morestats.py :893
Signature
def boxcox_llf ( lmb , data , * , axis = 0 , keepdims = False , nan_policy = propagate ) Summary
The boxcox log-likelihood function.
Parameters
lmb: scalarParameter for Box-Cox transformation. See
boxcoxfor details.data: array_likeData to calculate Box-Cox log-likelihood for. If
datais multi-dimensional, the log-likelihood is calculated along the first axis.axis: int, default: 0If an int, the axis of the input along which to compute the statistic. The statistic of each axis-slice (e.g. row) of the input will appear in a corresponding element of the output. If
None, the input will be raveled before computing the statistic.nan_policy: {'propagate', 'omit', 'raise'Defines how to handle input NaNs.
propagate: if a NaN is present in the axis slice (e.g. row) along which the statistic is computed, the corresponding entry of the output will be NaN.omit: NaNs will be omitted when performing the calculation. If insufficient data remains in the axis slice along which the statistic is computed, the corresponding entry of the output will be NaN.raise: if a NaN is present, aValueErrorwill be raised.
keepdims: bool, default: FalseIf this is set to True, the axes which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the input array.
Returns
llf: float or ndarrayBox-Cox log-likelihood of
datagivenlmb. A float for 1-Ddata, an array otherwise.
Notes
The Box-Cox log-likelihood function is defined here as
where is the number of data points data and is the Box-Cox transformed input data. This corresponds to the profile log-likelihood of the original data with some constant terms dropped.
Array API Standard Support
boxcox_llf 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
import numpy as np from scipy import stats import matplotlib.pyplot as plt from mpl_toolkits.axes_grid1.inset_locator import inset_axes✓
rng = np.random.default_rng() x = stats.loggamma.rvs(5, loc=10, size=1000, random_state=rng) lmbdas = np.linspace(-2, 10) llf = np.zeros(lmbdas.shape, dtype=float) for ii, lmbda in enumerate(lmbdas): llf[ii] = stats.boxcox_llf(lmbda, x)✓
x_most_normal, lmbda_optimal = stats.boxcox(x)
✓fig = plt.figure() ax = fig.add_subplot(111)✓
ax.plot(lmbdas, llf, 'b.-') ax.axhline(stats.boxcox_llf(lmbda_optimal, x), color='r') ax.set_xlabel('lmbda parameter') ax.set_ylabel('Box-Cox log-likelihood')✗
locs = [3, 10, 4] # 'lower left', 'center', 'lower right'
✓for lmbda, loc in zip([-1, lmbda_optimal, 9], locs): xt = stats.boxcox(x, lmbda=lmbda) (osm, osr), (slope, intercept, r_sq) = stats.probplot(xt) ax_inset = inset_axes(ax, width="20%", height="20%", loc=loc) ax_inset.plot(osm, osr, 'c.', osm, slope*osm + intercept, 'k-') ax_inset.set_xticklabels([]) ax_inset.set_yticklabels([]) ax_inset.set_title(r'$\lambda=%1.2f$' % lmbda)✗
plt.show()
✓
See also
Aliases
-
scipy.stats.boxcox_llf