In [1]:
import pymc as pm, pandas as pd, seaborn
%matplotlib inline

In [4]:
import io

df = pd.read_csv(io.StringIO("""ID,GotSick,Salad,Sandwich,Water
1,0,0,1,0
2,1,1,0,1
3,0,1,0,0
100,1,1,0,1"""))

In [5]:
x1 = df.Salad
x2 = df.Sandwich
x3 = df.Water

### hyperpriors
tau = pm.Gamma('tau', 1.e-3, 1.e-3, value=10.)
sigma = pm.Lambda('sigma', lambda tau=tau: tau**-.5)

### parameters
# fixed effects
beta0 =  pm.Normal('beta0',  0., 1e-6, value=0.)
betaSalad =  pm.Normal('betaSalad',  0., 1e-6, value=0.) 
betaSandwich =  pm.Normal('betaSandwich',  0., 1e-6, value=0.)
betaWater = pm.Normal('betaWater',  0., 1e-6, value=0.)

# expected parameter
logit_p =  (beta0 + betaSalad*x1 + betaSandwich*x2 + betaWater*x3)

In [6]:
import pymc as pm

@pm.observed
def y(logit_p=logit_p, value=df.GotSick):
    return pm.bernoulli_like(df.GotSick, pm.invlogit(logit_p))

In [7]:
m = pm.MCMC(locals())

In [8]:
m.sample(100000, 50000, 50)


 [-----------------100%-----------------] 100000 of 100000 complete in 141.8 sec

In [10]:
pm.Matplot.plot(m)


Plotting betaSalad
Plotting betaSandwich
Plotting beta0
Plotting sigma
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-10-d24b139c4542> in <module>()
----> 1 pm.Matplot.plot(m)

/Users/blarsen/miniconda3/envs/python3/lib/python3.4/site-packages/pymc/Matplot.py in wrapper(pymc_obj, *args, **kwargs)
    339                     if args:
    340                         name = '%s_%s' % (args[0], variable.__name__)
--> 341                     f(data, name, *args, **kwargs)
    342             return
    343         except AttributeError:

/Users/blarsen/miniconda3/envs/python3/lib/python3.4/site-packages/pymc/Matplot.py in plot(data, name, format, suffix, path, common_scale, datarange, new, last, rows, num, fontmap, verbose)
    453             num=num * 2,
    454             last=last,
--> 455             fontmap=fontmap)
    456 
    457         if last:

/Users/blarsen/miniconda3/envs/python3/lib/python3.4/site-packages/pymc/Matplot.py in wrapper(pymc_obj, *args, **kwargs)
    375 
    376         # If others fail, assume that raw data is passed
--> 377         f(pymc_obj, *args, **kwargs)
    378 
    379     wrapper.__doc__ = f.__doc__

/Users/blarsen/miniconda3/envs/python3/lib/python3.4/site-packages/pymc/Matplot.py in histogram(data, name, bins, datarange, format, suffix, path, rows, columns, num, last, fontmap, verbose)
    576 
    577         # Generate histogram
--> 578         hist(data.tolist(), bins, histtype='stepfilled')
    579 
    580         xlim(datarange)

/Users/blarsen/miniconda3/envs/python3/lib/python3.4/site-packages/matplotlib/pyplot.py in hist(x, bins, range, normed, weights, cumulative, bottom, histtype, align, orientation, rwidth, log, color, label, stacked, hold, data, **kwargs)
   2956                       histtype=histtype, align=align, orientation=orientation,
   2957                       rwidth=rwidth, log=log, color=color, label=label,
-> 2958                       stacked=stacked, data=data, **kwargs)
   2959     finally:
   2960         ax.hold(washold)

/Users/blarsen/miniconda3/envs/python3/lib/python3.4/site-packages/matplotlib/__init__.py in inner(ax, *args, **kwargs)
   1810                     warnings.warn(msg % (label_namer, func.__name__),
   1811                                   RuntimeWarning, stacklevel=2)
-> 1812             return func(ax, *args, **kwargs)
   1813         pre_doc = inner.__doc__
   1814         if pre_doc is None:

/Users/blarsen/miniconda3/envs/python3/lib/python3.4/site-packages/matplotlib/axes/_axes.py in hist(self, x, bins, range, normed, weights, cumulative, bottom, histtype, align, orientation, rwidth, log, color, label, stacked, **kwargs)
   6008             # this will automatically overwrite bins,
   6009             # so that each histogram uses the same bins
-> 6010             m, bins = np.histogram(x[i], bins, weights=w[i], **hist_kwargs)
   6011             m = m.astype(float)  # causes problems later if it's an int
   6012             if mlast is None:

/Users/blarsen/miniconda3/envs/python3/lib/python3.4/site-packages/numpy/lib/function_base.py in histogram(a, bins, range, normed, weights, density)
    503     if not np.all(np.isfinite([mn, mx])):
    504         raise ValueError(
--> 505             'range parameter must be finite.')
    506     if mn == mx:
    507         mn -= 0.5

ValueError: range parameter must be finite.

In [ ]: