6
6
Getting started
7
7
=================
8
8
9
- PyStan is the `Python <http://python.org >`_ interface for `Stan <http://mc-stan.org/ >`_.
9
+ PyStan is the `Python <http://python.org >`_ interface for
10
+ `Stan <http://mc-stan.org/ >`_.
10
11
11
12
Prerequisites
12
13
=============
@@ -108,8 +109,8 @@ which studied coaching effects from eight schools.
108
109
' y' : [28 , 8 , - 3 , 7 , - 1 , 1 , 18 , 12 ],
109
110
' sigma' : [15 , 10 , 16 , 11 , 9 , 11 , 10 , 18 ]}
110
111
111
- fit = pystan.stan (model_code = schools_code, data = schools_dat,
112
- iter = 1000 , chains = 4 )
112
+ sm = pystan.StanModel (model_code = schools_code)
113
+ fit = sm.sampling( data = schools_dat, iter = 1000 , chains = 4 )
113
114
114
115
In this model, we let ``theta `` be transformed parameters of ``mu `` and ``eta ``
115
116
instead of directly declaring theta as parameters. By parameterizing this way,
@@ -121,17 +122,16 @@ our working directory and use the following call to ``stan`` instead:
121
122
122
123
.. code-block :: python
123
124
124
- fit1 = pystan.stan(file = ' 8schools.stan' , data = schools_dat, iter = 1000 , chains = 4 )
125
+ sm = pystan.StanModel(file = ' 8schools.stan' )
126
+ fit = sm.sampling(data = schools_dat, iter = 1000 , chains = 4 )
125
127
126
- Once a model is fitted, we can use the fitted result as an input to the model
127
- with other data or settings. This saves us time compiling the C++ code for the
128
- model. By specifying the parameter ``fit `` for the ``stan `` function, we can fit
129
- the model again. For example, if we want to sample more iterations, we proceed
130
- as follows:
128
+ Once a model is compiled, we can use the StanModel object multiple times.
129
+ This saves us time compiling the C++ code for the model. For example, if we
130
+ want to sample more iterations, we proceed as follows:
131
131
132
132
.. code-block :: python
133
133
134
- fit2 = pystan.stan( fit = fit1, data = schools_dat, iter = 10000 , chains = 4 )
134
+ fit2 = sm.sampling( data = schools_dat, iter = 10000 , chains = 4 )
135
135
136
136
The object ``fit ``, returned from function ``stan `` stores samples from the
137
137
posterior distribution. The ``fit `` object has a number of methods, including
@@ -154,7 +154,8 @@ parameters of interest, or just an array.
154
154
155
155
print (fit)
156
156
157
- If `matplotlib <http://matplotlib.org/ >`_ and `scipy <http://http://www.scipy.org/ >`_ are installed, a visual summary may
157
+ If `matplotlib <http://matplotlib.org/ >`_ and
158
+ `scipy <http://http://www.scipy.org/ >`_ are installed, a visual summary may
158
159
also be displayed using the ``plot() `` method.
159
160
160
161
.. code-block :: python
0 commit comments