| 323 | |
| 324 | @derived_from(scipy.stats) |
| 325 | def kurtosistest(a, axis=0, nan_policy="propagate"): |
| 326 | if nan_policy != "propagate": |
| 327 | raise NotImplementedError( |
| 328 | "`nan_policy` other than 'propagate' have not been implemented." |
| 329 | ) |
| 330 | |
| 331 | n = float(a.shape[axis]) |
| 332 | b2 = kurtosis(a, axis, fisher=False) |
| 333 | |
| 334 | E = 3.0 * (n - 1) / (n + 1) |
| 335 | varb2 = ( |
| 336 | 24.0 * n * (n - 2) * (n - 3) / ((n + 1) * (n + 1.0) * (n + 3) * (n + 5)) |
| 337 | ) # [1]_ Eq. 1 |
| 338 | x = (b2 - E) / np.sqrt(varb2) # [1]_ Eq. 4 |
| 339 | # [1]_ Eq. 2: |
| 340 | sqrtbeta1 = ( |
| 341 | 6.0 |
| 342 | * (n * n - 5 * n + 2) |
| 343 | / ((n + 7) * (n + 9)) |
| 344 | * np.sqrt((6.0 * (n + 3) * (n + 5)) / (n * (n - 2) * (n - 3))) |
| 345 | ) |
| 346 | # [1]_ Eq. 3: |
| 347 | A = 6.0 + 8.0 / sqrtbeta1 * (2.0 / sqrtbeta1 + np.sqrt(1 + 4.0 / (sqrtbeta1**2))) |
| 348 | term1 = 1 - 2 / (9.0 * A) |
| 349 | denom = 1 + x * np.sqrt(2 / (A - 4.0)) |
| 350 | denom = np.where(denom < 0, 99, denom) |
| 351 | term2 = np.where(denom < 0, term1, np.power((1 - 2.0 / A) / denom, 1 / 3.0)) |
| 352 | Z = (term1 - term2) / np.sqrt(2 / (9.0 * A)) # [1]_ Eq. 5 |
| 353 | Z = np.where(denom == 99, 0, Z) |
| 354 | if Z.ndim == 0: |
| 355 | Z = Z[()] |
| 356 | |
| 357 | # zprob uses upper tail, so Z needs to be positive |
| 358 | return delayed(KurtosistestResult, nout=2)(Z, 2 * distributions.norm.sf(np.abs(Z))) |
| 359 | |
| 360 | |
| 361 | @derived_from(scipy.stats) |