1

# pvalues and weights must be of the same size.

Package:
scipy
8546
Exception Class:
ValueError

## Raise code

``````    elif method == 'tippett':
statistic = np.min(pvalues)
pval = distributions.beta.sf(statistic, 1, len(pvalues))
elif method == 'stouffer':
if weights is None:
weights = np.ones_like(pvalues)
elif len(weights) != len(pvalues):
raise ValueError("pvalues and weights must be of the same size.")

weights = np.asarray(weights)
if weights.ndim != 1:
raise ValueError("weights is not 1-D")

Zi = distributions.norm.isf(pvalues)
statistic = np.dot(weights, Zi) / np.linalg.norm(weights)``````
😲  Walkingbet is Android app that pays you real bitcoins for a walking. Withdrawable real money bonus is available now, hurry up! 🚶

## Ways to fix

2

This happens when `pvalues` and `weights `vary in size. To be specific, this error is raised only when the `method` is

`'stouffer'`

## Reproducing the error:

• Install Scipy
\$ pip install scipy

```from scipy import stats
xsq, p = stats.combine_pvalues([.01, .2, .3], method ='stouffer',weights=[0.034,0.2,0.4,0.5,0.5])
print(xsq,p)
```

```---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-48-21ed99c7f630> in <module>()  1 from scipy import stats ----> 2 xsq, p = stats.combine_pvalues([.01, .2, .3], method ='stouffer',weights=[0.034,0.2,0.4,0.5,0.5])  3 print(xsq,p)
/usr/local/lib/python3.7/dist-packages/scipy/stats/stats.py in combine_pvalues(pvalues, method, weights)  6910 weights = np.ones_like(pvalues)  6911 elif len(weights) != len(pvalues): -> 6912 raise ValueError("pvalues and weights must be of the same size.")  6913   6914 weights = np.asarray(weights)
ValueError: pvalues and weights must be of the same size.
```

## Fixed:

```from scipy import stats
xsq, p = stats.combine_pvalues([.01, .2, .3], method ='stouffer',weights=[0.4,0.5,0.5])
print(xsq,p)
```

```1.9861427807087246 0.0235087360896722
```

Sep 15, 2021
kellemnegasi 31.6k