Skip to content

Commit

Permalink
Merge pull request scipy#14182 from WarrenWeckesser/ppccplot-rng-seed
Browse files Browse the repository at this point in the history
MAINT: stats: Update ppcc_plot and ppcc_max docstring.
  • Loading branch information
tylerjereddy authored Jun 5, 2021
2 parents f89d399 + 4c78eb0 commit f856e3e
Showing 1 changed file with 43 additions and 40 deletions.
83 changes: 43 additions & 40 deletions scipy/stats/morestats.py
Original file line number Diff line number Diff line change
Expand Up @@ -630,11 +630,11 @@ def probplot(x, sparams=(), dist='norm', fit=True, plot=None, rvalue=False):
def ppcc_max(x, brack=(0.0, 1.0), dist='tukeylambda'):
"""Calculate the shape parameter that maximizes the PPCC.
The probability plot correlation coefficient (PPCC) plot can be used to
determine the optimal shape parameter for a one-parameter family of
distributions. ppcc_max returns the shape parameter that would maximize the
probability plot correlation coefficient for the given data to a
one-parameter family of distributions.
The probability plot correlation coefficient (PPCC) plot can be used
to determine the optimal shape parameter for a one-parameter family
of distributions. ``ppcc_max`` returns the shape parameter that would
maximize the probability plot correlation coefficient for the given
data to a one-parameter family of distributions.
Parameters
----------
Expand Down Expand Up @@ -667,37 +667,33 @@ def ppcc_max(x, brack=(0.0, 1.0), dist='tukeylambda'):
References
----------
.. [1] J.J. Filliben, "The Probability Plot Correlation Coefficient Test for
Normality", Technometrics, Vol. 17, pp. 111-117, 1975.
.. [2] https://www.itl.nist.gov/div898/handbook/eda/section3/ppccplot.htm
.. [1] J.J. Filliben, "The Probability Plot Correlation Coefficient Test
for Normality", Technometrics, Vol. 17, pp. 111-117, 1975.
.. [2] Engineering Statistics Handbook, NIST/SEMATEC,
https://www.itl.nist.gov/div898/handbook/eda/section3/ppccplot.htm
Examples
--------
First we generate some random data from a Tukey-Lambda distribution,
with shape parameter -0.7:
First we generate some random data from a Weibull distribution
with shape parameter 2.5:
>>> from scipy import stats
>>> x = stats.tukeylambda.rvs(-0.7, loc=2, scale=0.5, size=10000,
... random_state=1234567) + 1e4
Now we explore this data with a PPCC plot as well as the related
probability plot and Box-Cox normplot. A red line is drawn where we
expect the PPCC value to be maximal (at the shape parameter -0.7 used
above):
>>> import matplotlib.pyplot as plt
>>> fig = plt.figure(figsize=(8, 6))
>>> ax = fig.add_subplot(111)
>>> res = stats.ppcc_plot(x, -5, 5, plot=ax)
>>> rng = np.random.default_rng()
>>> c = 2.5
>>> x = stats.weibull_min.rvs(c, scale=4, size=2000, random_state=rng)
Generate the PPCC plot for this data with the Weibull distribution.
We calculate the value where the shape should reach its maximum and a red
line is drawn there. The line should coincide with the highest point in the
ppcc_plot.
>>> fig, ax = plt.subplots(figsize=(8, 6))
>>> res = stats.ppcc_plot(x, c/2, 2*c, dist='weibull_min', plot=ax)
>>> max = stats.ppcc_max(x)
>>> ax.vlines(max, 0, 1, colors='r', label='Expected shape value')
We calculate the value where the shape should reach its maximum and a
red line is drawn there. The line should coincide with the highest
point in the PPCC graph.
>>> cmax = stats.ppcc_max(x, brack=(c/2, 2*c), dist='weibull_min')
>>> ax.axvline(cmax, color='r')
>>> plt.show()
"""
Expand Down Expand Up @@ -770,28 +766,35 @@ def ppcc_plot(x, a, b, dist='tukeylambda', plot=None, N=80):
Examples
--------
First we generate some random data from a Tukey-Lambda distribution,
with shape parameter -0.7:
First we generate some random data from a Weibull distribution
with shape parameter 2.5, and plot the histogram of the data:
>>> from scipy import stats
>>> import matplotlib.pyplot as plt
>>> rng = np.random.default_rng()
>>> x = stats.tukeylambda.rvs(-0.7, loc=2, scale=0.5,
... size=10000, random_state=rng) + 1e4
>>> c = 2.5
>>> x = stats.weibull_min.rvs(c, scale=4, size=2000, random_state=rng)
Take a look at the histogram of the data.
>>> fig1, ax = plt.subplots(figsize=(9, 4))
>>> ax.hist(x, bins=50)
>>> ax.set_title('Histogram of x')
>>> plt.show()
Now we explore this data with a PPCC plot as well as the related
probability plot and Box-Cox normplot. A red line is drawn where we
expect the PPCC value to be maximal (at the shape parameter -0.7 used
above):
expect the PPCC value to be maximal (at the shape parameter ``c``
used above):
>>> fig = plt.figure(figsize=(12, 4))
>>> ax1 = fig.add_subplot(131)
>>> ax2 = fig.add_subplot(132)
>>> ax3 = fig.add_subplot(133)
>>> fig2 = plt.figure(figsize=(12, 4))
>>> ax1 = fig2.add_subplot(1, 3, 1)
>>> ax2 = fig2.add_subplot(1, 3, 2)
>>> ax3 = fig2.add_subplot(1, 3, 3)
>>> res = stats.probplot(x, plot=ax1)
>>> res = stats.boxcox_normplot(x, -5, 5, plot=ax2)
>>> res = stats.ppcc_plot(x, -5, 5, plot=ax3)
>>> ax3.vlines(-0.7, 0, 1, colors='r', label='Expected shape value')
>>> res = stats.boxcox_normplot(x, -4, 4, plot=ax2)
>>> res = stats.ppcc_plot(x, c/2, 2*c, dist='weibull_min', plot=ax3)
>>> ax3.axvline(c, color='r')
>>> plt.show()
"""
Expand Down

0 comments on commit f856e3e

Please sign in to comment.