pymc-devs/pymc — Issue #92: The chain argument in stat is ignored
Author: isofer
Created: 2012-02-10 18:06:19+00:00
State: open

```
import pymc as pm

#creating a simple model
x = pm.Normal('x',0,1)
y = pm.Normal('y',x,1,value=randn(10), observed=True)
m = pm.MCMC([x,y])

#sampling once
m.sample(1000)

#the mean of the first chain
print "mean of the first chain"
print x.stats()['mean']
print

#sampling again
m.sample(1000)

print "direct computation of the mean of the second chain"
print mean(x.trace()[:])
print

#showing that the chain argument does not work
print "The following results should all look different from each other:"
print "suppose to be the mean of both chains: ", x.stats()['mean']
print "suppose to be the mean of the first chain: ", x.stats(chain=0)['mean']
print "suppose to be the mean of the second chain: ", x.stats(chain=1)['mean']
print "suppose to raise an error: ", x.stats(chain='sdfs')['mean']

print
print "suppose to be the mean of both chains: ", m.stats()['x']['mean']
print "suppose to be the mean of the first chains ", m.stats(chain=0)['x']['mean']
print "suppose to be the mean of the second chains ", m.stats(chain=1)['x']['mean']
print "suppose to raise an error: ", m.stats(chain='sdfs')['x']['mean']
```

results:

```
Sampling: 100% [000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000] Iterations: 1000
mean of the first chain
-0.158602456071

Sampling: 100% [000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000] Iterations: 1000
direct computation of the mean of the second chain
-0.132858643087

The following results should all look different from each other:
suppose to be the mean of both chains: -0.132858643087
suppose to be the mean of the first chains: -0.132858643087
suppose to be the mean of the second chains: -0.132858643087
suppose to raise an error: -0.132858643087

suppose to be the mean of both chains: -0.132858643087
suppose to be the mean of the first chains: -0.132858643087
suppose to be the mean of the second chains: -0.132858643087
suppose to raise an error: -0.132858643087
```