def combine_pvalues(pvalues, method='<STR_LIT>', weights=None):
pvalues = np.asarray(pvalues)<EOL>if pvalues.ndim != <NUM_LIT:1>:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if method == '<STR_LIT>':<EOL><INDENT>Xsq = -<NUM_LIT:2> * np.sum(np.log(pvalues))<EOL>pval = distributions.chi2.sf(Xsq, <NUM_LIT:2> * len(pvalues))<EOL>return (Xsq, pval)<EOL><DEDENT>elif method == '<STR_LIT>':<EOL><INDENT>if weights is None:<EOL><INDENT>weights = np.ones_like(pvalues)<EOL><DEDENT>elif len(weights) != len(pvalues):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>weights = np.asarray(weights)<EOL>if weights.ndim != <NUM_LIT:1>:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>Zi = distributions.norm.isf(pvalues)<EOL>Z = np.dot(weights, Zi) / np.linalg.norm(weights)<EOL>pval = distributions.norm.sf(Z)<EOL>return (Z, pval)<EOL><DEDENT>else:<EOL><INDENT>raise ValueError(<EOL>"<STR_LIT>", method)<EOL><DEDENT>
Methods for combining the p-values of independent tests bearing upon the
same hypothesis.

Parameters
----------
p: array_like, 1-D
    Array of p-values assumed to come from independent tests.
method: str
    Name of method to use to combine p-values. The following methods are
    available:
    - "fisher": Fisher's method (Fisher's combined probability test)
    - "stouffer": Stouffer's Z-score method
weights: array_like, 1-D, optional
    Optional array of weights used only for Stouffer's Z-score method.

Returns
-------
statistic: float
    The statistic calculated by the specified method:
    - "fisher": The chi-squared statistic
    - "stouffer": The Z-score
pval: float
    The combined p-value.

Notes
-----
Fisher's method (also known as Fisher's combined probability test) [1]_ uses
a chi-squared statistic to compute a combined p-value. The closely related
Stouffer's Z-score method [2]_ uses Z-scores rather than p-values. The
advantage of Stouffer's method is that it is straightforward to introduce
weights, which can make Stouffer's method more powerful than Fisher's
method when the p-values are from studies of different size [3]_ [4]_.

Fisher's method may be extended to combine p-values from dependent tests
[5]_. Extensions such as Brown's method and Kost's method are not currently
implemented.

References
----------
.. [1] https://en.wikipedia.org/wiki/Fisher%27s_method
.. [2] http://en.wikipedia.org/wiki/Fisher's_method#Relation_to_Stouffer.27s_Z-score_method
.. [3] Whitlock, M. C. "Combining probability from independent tests: the
       weighted Z-method is superior to Fisher's approach." Journal of
       Evolutionary Biology 18, no. 5 (2005): 1368-1373.
.. [4] Zaykin, Dmitri V. "Optimally weighted Z-test is a powerful method
       for combining probabilities in meta-analysis." Journal of
       Evolutionary Biology 24, no. 8 (2011): 1836-1841.
.. [5] https://en.wikipedia.org/wiki/Extensions_of_Fisher%27s_method