Skip to content
This repository was archived by the owner on Mar 19, 2021. It is now read-only.

Commit f83dfeb

Browse files
authored
Add stansummary method to class StanFit4Model
calls `pystan.misc.stansummary` function. Docstring updated to `fit.stansummary()`
1 parent d7b7db1 commit f83dfeb

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

pystan/stanfit4model.pyx

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,46 @@ cdef class StanFit4Model:
626626
def __getitem__(self, key):
627627
extr = self.extract(pars=(key,))
628628
return extr[key]
629+
630+
def stansummary(self, pars=None, probs=(0.025, 0.25, 0.5, 0.75, 0.975), digits_summary=2):
631+
"""
632+
Summary statistics table.
629633
634+
Parameters
635+
----------
636+
fit : StanFit4Model object
637+
pars : str or sequence of str, optional
638+
Parameter names. By default use all parameters
639+
probs : sequence of float, optional
640+
Quantiles. By default, (0.025, 0.25, 0.5, 0.75, 0.975)
641+
digits_summary : int, optional
642+
Number of significant digits. By default, 2
643+
Returns
644+
-------
645+
summary : string
646+
Table includes mean, se_mean, sd, probs_0, ..., probs_n, n_eff and Rhat.
647+
648+
Examples
649+
--------
650+
>>> model_code = 'parameters {real y;} model {y ~ normal(0,1);}'
651+
>>> m = StanModel(model_code=model_code, model_name="example_model")
652+
>>> fit = m.sampling()
653+
>>> print(fit.stansummary())
654+
Inference for Stan model: example_model.
655+
4 chains, each with iter=2000; warmup=1000; thin=1;
656+
post-warmup draws per chain=1000, total post-warmup draws=4000.
657+
658+
mean se_mean sd 2.5% 25% 50% 75% 97.5% n_eff Rhat
659+
y 0.01 0.03 1.0 -2.01 -0.68 0.02 0.72 1.97 1330 1.0
660+
lp__ -0.5 0.02 0.68 -2.44 -0.66 -0.24 -0.05-5.5e-4 1555 1.0
661+
662+
Samples were drawn using NUTS at Thu Aug 17 00:52:25 2017.
663+
For each parameter, n_eff is a crude measure of effective sample size,
664+
and Rhat is the potential scale reduction factor on split chains (at
665+
convergence, Rhat=1).
666+
"""
667+
return pystan.misc.stansummary(fit=self, pars=pars, probs=probs, digits_summary=digits_summary)
668+
630669
def summary(self, pars=None, probs=None):
631670
return pystan.misc._summary(self, pars, probs)
632671

0 commit comments

Comments
 (0)