boxcox_llf(lmb, data)
The Box-Cox log-likelihood function is defined here as
llf = (\lambda - 1) \sum_i(\log(x_i)) - N/2 \log(\sum_i (y_i - \bar{y})^2 / N),
where y
is the Box-Cox transformed input data x
.
Parameter for Box-Cox transformation. See boxcox for details.
Data to calculate Box-Cox log-likelihood for. If data is multi-dimensional, the log-likelihood is calculated along the first axis.
The boxcox log-likelihood function.
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()
The following pages refer to to this document either explicitly or contain code examples using this.
scipy.stats._morestats:boxcox
scipy.stats._morestats:boxcox_normmax
scipy.stats._morestats:boxcox_normplot
Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.
Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)
SVG is more flexible but power hungry; and does not scale well to 50 + nodes.
All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them