Repository: stan-dev/cmdstanpy

Issue:
Provide sig_figs options to cmstanMCMC.summary
The summary method executes cmstan's stansummary, and it would be good to pass `sig_figs` option to the summary method. This would make unit testing easier for developers building interfaces to cmstanpy since they can make sure their computations (e.g. their own summary output) line up with what cmdstan does.

https://github.com/stan-dev/cmdstanpy/blob/develop/cmdstanpy/stanfit.py#L616




Discussion:

Patch:
diff --git a/cmdstanpy/cmdstan_args.py b/cmdstanpy/cmdstan_args.py
index 48a2a34..0718cab 100644
--- a/cmdstanpy/cmdstan_args.py
+++ b/cmdstanpy/cmdstan_args.py
@@ -9,7 +9,12 @@ from numbers import Integral, Real
 from typing import List, Union
 from numpy.random import RandomState
 
-from cmdstanpy.utils import read_metric, get_logger
+from cmdstanpy.utils import (
+    read_metric,
+    get_logger,
+    cmdstan_path,
+    cmdstan_version_at,
+)
 
 
 class Method(Enum):
@@ -539,6 +544,7 @@ class CmdStanArgs:
         seed: Union[int, List[int]] = None,
         inits: Union[int, float, str, List[str]] = None,
         output_dir: str = None,
+        sig_figs: str = None,
         save_diagnostics: bool = False,
         refresh: str = None,
         logger: logging.Logger = None,
@@ -551,6 +557,7 @@ class CmdStanArgs:
         self.seed = seed
         self.inits = inits
         self.output_dir = output_dir
+        self.sig_figs = sig_figs
         self.save_diagnostics = save_diagnostics
         self.refresh = refresh
         self.method_args = method_args
@@ -619,6 +626,25 @@ class CmdStanArgs:
                     ' cannot write to dir: {}'.format(self.output_dir)
                 ) from exc
 
+        if self.sig_figs is not None:
+            if (
+                not isinstance(self.sig_figs, int)
+                or self.sig_figs < 1
+                or self.sig_figs > 18
+            ):
+                raise ValueError(
+                    'sig_figs must be an integer between 1 and 18,'
+                    ' found {}'.format(self.sig_figs)
+                )
+            if not cmdstan_version_at(2, 25):
+                self.sig_figs = None
+                self._logger.warning(
+                    'arg sig_figs not valid, CmdStan version must be 2.25 '
+                    'or higher, using verson %s in directory %s',
+                    os.path.basename(cmdstan_path()),
+                    os.path.dirname(cmdstan_path()),
+                )
+
         if self.seed is None:
             rng = RandomState()
             self.seed = rng.randint(1, 99999 + 1)
@@ -738,5 +764,7 @@ class CmdStanArgs:
             cmd.append('diagnostic_file={}'.format(diagnostic_file))
         if self.refresh is not None:
             cmd.append('refresh={}'.format(self.refresh))
+        if self.sig_figs is not None:
+            cmd.append('sig_figs={}'.format(self.sig_figs))
         cmd = self.method_args.compose(idx, cmd)
         return cmd
diff --git a/cmdstanpy/install_cmdstan.py b/cmdstanpy/install_cmdstan.py
index 03c0895..a6bd1d1 100644
--- a/cmdstanpy/install_cmdstan.py
+++ b/cmdstanpy/install_cmdstan.py
@@ -198,6 +198,8 @@ def latest_version():
 
 def retrieve_version(version: str):
     """Download specified CmdStan version."""
+    if version is None or version == '':
+        raise ValueError('Argument "version" unspecified.')
     print('Downloading CmdStan version {}'.format(version))
     url = (
         'https://github.com/stan-dev/cmdstan/releases/download/'
diff --git a/cmdstanpy/model.py b/cmdstanpy/model.py
index 5dcd2be..a0f22e0 100644
--- a/cmdstanpy/model.py
+++ b/cmdstanpy/model.py
@@ -324,6 +324,7 @@ class CmdStanModel:
         seed: int = None,
         inits: Union[Dict, float, str] = None,
         output_dir: str = None,
+        sig_figs: int = None,
         algorithm: str = None,
         init_alpha: float = None,
         iter: int = None,
@@ -377,6 +378,11 @@ class CmdStanModel:
             files are written. If unspecified, output files will be written
             to a temporary directory which is deleted upon session exit.
 
+        :param sig_figs: Numerical precision used for output CSV and text files.
+            Must be an integer between 1 and 18.  If unspecified, the default
+            precision for the system file I/O is used; the usual value is 6.
+            Introduced in CmdStan-2.25.
+
         :param algorithm: Algorithm to use. One of: 'BFGS', 'LBFGS', 'Newton'
 
         :param init_alpha: Line search step size for first iteration
@@ -398,6 +404,7 @@ class CmdStanModel:
                 seed=seed,
                 inits=_inits,
                 output_dir=output_dir,
+                sig_figs=sig_figs,
                 save_diagnostics=False,
                 method_args=optimize_args,
             )
@@ -412,6 +419,7 @@ class CmdStanModel:
         mle = CmdStanMLE(runset)
         return mle
 
+    # pylint: disable=too-many-arguments
     def sample(
         self,
         data: Union[Dict, str] = None,
@@ -435,6 +443,7 @@ class CmdStanModel:
         adapt_step_size: int = None,
         fixed_param: bool = False,
         output_dir: str = None,
+        sig_figs: int = None,
         save_diagnostics: bool = False,
         show_progress: Union[bool, str] = False,
         validate_csv: bool = True,
@@ -573,6 +582,11 @@ class CmdStanModel:
             files are written. If unspecified, output files will be written
             to a temporary directory which is deleted upon session exit.
 
+        :param sig_figs: Numerical precision used for output CSV and text files.
+            Must be an integer between 1 and 18.  If unspecified, the default
+            precision for the system file I/O is used; the usual value is 6.
+            Introduced in CmdStan-2.25.
+
         :param save_diagnostics: Whether or not to save diagnostics. If True,
             csv output files are written to an output file with filename
             template '<model_name>-<YYYYMMDDHHMM>-diagnostic-<chain_id>',
@@ -693,6 +707,7 @@ class CmdStanModel:
                 seed=seed,
                 inits=_inits,
                 output_dir=output_dir,
+                sig_figs=sig_figs,
                 save_diagnostics=save_diagnostics,
                 method_args=sampler_args,
                 refresh=refresh,
@@ -764,6 +779,7 @@ class CmdStanModel:
         mcmc_sample: Union[CmdStanMCMC, List[str]] = None,
         seed: int = None,
         gq_output_dir: str = None,
+        sig_figs: int = None,
     ) -> CmdStanGQ:
         """
         Run CmdStan's generate_quantities method which runs the generated
@@ -807,6 +823,11 @@ class CmdStanModel:
             files are saved.  If unspecified, files will be written to a
             temporary directory which is deleted upon session exit.
 
+        :param sig_figs: Numerical precision used for output CSV and text files.
+            Must be an integer between 1 and 18.  If unspecified, the default
+            precision for the system file I/O is used; the usual value is 6.
+            Introduced in CmdStan-2.25.
+
         :return: CmdStanGQ object
         """
         sample_csv_files = []
@@ -881,6 +902,7 @@ class CmdStanModel:
                 data=_data,
                 seed=seed,
                 output_dir=gq_output_dir,
+                sig_figs=sig_figs,
                 method_args=generate_quantities_args,
             )
             runset = RunSet(args=args, chains=chains, chain_ids=chain_ids)
@@ -905,6 +927,7 @@ class CmdStanModel:
         seed: int = None,
         inits: float = None,
         output_dir: str = None,
+        sig_figs: int = None,
         save_diagnostics: bool = False,
         algorithm: str = None,
         iter: int = None,
@@ -959,6 +982,11 @@ class CmdStanModel:
             files are written. If unspecified, output files will be written
             to a temporary directory which is deleted upon session exit.
 
+        :param sig_figs: Numerical precision used for output CSV and text files.
+            Must be an integer between 1 and 18.  If unspecified, the default
+            precision for the system file I/O is used; the usual value is 6.
+            Introduced in CmdStan-2.25.
+
         :param save_diagnostics: Whether or not to save diagnostics. If True,
             csv output files are written to an output file with filename
             template '<model_name>-<YYYYMMDDHHMM>-diagnostic-<chain_id>',
@@ -1012,6 +1040,7 @@ class CmdStanModel:
                 seed=seed,
                 inits=_inits,
                 output_dir=output_dir,
+                sig_figs=sig_figs,
                 save_diagnostics=save_diagnostics,
                 method_args=variational_args,
             )
diff --git a/cmdstanpy/stanfit.py b/cmdstanpy/stanfit.py
index 8ec51f3..a710871 100644
--- a/cmdstanpy/stanfit.py
+++ b/cmdstanpy/stanfit.py
@@ -321,6 +321,7 @@ class CmdStanMCMC:
         self._iter_warmup = runset._args.method_args.iter_warmup
         self._save_warmup = runset._args.method_args.save_warmup
         self._thin = runset._args.method_args.thin
+        self._sig_figs = runset._args.sig_figs
         # parse the remainder from csv files
         self._draws_sampling = None
         self._draws_warmup = None
@@ -636,17 +637,34 @@ class CmdStanMCMC:
                     xs = line.split(',')
                     self._draws[i, chain, :] = [float(x) for x in xs]
 
-    def summary(self, percentiles: List[int] = None) -> pd.DataFrame:
+    def summary(
+        self, percentiles: List[int] = None, sig_figs: int = None
+    ) -> pd.DataFrame:
         """
-        Run cmdstan/bin/stansummary over all output csv files.
-        Echo stansummary stdout/stderr to console.
-        Assemble csv tempfile contents into pandasDataFrame.
+        Run cmdstan/bin/stansummary over all output csv files, assemble
+        summary into DataFrame object; first row contains summary statistics
+        for total joint log probability `lp__`, remaining rows contain summary
+        statistics for all parameters, transformed parameters, and generated
+        quantities variables listed in the order in which they were declared
+        in the Stan program.
 
         :param percentiles: Ordered non-empty list of percentiles to report.
             Must be integers from (1, 99), inclusive.
+
+        :param sig_figs: Number of significant figures to report.
+            Must be an integer between 1 and 18.  If unspecified, the default
+            precision for the system file I/O is used; the usual value is 6.
+            If precision above 6 is requested, sample must have been produced
+            by CmdStan version 2.25 or later and sampler output precision
+            must equal to or greater than the requested summary precision.
+
+        :return: pandas.DataFrame
         """
+        n_cols = 7
         percentiles_str = '--percentiles=5,50,95'
-        if percentiles is not None:
+        if percentiles is None:
+            n_cols = 10
+        else:
             if len(percentiles) == 0:
                 raise ValueError(
                     'invalid percentiles argument, must be ordered'
@@ -661,9 +679,26 @@ class CmdStanMCMC:
                         ' non-empty list from (1, 99), inclusive.'
                     )
                 cur_pct = pct
+            n_cols += len(percentiles)
             percentiles_str = '='.join(
                 ['--percentiles', ','.join([str(x) for x in percentiles])]
             )
+        sig_figs_str = '--sig_figs=2'
+        if sig_figs is not None:
+            if not isinstance(sig_figs, int) or sig_figs < 1 or sig_figs > 18:
+                raise ValueError(
+                    'sig_figs must be an integer between 1 and 18,'
+                    ' found {}'.format(sig_figs)
+                )
+            csv_sig_figs = self._sig_figs or 6
+            if sig_figs > csv_sig_figs:
+                self._logger.warning(
+                    'Requesting %d significant digits of output, but CSV files'
+                    ' only have %d digits of precision.',
+                    sig_figs,
+                    csv_sig_figs,
+                )
+            sig_figs_str = '--sig_figs=' + str(sig_figs)
         cmd_path = os.path.join(
             cmdstan_path(), 'bin', 'stansummary' + EXTENSION
         )
@@ -676,6 +711,7 @@ class CmdStanMCMC:
         cmd = [
             cmd_path,
             percentiles_str,
+            sig_figs_str,
             '--csv_file={}'.format(tmp_csv_path),
         ] + self.runset.csv_files
         do_command(cmd, logger=self.runset._logger)
diff --git a/cmdstanpy/utils.py b/cmdstanpy/utils.py
index 0473692..7c54211 100644
--- a/cmdstanpy/utils.py
+++ b/cmdstanpy/utils.py
@@ -163,6 +163,47 @@ def cmdstan_path() -> str:
     return cmdstan
 
 
+def cmdstan_version_at(maj: int, min: int) -> bool:
+    """
+    Check that CmdStan version is at or above Maj.min version.
+    Parses version string out of CmdStan makefile in CmdStan path dir.
+
+    :param maj: Major version number
+    :param min: Minor version number
+
+    :return: True if version at or above, else False
+    """
+    path = cmdstan_path()
+    makefile = os.path.join(path, 'makefile')
+    if not os.path.exists(makefile):
+        raise ValueError(
+            'CmdStan installation {}: missing makefile'.format(path)
+        )
+    version = None
+    with open(makefile, 'r') as fd:
+        contents = fd.read()
+        start_idx = contents.find('CMDSTAN_VERSION := ') + len(
+            'CMDSTAN_VERSION := '
+        )
+        end_idx = contents.find('\n', start_idx)
+        version = contents[start_idx:end_idx]
+    if version is None:
+        raise ValueError(
+            'Cannot parse version from makefile: {}'.format(makefile)
+        )
+    splits = version.split('.')
+    if len(splits) < 2:
+        raise ValueError(
+            'Cannot parse version from makefile: {}'.format(makefile)
+        )
+    cur_maj = int(splits[0])
+    cur_min = int(splits[1])
+
+    if cur_maj > maj or (cur_maj == maj and cur_min >= min):
+        return True
+    return False
+
+
 def cxx_toolchain_path(version: str = None) -> Tuple[str]:
     """
     Validate, then activate C++ toolchain directory path.
@@ -783,8 +824,9 @@ def do_command(cmd: str, cwd: str = None, logger: logging.Logger = None) -> str:
     )
     stdout, stderr = proc.communicate()
     if proc.returncode:
+        msg = 'ERROR\n'
         if stderr:
-            msg = 'ERROR\n {} '.format(stderr.decode('utf-8').strip())
+            msg = '{}{} '.format(msg, stderr.decode('utf-8').strip())
         raise RuntimeError(msg)
     if stdout:
         return stdout.decode('utf-8').strip()


Test patch:
diff --git a/test/data/logistic_output_1.csv b/test/data/logistic_output_1.csv
new file mode 100644
index 0000000..86fee66
--- /dev/null
+++ b/test/data/logistic_output_1.csv
@@ -0,0 +1,149 @@
+# stan_version_major = 2
+# stan_version_minor = 25
+# stan_version_patch = 0
+# model = logistic_model
+# method = sample (Default)
+#   sample
+#     num_samples = 100
+#     num_warmup = 1000 (Default)
+#     save_warmup = 0 (Default)
+#     thin = 1 (Default)
+#     adapt
+#       engaged = 1 (Default)
+#       gamma = 0.050000000000000003 (Default)
+#       delta = 0.80000000000000004 (Default)
+#       kappa = 0.75 (Default)
+#       t0 = 10 (Default)
+#       init_buffer = 75 (Default)
+#       term_buffer = 50 (Default)
+#       window = 25 (Default)
+#     algorithm = hmc (Default)
+#       hmc
+#         engine = nuts (Default)
+#           nuts
+#             max_depth = 10 (Default)
+#         metric = diag_e (Default)
+#         metric_file =  (Default)
+#         stepsize = 1 (Default)
+#         stepsize_jitter = 0 (Default)
+# id = 1
+# data
+#   file = logistic.data.R
+# init = 2 (Default)
+# random
+#   seed = 12345
+# output
+#   file = logistic_output_1.csv
+#   diagnostic_file =  (Default)
+#   refresh = 100 (Default)
+#   sig_figs = 17
+lp__,accept_stat__,stepsize__,treedepth__,n_leapfrog__,divergent__,energy__,beta.1,beta.2
+# Adaptation terminated
+# Step size = 0.867157
+# Diagonal elements of inverse mass matrix:
+# 0.0574982, 0.0750306
+-65.512400286053165,1,0.86715739477627263,2,3,0,66.280862231993666,1.4566622706449768,-0.4342590644812877
+-65.719688477280485,0.99248257162124764,0.86715739477627263,2,3,0,65.922011060613997,1.5409448290528129,-0.59782097403029932
+-66.40561737120683,0.89110655416718165,0.86715739477627263,2,3,0,67.065460661908105,1.6553555759093581,-0.70768495323223835
+-65.447760329991169,0.95964309775491108,0.86715739477627263,2,3,0,66.76616089813561,1.4484211249775547,-0.45705274753495895
+-65.269287751820727,1,0.86715739477627263,2,3,0,65.414888807732254,1.2276454682215834,-0.5209264945592641
+-65.326028806530672,0.9813700859439215,0.86715739477627263,2,7,0,65.459221472467021,1.3165214555815385,-0.63225835202082414
+-66.753475871109359,0.63806723043285762,0.86715739477627263,1,3,0,67.567791765715086,1.4647285504902614,-0.14993065223050367
+-65.35474206942348,1,0.86715739477627263,2,3,0,66.470808798748209,1.2553895816226195,-0.61639706238026382
+-65.908109954553495,0.76235808575060859,0.86715739477627263,2,3,0,66.886929674510398,1.0521844658942083,-0.48387526299359274
+-65.265785302046012,1,0.86715739477627263,2,3,0,65.795677669044082,1.38906011432932,-0.49448645430087557
+-65.993415802732883,0.87085684871886271,0.86715739477627263,2,3,0,66.577300779775157,1.0361351256362747,-0.45781525102552556
+-65.606977373315729,1,0.86715739477627263,1,1,0,65.93511798177785,1.1111423494476524,-0.47256046632857684
+-65.986419117332488,0.72499319468783718,0.86715739477627263,2,7,0,67.800177795555996,1.5902882367600022,-0.65230661044303839
+-65.753810023267988,0.94597083505352142,0.86715739477627263,2,3,0,66.668585202671295,1.5492613344767816,-0.5929084910464365
+-65.5188370344937,1,0.86715739477627263,1,1,0,65.753102552009452,1.4906922522178609,-0.53575104274149044
+-65.544955501602388,1,0.86715739477627263,2,3,0,65.635430369354992,1.483769678158346,-0.63340332486418904
+-65.313222727141479,0.92339757972274239,0.86715739477627263,2,3,0,66.085486419797462,1.2642247632346051,-0.39207376037715019
+-66.128920011059591,0.86631266380193706,0.86715739477627263,2,3,0,66.363717114888459,1.3091258203667495,-0.83341004731653867
+-68.142933133517147,0.84538747258600855,0.86715739477627263,2,3,0,68.960737743700946,1.815596974894774,-0.95115415980548657
+-67.49661536929554,1,0.86715739477627263,1,1,0,68.218685615098067,1.7100687720150958,-0.94910791896127988
+-67.089380661209674,0.99465854812908139,0.86715739477627263,2,3,0,67.996767890476306,1.7620998211523273,-0.66922944522473182
+-66.590203924333309,1,0.86715739477627263,2,3,0,67.395961295179859,1.6784213471122733,-0.49006064020100026
+-67.797575682674008,0.72566094174448326,0.86715739477627263,2,3,0,71.513279853777647,1.0266528100118646,-0.033506121483892037
+-66.641128965433538,1,0.86715739477627263,2,3,0,68.728501857687135,1.1722948033254166,-0.84520544395993213
+-65.365854768791479,0.98255286138747333,0.86715739477627263,2,3,0,66.666307620133921,1.4404623865144499,-0.55900256217926014
+-65.873452892937323,0.87705225128108522,0.86715739477627263,2,3,0,66.126987987543473,1.4406893116019479,-0.29618408800719281
+-65.645266863010193,1,0.86715739477627263,2,3,0,65.855921871376779,1.1506115895924354,-0.61432992142001952
+-65.45429047664463,0.97588044325401502,0.86715739477627263,2,3,0,66.056483585555981,1.3918460578851,-0.3790157735935028
+-65.785714408307953,0.73299955295148267,0.86715739477627263,2,3,0,67.672680022572848,1.312028985717143,-0.76740204748904539
+-66.019343081458061,0.92629348968646141,0.86715739477627263,1,1,0,66.146291771557927,1.269569826927009,-0.79912271046582428
+-65.777800264835633,0.95958209829994234,0.86715739477627263,2,7,0,66.850367759741133,1.0750828320160459,-0.47224693602550882
+-65.484491032688609,0.91519201774663872,0.86715739477627263,2,7,0,66.304800231726631,1.4812581243129972,-0.56392251972517116
+-65.681364565028943,0.93842485216526816,0.86715739477627263,2,3,0,66.253134800356491,1.1280261120279407,-0.34600691894882091
+-65.588293698632796,0.92809815715654853,0.86715739477627263,2,3,0,66.431378746608104,1.1155712068057757,-0.473773937653794
+-66.081104352417356,0.92739335884364849,0.86715739477627263,2,7,0,66.324436180990872,1.5797089339549297,-0.73382677285917064
+-66.708199173807373,0.89342456228924361,0.86715739477627263,2,3,0,67.499474849165338,1.2197989381520631,-0.095061963529567417
+-66.708199173807373,0.50677347513114435,0.86715739477627263,1,1,0,68.701598718634386,1.2197989381520631,-0.095061963529567417
+-66.964895059254758,0.9612854683996207,0.86715739477627263,2,3,0,67.501747804902521,1.2624406696935915,-0.93990490861294418
+-66.716575723889036,1,0.86715739477627263,2,3,0,66.903238135184509,1.3892437787623937,-0.11662516805948361
+-67.257737757910789,0.94993191165174951,0.86715739477627263,2,3,0,67.783972893166833,0.93920887910973072,-0.67107145247798472
+-66.472565424618026,1,0.86715739477627263,2,3,0,67.133381965680613,1.5499151265973516,-0.27373060276144057
+-66.271430003934313,0.99741654718620809,0.86715739477627263,2,3,0,66.846569523034432,1.0507664307737801,-0.64641017007073787
+-65.361508202556621,1,0.86715739477627263,1,3,0,66.225896120137506,1.2974949890081742,-0.6422316155198855
+-66.724014708672343,0.74962388138024716,0.86715739477627263,2,3,0,67.590262893159206,0.94097164192886951,-0.36755456898270999
+-66.423455686672085,1,0.86715739477627263,1,1,0,66.894892742985363,1.0061709840415141,-0.29197755602424419
+-66.121768439433808,1,0.86715739477627263,2,3,0,66.495256290491582,1.0562883184485541,-0.29722532717376299
+-65.86603494611289,0.92163741741908323,0.86715739477627263,2,3,0,67.042149955971283,1.4259746823799231,-0.28626936361161648
+-65.263556632679226,1,0.86715739477627263,2,3,0,65.879912764266862,1.2255237559395873,-0.49014544724613696
+-65.25247489672401,0.82549084802665718,0.86715739477627263,2,3,0,66.244925834113772,1.364385045357591,-0.57983373888621959
+-70.644148309970177,0.49784624198691985,0.86715739477627263,2,3,0,70.760334033517026,2.08673471109707,-0.97724743941973424
+-68.060726263777852,1,0.86715739477627263,2,3,0,70.765092750121596,1.7084410322496906,-1.0494366316838157
+-67.383067016120506,1,0.86715739477627263,1,1,0,68.090010088148617,1.683265394253066,-0.95269995564347132
+-65.331073941060808,0.90008703495823905,0.86715739477627263,2,3,0,68.388924461922656,1.2301660337999838,-0.39937755180549439
+-65.314670068649875,0.99520290681278067,0.86715739477627263,2,3,0,65.407487281790992,1.4125786321325826,-0.57688582266858091
+-65.231173275926409,0.97791562438008361,0.86715739477627263,1,3,0,65.525541818590966,1.248807806229745,-0.47757449958173231
+-65.268997090978402,0.99061616554550136,0.86715739477627263,3,7,0,65.309523643951977,1.3842845905866552,-0.57493173963062749
+-67.061065515237942,0.7215994887988938,0.86715739477627263,1,3,0,67.750871940856882,1.7360378243616088,-0.78683972144932868
+-66.726971454994995,0.94589139346245832,0.86715739477627263,2,3,0,67.997782495547014,1.6756247593088232,-0.42379937989433913
+-65.943316666116374,1,0.86715739477627263,1,1,0,66.611812430647873,1.559448206035416,-0.44102712650097059
+-66.221260085157908,0.83013205253093714,0.86715739477627263,2,3,0,68.167681740179617,1.0008866438649227,-0.43684259896504701
+-65.403464895825095,1,0.86715739477627263,2,3,0,66.052954059182056,1.4351610381757118,-0.46070961729604909
+-65.364042010533595,0.95385985833998443,0.86715739477627263,2,3,0,65.79261483304856,1.2936749984004954,-0.36691957162293926
+-65.491145490890773,0.95001224687242936,0.86715739477627263,2,7,0,65.811231604961705,1.4722602259855051,-0.48397825938393063
+-65.723548514585374,0.88166201274202238,0.86715739477627263,2,3,0,66.460720472066086,1.322041905081337,-0.26719844004468529
+-65.537991105833811,0.96269090422565762,0.86715739477627263,2,7,0,66.218853338726106,1.4898166575893159,-0.49991152390342058
+-65.808087778306302,0.81517365270238418,0.86715739477627263,2,3,0,66.71891885013298,1.4163672338291968,-0.29297318545112738
+-65.57812191324966,0.93867229663374552,0.86715739477627263,2,3,0,66.322312066549202,1.491030752297811,-0.64157621974410284
+-65.57812191324966,0.54291294583423311,0.86715739477627263,1,3,0,68.190189322005011,1.491030752297811,-0.64157621974410284
+-65.628858520879888,0.89276650612275432,0.86715739477627263,2,3,0,66.215283133930939,1.4629607128923845,-0.39214757820786672
+-66.540124564366138,0.85004740488236175,0.86715739477627263,1,3,0,66.65613736854381,1.4567718247831485,-0.17828139258488362
+-65.598783278378079,1,0.86715739477627263,1,1,0,66.30372789073904,1.3743879288884064,-0.31977062155183533
+-65.508784422913465,1,0.86715739477627263,2,3,0,65.734802186926174,1.3888365054487422,-0.69895198076222376
+-65.856506692724295,0.87351401937981343,0.86715739477627263,2,3,0,66.391069843593982,1.2910301925029994,-0.23301832715347576
+-66.722409155623467,0.76977031299973275,0.86715739477627263,2,3,0,67.455479404293897,0.93660694913986164,-0.46251205759082104
+-65.203351312998706,0.9882921859891568,0.86715739477627263,2,3,0,66.781679600362196,1.3233318443102395,-0.47851836827895333
+-65.26828899977383,0.98555184592977729,0.86715739477627263,1,3,0,65.288617672917269,1.3913184952326347,-0.49709832612499338
+-65.350268652723216,0.95849171767126784,0.86715739477627263,2,3,0,65.543614686011395,1.2044236913488935,-0.55360174926331951
+-66.270169238406282,0.8752137236832489,0.86715739477627263,2,3,0,66.419596351993903,1.3480276562769422,-0.1699988042143257
+-65.52342336774619,0.90141551904652717,0.86715739477627263,2,3,0,66.643588991883789,1.1392097984574228,-0.52467713319868903
+-65.633293389844525,0.97130856933104015,0.86715739477627263,2,3,0,65.737865412269187,1.4456827050593353,-0.36880614816447371
+-65.402919371951526,1,0.86715739477627263,2,3,0,65.583234574297975,1.2682449724663285,-0.64470018592839984
+-65.439863994466876,0.99838706014587519,0.86715739477627263,2,3,0,65.548919727733661,1.3097208639279752,-0.34163644993894932
+-66.360517971937156,0.72381204949881617,0.86715739477627263,1,3,0,67.280393320306658,1.2348390659335782,-0.84083613490335929
+-65.269140955412382,1,0.86715739477627263,2,3,0,66.201180385424237,1.3879232902316168,-0.56890009415394693
+-67.727667002745079,0.53872866649941564,0.86715739477627263,1,3,0,68.17961379446875,1.7179222230313318,-0.26331273154812523
+-66.124488868698606,0.96038349537064105,0.86715739477627263,1,3,0,67.892754416101383,1.3983568747798647,-0.21564824637840407
+-66.242969799296148,0.98141527475607182,0.86715739477627263,2,3,0,66.502557932986278,1.1658443590027292,-0.77533770470910146
+-65.790408091814143,1,0.86715739477627263,1,1,0,66.246374081247879,1.1631299190893645,-0.67523143211938386
+-65.390741906047907,0.91692834177199278,0.86715739477627263,2,3,0,66.160774283818995,1.4476262192915363,-0.51161449300530148
+-65.402630535918718,0.93946218360192113,0.86715739477627263,2,3,0,65.929054552772683,1.2312908672399951,-0.61703995798929667
+-67.058548494256158,0.68472475000466249,0.86715739477627263,1,3,0,68.031440806852842,1.5037662929113553,-0.98654821421721695
+-65.761494178421614,0.97117173147756253,0.86715739477627263,2,3,0,68.015798622497627,1.4529757126981111,-0.33687415206272625
+-65.708598826584151,0.92040758870995287,0.86715739477627263,2,3,0,67.052356473823238,1.1178502602083882,-0.58265123309351841
+-65.452219994008331,1,0.86715739477627263,2,3,0,65.667286197215759,1.1629004708963848,-0.53768670544853525
+-65.634396647173688,0.95129692237054664,0.86715739477627263,1,1,0,65.676219258756703,1.1172610196667061,-0.5407296731100153
+-68.263817799073919,0.63069177751210637,0.86715739477627263,2,3,0,68.880464693750739,1.7764379672639627,-1.0258238895691656
+-66.975871867717458,1,0.86715739477627263,2,3,0,68.212449542233344,1.5987158286072445,-0.93941832115675439
+-67.0307535928645,0.89263179810165205,0.86715739477627263,2,3,0,68.223106596812556,1.2649366674576557,-0.94936835249643303
+-66.753891835478015,0.79938527706674378,0.86715739477627263,2,3,0,70.498183322259223,1.2801111795204292,-0.087170100850500642
+-67.071779755589432,0.9806825693302873,0.86715739477627263,2,3,0,67.951999750400887,0.95985614417916687,-0.207509045663615
+# 
+#  Elapsed Time: 0.066 seconds (Warm-up)
+#                0.006 seconds (Sampling)
+#                0.072 seconds (Total)
+# 
diff --git a/test/data/logistic_output_2.csv b/test/data/logistic_output_2.csv
new file mode 100644
index 0000000..d6b61b7
--- /dev/null
+++ b/test/data/logistic_output_2.csv
@@ -0,0 +1,149 @@
+# stan_version_major = 2
+# stan_version_minor = 25
+# stan_version_patch = 0
+# model = logistic_model
+# method = sample (Default)
+#   sample
+#     num_samples = 100
+#     num_warmup = 1000 (Default)
+#     save_warmup = 0 (Default)
+#     thin = 1 (Default)
+#     adapt
+#       engaged = 1 (Default)
+#       gamma = 0.050000000000000003 (Default)
+#       delta = 0.80000000000000004 (Default)
+#       kappa = 0.75 (Default)
+#       t0 = 10 (Default)
+#       init_buffer = 75 (Default)
+#       term_buffer = 50 (Default)
+#       window = 25 (Default)
+#     algorithm = hmc (Default)
+#       hmc
+#         engine = nuts (Default)
+#           nuts
+#             max_depth = 10 (Default)
+#         metric = diag_e (Default)
+#         metric_file =  (Default)
+#         stepsize = 1 (Default)
+#         stepsize_jitter = 0 (Default)
+# id = 2
+# data
+#   file = logistic.data.R
+# init = 2 (Default)
+# random
+#   seed = 12345
+# output
+#   file = logistic_output_2.csv
+#   diagnostic_file =  (Default)
+#   refresh = 100 (Default)
+#   sig_figs = 17
+lp__,accept_stat__,stepsize__,treedepth__,n_leapfrog__,divergent__,energy__,beta.1,beta.2
+# Adaptation terminated
+# Step size = 0.775091
+# Diagonal elements of inverse mass matrix:
+# 0.0430432, 0.0599893
+-65.56001059223486,1,0.77509112239497502,3,7,0,68.768937432252898,1.2858956826664345,-0.3021794932200953
+-65.469062471150579,0.97083614067955903,0.77509112239497502,2,3,0,66.112940073029009,1.1504010127406916,-0.50984220648066914
+-66.218164339034473,0.8904137571224503,0.77509112239497502,3,7,0,66.842917041386798,1.626258845935231,-0.50231662106405206
+-66.44611163232149,0.95694895834997762,0.77509112239497502,3,7,0,67.266438218884701,1.2995753769208616,-0.88199628616545955
+-65.607370772152848,0.85964428188266717,0.77509112239497502,1,3,0,68.156247269579239,1.4943984519964564,-0.45909232113162379
+-65.321904027713998,1,0.77509112239497502,2,3,0,65.623362211898581,1.2635442717552592,-0.60674862957310083
+-66.198851169141662,0.90936335069804497,0.77509112239497502,2,7,0,66.235677128452707,1.5471257616485408,-0.33369348280659256
+-68.470836108407013,0.843312574314112,0.77509112239497502,2,3,0,69.064624167038303,1.5970914253333564,-1.1488637406815776
+-67.530162794926852,0.97212020329943094,0.77509112239497502,2,3,0,69.294992720675722,1.7723733427626058,-0.86702689895995322
+-65.319536638528149,0.99095777064141544,0.77509112239497502,3,7,0,67.944278017446294,1.3507225957562992,-0.40626224050232007
+-65.217699237136841,0.97366799528803549,0.77509112239497502,2,3,0,65.587195188693556,1.3517284491487978,-0.54745559732991733
+-65.429541064822942,0.95615942734863968,0.77509112239497502,3,7,0,65.797603989184736,1.4142672174981421,-0.41270968129054059
+-65.225250090079669,0.9981616220967785,0.77509112239497502,3,7,0,65.585839761918336,1.304542554263693,-0.56785012838122284
+-65.846848332416968,0.93546695898901289,0.77509112239497502,3,7,0,66.14081101462989,1.1803802303560549,-0.25314890999300399
+-65.682239013873243,0.71512237476561891,0.77509112239497502,3,7,0,69.018968448869032,1.3809580807570572,-0.30119127957587721
+-65.254770407300981,0.91929185568456184,0.77509112239497502,3,7,0,66.438059339134483,1.3331585159495722,-0.59404447235721503
+-65.285540061138761,0.99934725143343495,0.77509112239497502,3,7,0,65.294247370524204,1.2780150585779138,-0.40421611929908918
+-65.579888301587815,0.9547382304263291,0.77509112239497502,2,3,0,65.811227707531927,1.1223859959387492,-0.42126482543236549
+-65.764371577842468,0.97008151650253238,0.77509112239497502,2,3,0,66.039786061545186,1.2421384239600939,-0.25341044054820527
+-65.623399188247859,0.83504053827643787,0.77509112239497502,2,3,0,67.790678622596815,1.2699954313874096,-0.71338964780421521
+-66.193381255542477,0.95561168020244169,0.77509112239497502,2,3,0,66.699422423283451,1.0165669799005748,-0.35944500492533699
+-68.233900747582638,0.67053640264497538,0.77509112239497502,2,3,0,69.455113589133404,1.1312774511108141,0.060230280730240671
+-66.374076607963787,1,0.77509112239497502,3,7,0,68.217544575768827,1.3795517892750899,-0.16423664327383874
+-65.39331825616901,0.96266781516703848,0.77509112239497502,2,3,0,66.936134946865806,1.1851085325977191,-0.41330276804351213
+-65.595961372505869,0.9443547509209449,0.77509112239497502,3,7,0,66.136783008097439,1.3170555820873198,-0.72313210208420609
+-65.494924132020742,1,0.77509112239497502,3,7,0,65.715788922128652,1.4131141202147159,-0.68507973135998634
+-67.807116155964266,0.87437612501377104,0.77509112239497502,2,3,0,67.887778427392931,1.6676289165988141,-1.0362912889286389
+-66.869402082591819,1,0.77509112239497502,2,3,0,68.278195523251497,1.7329993290462864,-0.66750779803853622
+-65.771158882002382,0.98849352925723355,0.77509112239497502,2,3,0,67.079925157468253,1.5467275374183089,-0.50892528909761903
+-65.466762190132528,0.83692150601818349,0.77509112239497502,2,3,0,67.561260695316719,1.4456476305053685,-0.43984738086754666
+-65.343870018604221,0.93558518803173563,0.77509112239497502,1,3,0,66.112513260280551,1.2670083284738589,-0.61959292686923151
+-65.36229828989255,0.97635208080601843,0.77509112239497502,3,7,0,65.959158325860884,1.3196979566773466,-0.37265651088494867
+-67.351124898502235,0.74394685479204592,0.77509112239497502,2,3,0,68.306189241835625,1.4723496576356869,-1.0293445846474376
+-67.901666367585719,0.9829277369009688,0.77509112239497502,3,7,0,68.032436185567832,1.4530791841358022,-1.0947059824092433
+-67.194002107052867,1,0.77509112239497502,2,7,0,69.018872233294786,1.7382978660892208,-0.43443784667429997
+-66.384598125892182,1,0.77509112239497502,1,1,0,67.107238798459591,1.6378892668356637,-0.45353302684051666
+-65.725838259812306,1,0.77509112239497502,2,3,0,66.362949254514902,1.1034384402817441,-0.55751182912052366
+-65.537954330464373,0.9544394088382373,0.77509112239497502,2,3,0,66.438152329621317,1.4930050743005123,-0.59760909895157976
+-65.289007966127016,0.99509237026715958,0.77509112239497502,3,7,0,65.734685254712787,1.2126496162966993,-0.49740158763787723
+-66.199637861528146,0.89759685520054822,0.77509112239497502,2,3,0,66.429644368463968,1.6338643787482263,-0.57105653833453462
+-67.319970374616119,0.90815180799497075,0.77509112239497502,2,3,0,67.558718016299736,1.7286042553683298,-0.3726542616062638
+-67.412252063728403,0.98168966978378236,0.77509112239497502,2,7,0,68.587257103808142,1.5178187179882643,-1.0331021140711498
+-65.476255829428467,0.99439046658110541,0.77509112239497502,2,3,0,67.442702577068218,1.3595948736738976,-0.34865647447558412
+-65.209054216759867,0.99171535438891034,0.77509112239497502,1,3,0,65.560615149212012,1.277915941015096,-0.47144444016262571
+-65.32556434658953,0.96698003166995594,0.77509112239497502,1,3,0,65.460230149100155,1.259792580382596,-0.60580961380417753
+-65.339996017350089,0.94131348652026203,0.77509112239497502,1,3,0,65.842648256480061,1.3837208708608004,-0.42351641738805335
+-65.65749799331482,0.92540631740462798,0.77509112239497502,2,3,0,66.338100770269136,1.5134351536681678,-0.64594643967651222
+-65.673370396580026,0.99873352920464153,0.77509112239497502,3,7,0,65.803967875656582,1.0998661081176118,-0.42051838985222018
+-65.545605285685099,0.98152165195533081,0.77509112239497502,2,3,0,65.969227865719219,1.1314859782271247,-0.51624366989556414
+-65.295638810026333,0.97054742132092076,0.77509112239497502,2,3,0,65.969764697047268,1.2738556525685389,-0.39925878380863339
+-65.542533414176859,0.88472534654709845,0.77509112239497502,1,3,0,66.73880864985226,1.4779425499266003,-0.64347239706324033
+-66.808451529351288,0.91554948146806658,0.77509112239497502,2,3,0,66.838543169573626,1.6475217093888679,-0.86453287718810434
+-65.430035187077209,0.96973784952940267,0.77509112239497502,3,7,0,67.76094884746982,1.1784004795503904,-0.39851160900155924
+-65.583222966307659,0.86006836718332025,0.77509112239497502,1,3,0,66.832733281538324,1.3035444550985518,-0.71603720012911221
+-65.465516801231118,0.80605123308263738,0.77509112239497502,3,7,0,68.000069348909392,1.4756284908946911,-0.54391612792885791
+-65.331591784182564,0.90361442634999434,0.77509112239497502,3,7,0,67.564511734230209,1.2217261060540143,-0.40652016146382919
+-65.40021401262814,0.99045904240383198,0.77509112239497502,2,3,0,65.49050319529951,1.1681849167381364,-0.48712305960156621
+-68.50320826886032,0.77618533223566388,0.77509112239497502,2,3,0,68.708620078999289,0.79621364342592882,-0.23573177892778929
+-66.062400751576035,1,0.77509112239497502,2,7,0,68.943549688412119,1.4890927542166561,-0.29672148080150723
+-65.344979401813788,1,0.77509112239497502,2,3,0,66.092757382830726,1.4324718194748189,-0.55327886513827618
+-65.981830572064041,0.8618455065110312,0.77509112239497502,2,3,0,66.540983254890065,1.3071210184566047,-0.80595610247492688
+-65.694422386383266,0.90740483639088498,0.77509112239497502,3,7,0,67.530348645340936,1.2260404738126516,-0.27315827113323904
+-66.09688219646732,0.94505806219812472,0.77509112239497502,2,7,0,66.409305933199263,1.1428698892909042,-0.72641971166076535
+-67.385670089182014,0.92641413760789582,0.77509112239497502,3,7,0,67.621371880870996,1.4152035225372994,-1.0317235725909415
+-69.115819936710324,0.89559206755426579,0.77509112239497502,2,7,0,70.758659167400737,0.93884369852767524,0.046447375643245747
+-66.276728484170476,0.84648754470008158,0.77509112239497502,2,3,0,72.003264554284016,1.0346492634910782,-0.61752206566753109
+-66.46403210047589,0.93122620003684065,0.77509112239497502,2,7,0,67.930283201886482,1.4447054067210476,-0.9029211449004565
+-66.152025080293072,1,0.77509112239497502,3,7,0,66.592496593534733,1.1789816947884422,-0.1910710018977832
+-65.398726308107925,0.9173373625060065,0.77509112239497502,2,3,0,67.232556575299569,1.4535831298073036,-0.54928335335327361
+-65.218351757848438,0.98910668182039441,0.77509112239497502,2,5,0,65.603223481016641,1.3339354898276403,-0.46604340768261132
+-65.262799957538192,0.99635104458933732,0.77509112239497502,2,3,0,65.29284355353748,1.3594278595726044,-0.59220292377827566
+-65.195164630511286,0.96745601860022945,0.77509112239497502,3,7,0,65.649019617426504,1.3031250739535847,-0.52531299472966264
+-66.907843202505632,0.8305673110662678,0.77509112239497502,2,3,0,67.033773750146523,1.0387878880583663,-0.76060220583688376
+-69.030271742056897,0.88420777983449872,0.77509112239497502,2,3,0,70.038716206427111,1.146988932861734,-1.0971943931807675
+-65.323896737284812,0.97239291221561486,0.77509112239497502,2,3,0,69.70090119277657,1.2352374331330556,-0.58179413563522464
+-65.777079496643722,0.84814209661218276,0.77509112239497502,1,3,0,66.699196373530157,1.3094264808005587,-0.2524416445669872
+-65.234658668863233,0.9688130443267039,0.77509112239497502,2,3,0,66.195728271933319,1.3258863917199664,-0.57909165452589817
+-66.233511765596475,0.77780775600202035,0.77509112239497502,2,3,0,67.163953729253251,1.51321593292518,-0.28345016237485426
+-66.636690562899162,0.94552459929156896,0.77509112239497502,1,1,0,66.744358556083128,1.587924535393505,-0.28701981797847648
+-68.01835445127243,0.90819783169421264,0.77509112239497502,3,7,0,69.300279748393677,1.1091059938223031,0.031434747697156096
+-65.420430525793364,1,0.77509112239497502,2,3,0,67.702321228270819,1.1756268001518417,-0.54539021695648415
+-65.235896346635968,0.97083442102425221,0.77509112239497502,2,3,0,65.641726875783121,1.3027683455308476,-0.43645136758393943
+-65.89516218903762,0.93775430756679024,0.77509112239497502,2,3,0,65.981436957330914,1.4364316412986187,-0.79360840559351797
+-65.528275039745466,1,0.77509112239497502,2,3,0,66.155246987030196,1.4546782417032611,-0.42284303784477484
+-65.432205216360529,0.91686264735057266,0.77509112239497502,2,7,0,66.314991698408789,1.3126481285592577,-0.6730710436059848
+-69.509567345531565,0.67022123745409834,0.77509112239497502,2,3,0,70.245277421958846,0.71079385563583863,-0.54591611967132592
+-66.531906506729413,1,0.77509112239497502,2,3,0,69.706135636262303,1.3361655398051333,-0.12639114575017915
+-66.295701878985369,1,0.77509112239497502,1,1,0,66.617539741170475,1.3534542889805232,-0.16750807289230771
+-65.284859412354933,1,0.77509112239497502,2,3,0,66.223140021797946,1.3657579682156649,-0.60514101870567072
+-65.970635369388916,0.94351882912064655,0.77509112239497502,2,3,0,66.003832807336167,1.4832119403841024,-0.79390983493505163
+-65.334195029949967,0.99791734041589919,0.77509112239497502,2,3,0,66.081812943679665,1.2750866741881657,-0.62010570505061713
+-66.054352524255876,0.75035128419775854,0.77509112239497502,1,3,0,67.370148035104165,1.4801044582242497,-0.28952601207362877
+-67.031248097094235,0.90088921266699806,0.77509112239497502,2,3,0,67.390684682932672,1.0709642244494,-0.81599186534617429
+-66.474862138538953,0.99695017734564539,0.77509112239497502,3,7,0,68.031814683887887,1.4817524429486855,-0.20732647090718628
+-68.194472320146417,0.92059216054073201,0.77509112239497502,3,7,0,68.823784011046413,1.8769669751191174,-0.55997493761745232
+-69.605260988160552,0.79341263868726175,0.77509112239497502,2,3,0,71.83515183052873,1.8025471627249718,-0.098493068334809405
+-65.583770282619909,0.96900279119763499,0.77509112239497502,3,7,0,70.603551499131783,1.287240461327265,-0.7104613717095134
+-65.688140001139246,0.99131713839339652,0.77509112239497502,2,7,0,65.903640149598075,1.1845903739087471,-0.66925877287119562
+-65.964485008519262,0.9733249764352111,0.77509112239497502,2,7,0,66.630201552895812,1.0415417509962641,-0.47145482870378697
+-65.322776499369411,0.92538581284226396,0.77509112239497502,3,7,0,66.783147110432481,1.4159774436668682,-0.57922499225735247
+# 
+#  Elapsed Time: 0.057 seconds (Warm-up)
+#                0.007 seconds (Sampling)
+#                0.064 seconds (Total)
+# 
diff --git a/test/data/logistic_output_3.csv b/test/data/logistic_output_3.csv
new file mode 100644
index 0000000..a806d6d
--- /dev/null
+++ b/test/data/logistic_output_3.csv
@@ -0,0 +1,149 @@
+# stan_version_major = 2
+# stan_version_minor = 25
+# stan_version_patch = 0
+# model = logistic_model
+# method = sample (Default)
+#   sample
+#     num_samples = 100
+#     num_warmup = 1000 (Default)
+#     save_warmup = 0 (Default)
+#     thin = 1 (Default)
+#     adapt
+#       engaged = 1 (Default)
+#       gamma = 0.050000000000000003 (Default)
+#       delta = 0.80000000000000004 (Default)
+#       kappa = 0.75 (Default)
+#       t0 = 10 (Default)
+#       init_buffer = 75 (Default)
+#       term_buffer = 50 (Default)
+#       window = 25 (Default)
+#     algorithm = hmc (Default)
+#       hmc
+#         engine = nuts (Default)
+#           nuts
+#             max_depth = 10 (Default)
+#         metric = diag_e (Default)
+#         metric_file =  (Default)
+#         stepsize = 1 (Default)
+#         stepsize_jitter = 0 (Default)
+# id = 3
+# data
+#   file = logistic.data.R
+# init = 2 (Default)
+# random
+#   seed = 12345
+# output
+#   file = logistic_output_3.csv
+#   diagnostic_file =  (Default)
+#   refresh = 100 (Default)
+#   sig_figs = 17
+lp__,accept_stat__,stepsize__,treedepth__,n_leapfrog__,divergent__,energy__,beta.1,beta.2
+# Adaptation terminated
+# Step size = 0.893365
+# Diagonal elements of inverse mass matrix:
+# 0.0460469, 0.0527956
+-65.505817829767395,1,0.89336516701798208,2,3,0,66.568673034237975,1.3250544321028301,-0.32473969429595312
+-65.412998623075694,0.94226911711082784,0.89336516701798208,1,3,0,66.191677260322123,1.4558038077059023,-0.57679257464888201
+-65.574810054077787,0.97141961136686938,0.89336516701798208,1,1,0,65.580133765725392,1.5067328243822646,-0.57069748673412535
+-65.588927384457733,0.98318845767729923,0.89336516701798208,2,3,0,65.908878462264497,1.1665556922735556,-0.33652998855918959
+-66.09643763078094,0.90668463307015978,0.89336516701798208,2,3,0,66.616409590016175,1.2490859350077712,-0.18679016763255296
+-65.440143752579004,0.73589158663352328,0.89336516701798208,2,3,0,69.395538806742962,1.1953936956415265,-0.59270871526831626
+-65.521835749337527,0.90357069834109682,0.89336516701798208,1,3,0,66.2395677139139,1.456141938298781,-0.42846005708091067
+-68.312482915251124,0.69671604781618701,0.89336516701798208,2,3,0,69.148645114591659,1.8350902465586949,-0.373823054219729
+-68.139244204054435,1,0.89336516701798208,2,3,0,69.086368432623971,1.7386146507929172,-0.22274253916007714
+-66.749110214693317,1,0.89336516701798208,1,1,0,68.016601694820508,1.5724915967161559,-0.24514813061500396
+-65.971104371564536,0.99467313930662848,0.89336516701798208,2,3,0,67.387651118854521,1.1332872734401271,-0.25238264351085477
+-65.5442679269526,0.96456477937761742,0.89336516701798208,2,3,0,66.430103049806405,1.1388326998744738,-0.54092911359328233
+-65.446826342344835,1,0.89336516701798208,1,1,0,65.559040602734328,1.1647100308902478,-0.53825150353906992
+-65.568204750996117,0.99437439928626947,0.89336516701798208,3,7,0,65.639387405598455,1.1203740467934902,-0.47270218250340101
+-65.786222876234348,0.7792511431653667,0.89336516701798208,1,3,0,67.658774799327873,1.5552605081429887,-0.60646687216533945
+-67.937196718552386,0.83078746528748726,0.89336516701798208,2,3,0,68.260370133292184,1.86105122842007,-0.68735919001967749
+-65.418166468215347,1,0.89336516701798208,2,3,0,67.56115723207526,1.3488613535738945,-0.67240077373121865
+-65.288362867386354,0.97934489526098356,0.89336516701798208,3,7,0,65.686620660812125,1.2456467497895802,-0.41536400867007467
+-66.616669957116287,0.82385481375240577,0.89336516701798208,2,3,0,66.873586080428097,1.6220844217852683,-0.34384006162949299
+-65.902453306152594,0.98950156369684661,0.89336516701798208,2,3,0,66.609030354856472,1.2115324179420659,-0.74349951746969123
+-65.316022959092635,0.95128530222521246,0.89336516701798208,2,3,0,66.433613993042584,1.2307018300720169,-0.4084013965078529
+-65.455941708360243,0.96118963096560373,0.89336516701798208,3,7,0,65.71564874031354,1.3351194726484383,-0.68498797454931903
+-65.527214463215472,0.99060501834101355,0.89336516701798208,1,1,0,65.558040084785375,1.3556087864094299,-0.70863841127078486
+-67.02457304151028,0.84420077409890359,0.89336516701798208,2,3,0,67.152181164380352,1.7367950428417533,-0.49785025168113034
+-66.121386805485116,1,0.89336516701798208,1,1,0,66.87318065456202,1.6169685315550071,-0.53619076941856947
+-68.365790034762355,0.85533028969902247,0.89336516701798208,2,3,0,69.066346060770982,1.9015293075080164,-0.77051339615694259
+-66.99443950904228,0.9512667322675582,0.89336516701798208,2,7,0,68.838190900618727,0.90772061143856642,-0.47875544540988046
+-66.508727501769243,0.98348108787595179,0.89336516701798208,2,3,0,68.472022882080836,1.5846991203985743,-0.31108493620313099
+-65.644115970917625,0.96299924661974523,0.89336516701798208,2,7,0,67.229164070195395,1.2289357991438996,-0.28530601318599536
+-67.798373796448971,0.56501479024381762,0.89336516701798208,2,3,0,69.027161362620546,0.88444710909097635,-0.66947129688811557
+-68.21932829373111,0.91162268309577243,0.89336516701798208,2,3,0,69.07556210333054,1.7290018361549344,-0.1955359656664008
+-66.099270613006155,0.9612220484693933,0.89336516701798208,2,3,0,69.101814788805299,1.2972208805656138,-0.18792774718156155
+-65.943739287582162,0.95194182402778471,0.89336516701798208,2,7,0,66.850737971593645,1.5598751773371313,-0.70950411724281248
+-65.932110335071059,0.95637698473486543,0.89336516701798208,2,3,0,66.506799341369728,1.2747894894082399,-0.78464003012352679
+-66.650638473071709,0.80346312591258384,0.89336516701798208,2,3,0,67.757430184495547,1.4115280409820925,-0.13573740812088447
+-65.979362150789697,0.97341923350342074,0.89336516701798208,2,7,0,67.451133509492038,1.574932075362808,-0.69593172724094754
+-66.265870990402703,0.9589774827578833,0.89336516701798208,2,7,0,66.792054607718029,1.0536557933831026,-0.25992013366777478
+-66.042264637900814,1,0.89336516701798208,1,1,0,66.31749137536579,1.085548594928736,-0.27985643899744961
+-66.917810451143069,0.93290266202302219,0.89336516701798208,2,3,0,67.128160363448387,1.1637828127120335,-0.07838015823118849
+-65.809447481035605,0.98108506032753162,0.89336516701798208,2,3,0,67.381889245480551,1.3281183841285169,-0.77647648190147889
+-65.600037744785581,0.91127533561173857,0.89336516701798208,2,3,0,66.773819404962211,1.4800771922699925,-0.43226799235624758
+-65.548560675822642,0.91898818147986694,0.89336516701798208,2,3,0,66.42445160620214,1.2478393668725447,-0.68052235681091711
+-65.903358316731484,0.97549255604165686,0.89336516701798208,2,3,0,66.026203576102446,1.5810520522038864,-0.574801021794904
+-65.590785236530834,0.95797960572471119,0.89336516701798208,2,3,0,66.741470954074543,1.3241644913803328,-0.72331596030687706
+-66.974548758928449,0.70183684639660326,0.89336516701798208,2,3,0,68.244227239728275,1.7371627394066576,-0.52744636482044172
+-66.418478932458527,0.9958722179920374,0.89336516701798208,3,7,0,67.61537610342566,1.5926938443513992,-0.8250065772696723
+-65.702110679788404,0.89094066381034664,0.89336516701798208,2,3,0,68.071268719402511,1.4786903925992272,-0.71717388889034206
+-65.981106206057277,0.9861200879783184,0.89336516701798208,2,3,0,66.009455500182682,1.4615172385695683,-0.80581741413303254
+-66.411699723551692,0.91527572328425599,0.89336516701798208,2,3,0,66.814725965142031,1.6646258354314414,-0.66878298271250336
+-65.909902348927631,0.88959123380632199,0.89336516701798208,2,3,0,67.296316055239529,1.3247799898733628,-0.79664262125313301
+-67.377622278418855,0.85422475227718442,0.89336516701798208,2,3,0,67.575638679657814,1.7929122677303146,-0.57608112216170515
+-65.580823342260118,0.97882672821916317,0.89336516701798208,3,7,0,69.346517824141074,1.1266476904493099,-0.5308148743573462
+-65.614195330261865,0.99113178921485667,0.89336516701798208,2,3,0,65.805643180398206,1.5138311557794326,-0.5223322428282261
+-65.784063381288902,0.96158293814883766,0.89336516701798208,2,7,0,66.20639266216908,1.0793061934043706,-0.4037042683693034
+-65.403552451873594,0.99168481471035275,0.89336516701798208,2,3,0,66.067274717877268,1.4433247808485001,-0.4800314069584195
+-65.403552451873594,0.72911534058007621,0.89336516701798208,1,3,0,67.35558540542398,1.4433247808485001,-0.4800314069584195
+-65.468723711629906,0.99559589512471314,0.89336516701798208,2,3,0,65.630521451758753,1.422843563865684,-0.66841772284588963
+-66.121575356151737,0.84405440310148216,0.89336516701798208,2,3,0,67.289299656120448,1.5757795565026007,-0.75546896204043446
+-66.924099967181434,0.90682780275859731,0.89336516701798208,2,3,0,67.776204845731769,1.1972953669392721,-0.069798929308174718
+-65.817529136782952,1,0.89336516701798208,2,3,0,67.090132527879732,1.1120055690541004,-0.61453529152397901
+-65.271773157828321,1,0.89336516701798208,1,3,0,65.70135507659856,1.2326879008048361,-0.53692394187824488
+-65.860484793173868,0.87661975465292519,0.89336516701798208,2,3,0,66.30774355135749,1.0958543738327959,-0.60054986483504347
+-65.860924267376902,0.99237023673691593,0.89336516701798208,2,3,0,66.139942914745461,1.5499822355700288,-0.45767659438992025
+-65.842095313255186,0.93042797878056349,0.89336516701798208,2,3,0,66.729935288049404,1.1163045141085504,-0.62976037853016675
+-65.992385036194648,1,0.89336516701798208,2,3,0,66.438365595188543,1.0369765254231165,-0.42959408889497308
+-66.335128038456048,0.92996568636687549,0.89336516701798208,1,1,0,66.423613247306207,0.98636946996966446,-0.4078719874474987
+-65.922852525591551,0.99755953557363541,0.89336516701798208,2,3,0,66.545959119072123,1.5839163547560899,-0.55721415955947384
+-66.136709278894955,0.98803311616296174,0.89336516701798208,3,7,0,66.5176962657807,1.6208797281534471,-0.64358668936455088
+-68.408523107207898,0.50795705915488087,0.89336516701798208,2,3,0,70.218901547738213,1.2329142185467754,-1.0859950426198954
+-65.893149402094011,1,0.89336516701798208,2,3,0,68.050742680709163,1.5737032529606827,-0.52194163970390717
+-66.418489245884643,0.88082943738177155,0.89336516701798208,2,3,0,67.328692377489219,1.4914374147818785,-0.8858470001562746
+-65.324080572538804,0.95242358347838774,0.89336516701798208,2,7,0,67.260475021910921,1.4143957841289987,-0.48454484195803726
+-65.884424651662798,0.90601811047078273,0.89336516701798208,2,3,0,66.21612454493021,1.5554562902295279,-0.46003783288969924
+-65.639500705209272,0.84801232718698127,0.89336516701798208,2,7,0,67.393221986005955,1.1183791879418623,-0.54745583144874488
+-66.356742725160004,0.9455962012078124,0.89336516701798208,3,7,0,66.543058161234555,1.3472212549340181,-0.88074072367740275
+-65.486839783593965,1,0.89336516701798208,2,3,0,66.646624347646096,1.1609869462942939,-0.39177354973653122
+-65.54824697593358,0.94023015039121227,0.89336516701798208,2,7,0,66.047143531115552,1.1918709843768285,-0.63271142593551954
+-65.403402550535432,0.96351172929787976,0.89336516701798208,2,3,0,65.951298763311769,1.1669683293792688,-0.46776556387669022
+-65.616578855680615,0.94514459668103346,0.89336516701798208,2,3,0,65.980695728614833,1.1131566784840552,-0.4211676866398697
+-65.620116280866426,0.95673689513498406,0.89336516701798208,2,7,0,66.18393184809554,1.3197446983678036,-0.73008384032420937
+-66.133725045037522,0.91330225922949748,0.89336516701798208,3,7,0,66.879481865844838,1.4843720956684106,-0.83142081695807168
+-65.511291302157915,0.99684372889682071,0.89336516701798208,3,7,0,66.059860606576407,1.1990047826907368,-0.33907201245313079
+-65.565027240662715,0.99715475319972702,0.89336516701798208,3,7,0,65.612798287209728,1.1613604019119568,-0.35153027638508128
+-65.324224710545153,0.96946603224745165,0.89336516701798208,2,7,0,65.977625177668784,1.2419514462180892,-0.58930495377630143
+-65.895003790723635,0.84354769503796367,0.89336516701798208,1,3,0,66.732481620532155,1.5743807229514162,-0.636592885572553
+-65.435333047654012,0.76552420950196653,0.89336516701798208,2,3,0,67.985823811222104,1.2320345812999256,-0.34958547804910073
+-65.244693543874405,0.9955763222301327,0.89336516701798208,3,7,0,65.490768885438968,1.3280722770946789,-0.58700316443080536
+-65.244693543874405,0.65637870256685538,0.89336516701798208,1,3,0,67.032052493783581,1.3280722770946789,-0.58700316443080536
+-65.477228614344341,0.94565947185403365,0.89336516701798208,1,3,0,65.57412178909793,1.1932422116202857,-0.60672851676246209
+-65.573822218968616,0.99837933343783247,0.89336516701798208,3,7,0,65.639161666678476,1.3012770023490823,-0.71278150859218958
+-65.868107257822516,0.81176262308409386,0.89336516701798208,1,3,0,67.544859819285634,1.3094466072700204,-0.23328644995195941
+-65.206799031046756,1,0.89336516701798208,2,3,0,65.753455173104598,1.2810107175186598,-0.5294962848078365
+-65.39580838970106,0.94241966936255217,0.89336516701798208,2,3,0,65.748614877462103,1.2484221385784486,-0.35914134065646303
+-65.275644188367451,0.9064895451166386,0.89336516701798208,2,3,0,66.115597821699552,1.3861902298221216,-0.57973275615438691
+-67.374856128216649,0.68619176630654921,0.89336516701798208,2,3,0,67.744087507022513,0.87716908911964542,-0.52891199651748622
+-65.616673193224315,1,0.89336516701798208,2,3,0,67.036430649781167,1.4376728487415633,-0.36552966948499527
+-66.03943690546464,0.8561705881931696,0.89336516701798208,2,7,0,67.30308972653809,1.4397015201754089,-0.8248039709934688
+-66.049332677133378,0.98523013518076841,0.89336516701798208,2,3,0,66.377510690789691,1.3029062785885974,-0.8172428123735811
+-66.744151928166673,0.9407257478752008,0.89336516701798208,2,3,0,67.228772031537218,1.1333012099220134,-0.11304063492318517
+-65.947827854473942,1,0.89336516701798208,2,3,0,67.094343292412148,1.4014225834831566,-0.81091135592849095
+# 
+#  Elapsed Time: 0.052 seconds (Warm-up)
+#                0.006 seconds (Sampling)
+#                0.058 seconds (Total)
+# 
diff --git a/test/data/logistic_output_4.csv b/test/data/logistic_output_4.csv
new file mode 100644
index 0000000..c3a0d1a
--- /dev/null
+++ b/test/data/logistic_output_4.csv
@@ -0,0 +1,149 @@
+# stan_version_major = 2
+# stan_version_minor = 25
+# stan_version_patch = 0
+# model = logistic_model
+# method = sample (Default)
+#   sample
+#     num_samples = 100
+#     num_warmup = 1000 (Default)
+#     save_warmup = 0 (Default)
+#     thin = 1 (Default)
+#     adapt
+#       engaged = 1 (Default)
+#       gamma = 0.050000000000000003 (Default)
+#       delta = 0.80000000000000004 (Default)
+#       kappa = 0.75 (Default)
+#       t0 = 10 (Default)
+#       init_buffer = 75 (Default)
+#       term_buffer = 50 (Default)
+#       window = 25 (Default)
+#     algorithm = hmc (Default)
+#       hmc
+#         engine = nuts (Default)
+#           nuts
+#             max_depth = 10 (Default)
+#         metric = diag_e (Default)
+#         metric_file =  (Default)
+#         stepsize = 1 (Default)
+#         stepsize_jitter = 0 (Default)
+# id = 4
+# data
+#   file = logistic.data.R
+# init = 2 (Default)
+# random
+#   seed = 12345
+# output
+#   file = logistic_output_4.csv
+#   diagnostic_file =  (Default)
+#   refresh = 100 (Default)
+#   sig_figs = 17
+lp__,accept_stat__,stepsize__,treedepth__,n_leapfrog__,divergent__,energy__,beta.1,beta.2
+# Adaptation terminated
+# Step size = 0.947608
+# Diagonal elements of inverse mass matrix:
+# 0.0462363, 0.0566844
+-66.847035785602301,0.82648539991727776,0.94760825861307307,1,1,0,66.937592630087181,0.9230629657124465,-0.39289875123005341
+-66.073191110529336,0.76080690440456777,0.94760825861307307,2,3,0,70.030179311789652,1.6090142982985995,-0.53801634538037302
+-65.694230224352665,1,0.94760825861307307,2,3,0,66.141127792543713,1.0938587123887547,-0.49415295442414359
+-66.757263610353576,0.86725995923981802,0.94760825861307307,2,3,0,67.002147863884275,1.5399926071963366,-0.20923188875598672
+-67.580678199408894,0.84177519278190138,0.94760825861307307,1,1,0,67.81301431165214,1.6546058058396356,-0.19881333213040589
+-66.215926451172152,1,0.94760825861307307,1,1,0,67.334421711328787,1.5105895669947076,-0.28449555872849008
+-65.265752403185047,0.98035277328784731,0.94760825861307307,2,3,0,66.280388779410728,1.2423810569592624,-0.43665561513942064
+-66.096306922144493,0.78624867898706075,0.94760825861307307,1,3,0,66.469880753236382,1.5210371176584987,-0.32517795560591145
+-65.440214806641208,1,0.94760825861307307,1,1,0,65.93596004475215,1.4314903982013774,-0.43111261106288579
+-65.373726607514996,0.73857239120012641,0.94760825861307307,2,3,0,67.630386417873581,1.3853294975109245,-0.6462574026737079
+-65.23800564438055,0.98567017108484445,0.94760825861307307,2,3,0,65.508403145196965,1.2781027903993085,-0.43691884235707168
+-65.247394586652916,0.83773383922669953,0.94760825861307307,3,7,0,66.482854904225661,1.2353872951639677,-0.49049101092260627
+-65.237520340216719,0.86837154622139445,0.94760825861307307,2,3,0,66.433159976561328,1.2790500766131756,-0.43703790751605576
+-68.699452561391823,0.3858481963670361,0.94760825861307307,1,3,0,69.553411139071798,1.0145233275867012,-0.96448768008876307
+-65.353182647924285,1,0.94760825861307307,1,3,0,68.051338339345335,1.3478936159826702,-0.64630754031966653
+-65.193717199991966,0.99687515279214167,0.94760825861307307,2,3,0,65.410185372170503,1.2952111957858401,-0.5092197666123619
+-65.250624686724024,0.61147858140890576,0.94760825861307307,2,3,0,68.063091064026366,1.3543384797312512,-0.45319346643540748
+-66.493859424469548,0.84153939442753778,0.94760825861307307,2,3,0,66.688098398651576,1.2323281062971867,-0.86018151008934174
+-65.575011395014798,0.94523491565101081,0.94760825861307307,1,3,0,67.43997523181109,1.1375720859092822,-0.38239397283561538
+-65.268469684640692,0.94791290625159863,0.94760825861307307,2,3,0,66.150962322625617,1.3941419682135177,-0.55066420618185141
+-65.213974098126599,0.99950901314364027,0.94760825861307307,2,3,0,65.286631042361918,1.2625225303546113,-0.50273242673983809
+-65.833460141108674,0.77161878301467335,0.94760825861307307,2,3,0,66.90813614636636,1.5311391284329574,-0.70813354553037722
+-66.074871015369965,0.9185782313290124,0.94760825861307307,3,7,0,66.969507675127275,1.5421094550282859,-0.77989754437898651
+-67.093580239447135,0.92181985052677862,0.94760825861307307,2,3,0,67.171951171322107,1.4807359962430608,-0.99454343486873198
+-66.980579698967986,0.99984324090611609,0.94760825861307307,2,7,0,67.146607248042116,1.1803729616690646,-0.065986404813840605
+-65.355669265544648,1,0.94760825861307307,2,3,0,66.665445832190983,1.2859078721177932,-0.63509365355564229
+-65.504259774160431,0.81711633086727831,0.94760825861307307,2,3,0,66.732595365033959,1.2590652882329045,-0.31909165724800487
+-65.932007247750406,0.93876477861074181,0.94760825861307307,3,7,0,66.150436665980635,1.2288542006358216,-0.21988329337893042
+-65.533626405225519,1,0.94760825861307307,2,3,0,65.894697577040617,1.2979056078949296,-0.31074268391574134
+-65.874188810223544,0.96766238971573781,0.94760825861307307,2,3,0,66.042255767265544,1.1100056528964524,-0.63006682723190921
+-65.928692062818953,0.72108951836902424,0.94760825861307307,2,3,0,67.984530149277902,1.2738174163736766,-0.78355201054486767
+-66.008595028574575,0.99818097252172822,0.94760825861307307,2,7,0,66.012300641660531,1.3408317529294609,-0.2135741990836614
+-65.399653028920952,1,0.94760825861307307,2,3,0,66.021112145391612,1.1701790523199618,-0.50286491492532459
+-65.678654783001249,0.92196515361517006,0.94760825861307307,2,3,0,66.061223532309583,1.5278064509030647,-0.6172044090539065
+-67.107422993897742,0.87205008671428441,0.94760825861307307,3,7,0,67.436676655942392,1.6810948416962754,-0.89707151990661993
+-65.875618396543075,0.99866285213481343,0.94760825861307307,2,3,0,67.226976373887851,1.4284238641851474,-0.79101206909486987
+-65.733892007830335,0.7289942922982976,0.94760825861307307,2,3,0,68.140481705489861,1.3941797755723857,-0.29613068353570604
+-65.191866972495305,0.99539319229801626,0.94760825861307307,1,3,0,65.727759313475659,1.3053654330823647,-0.51051057931279908
+-65.301605414801827,0.97454681222362749,0.94760825861307307,1,3,0,65.366973005313312,1.4120488592813125,-0.55483984561036415
+-65.65885467577111,0.96811590867225517,0.94760825861307307,2,7,0,65.702198424556869,1.1420526022745081,-0.33638544919279834
+-66.187315227559296,0.66256709727862573,0.94760825861307307,2,3,0,68.448030754031208,1.6326510156841509,-0.58775596733065627
+-65.32584979885722,0.96725404872677301,0.94760825861307307,1,3,0,66.701938169957799,1.3413817155146193,-0.39760241824545917
+-66.668233248393022,0.84267510241435517,0.94760825861307307,2,3,0,66.843387177162896,1.1943571266812714,-0.86389928360971935
+-66.169111182670946,1,0.94760825861307307,1,1,0,66.737312611189353,1.1850289633537936,-0.77681945630154647
+-65.311984078429944,0.9328037535067043,0.94760825861307307,2,3,0,66.693833890293334,1.2057546154855385,-0.4518441579168096
+-65.932996551420999,0.7696018923069472,0.94760825861307307,1,3,0,67.185651279214071,1.5100639367665001,-0.76626852793285161
+-65.842847134641346,0.99688704633939029,0.94760825861307307,2,7,0,65.976478887565648,1.1466921791124525,-0.2744515815707203
+-65.447980086468874,1,0.94760825861307307,2,3,0,65.79495785983292,1.2474474349068991,-0.33976697603751121
+-65.355006467137244,0.97350685078951571,0.94760825861307307,2,7,0,65.675198116563109,1.4332012345238097,-0.50543994035401685
+-66.34896206642172,0.80244035517855228,0.94760825861307307,2,3,0,67.052908275757247,1.5562389438574789,-0.309027705452534
+-66.577254011271478,0.97236574079422267,0.94760825861307307,2,3,0,67.69516567335404,1.0275691864117822,-0.21951348217914371
+-65.917281572225392,0.73973200810622364,0.94760825861307307,2,3,0,68.494317075865268,1.534702812161024,-0.39976151378856239
+-65.861654714207305,1,0.94760825861307307,2,3,0,66.079580153037625,1.4970122601078975,-0.35936553293552903
+-66.143335381466159,0.75873692423844408,0.94760825861307307,3,7,0,69.106001755643859,1.0295414679360384,-0.55499240841000186
+-66.181577121111289,1,0.94760825861307307,2,3,0,66.70114431819411,1.0481104232258043,-0.29171935784681863
+-65.595366197058311,0.9426517527469036,0.94760825861307307,2,3,0,66.823517313912802,1.2619260965895716,-0.29272620498241725
+-65.515058623688276,0.92884695746137214,0.94760825861307307,2,3,0,66.276256243905692,1.3129643520556469,-0.69947836673074293
+-66.385827766264612,0.89914993472846394,0.94760825861307307,2,3,0,66.832526132670765,1.5604354626749628,-0.84510069217028705
+-66.385827766264612,0.63089911319376435,0.94760825861307307,2,3,0,68.661705030014758,1.5604354626749628,-0.84510069217028705
+-66.191368947866323,1,0.94760825861307307,2,3,0,66.581920344771419,1.6207115479376506,-0.69185859087087853
+-65.315320343023757,0.83776174634067635,0.94760825861307307,2,3,0,67.569853487055369,1.2132540114946573,-0.54155087938369617
+-65.616188990564197,0.89424961670740244,0.94760825861307307,2,3,0,66.092975110981868,1.1088964201574794,-0.46076397878725783
+-65.309455199948985,1,0.94760825861307307,2,3,0,65.706531719252339,1.2387663505851283,-0.57698873187925792
+-65.766840100925876,0.90919506259650118,0.94760825861307307,1,3,0,65.967688899325026,1.3290230438286637,-0.76728078507400732
+-66.540150126947609,0.85932598267986615,0.94760825861307307,2,3,0,66.760258455919271,1.6270833293371632,-0.37386050400995069
+-65.711445811292251,1,0.94760825861307307,2,3,0,66.457645884533093,1.4631079665326094,-0.36334128091111351
+-65.222641906893443,0.98663389568502391,0.94760825861307307,2,3,0,65.810098942493127,1.3633195910132883,-0.53234767983391573
+-65.690509795367873,0.90702478940684739,0.94760825861307307,2,3,0,65.917656147725324,1.4770167400135026,-0.38886351182575885
+-65.665065329602456,1,0.94760825861307307,2,3,0,65.818778918316212,1.1060491720168111,-0.52528928177767809
+-65.451565142322849,0.92842645391803502,0.94760825861307307,2,3,0,66.576458459062351,1.4146206009001672,-0.40298883952437392
+-65.783181792950742,0.89639695218152349,0.94760825861307307,2,3,0,66.473268610819247,1.0740818856894543,-0.47291470014777287
+-65.767965974323715,0.99888018281193747,0.94760825861307307,2,3,0,65.92661100584526,1.0813108512564735,-0.50822451555380144
+-65.775827782477819,0.99584791721974164,0.94760825861307307,1,1,0,65.920654248121693,1.0819199914915154,-0.51862924150552037
+-65.700062135805126,0.97165445843821108,0.94760825861307307,2,3,0,66.110167319677998,1.5324120925388376,-0.51410937644746335
+-65.340019059211841,0.9423130255467157,0.94760825861307307,1,3,0,66.382806491336169,1.1927471751782348,-0.45264340493575289
+-66.409245364658545,0.82068496599079055,0.94760825861307307,2,3,0,66.845369866762439,1.637515575714322,-0.75738075073892919
+-67.805335709748093,0.81221239802739953,0.94760825861307307,2,3,0,68.983771375713133,1.2327713558664626,0.035088863969391648
+-66.574609416251391,1,0.94760825861307307,2,3,0,68.7077294355162,0.98339269381055672,-0.59297687729803494
+-65.737898253206083,1,0.94760825861307307,2,3,0,66.668497481556926,1.1248294850415124,-0.32809462838751124
+-65.232075132693453,1,0.94760825861307307,2,3,0,65.714817492827294,1.2872725826612201,-0.56557150566384873
+-65.232075132693453,0.84195966512847276,0.94760825861307307,2,3,0,66.4941277534965,1.2872725826612201,-0.56557150566384873
+-65.53413429006163,0.804662171623308,0.94760825861307307,2,3,0,66.685665017072537,1.3088650198972984,-0.31241475251480866
+-65.505211431728171,0.86186278828263363,0.94760825861307307,3,7,0,66.837719390352689,1.3056726927535205,-0.69454500551279974
+-65.505211431728171,0.71081910445992891,0.94760825861307307,2,3,0,66.767390861864683,1.3056726927535205,-0.69454500551279974
+-68.542661429349096,0.4766697346665752,0.94760825861307307,2,3,0,71.224487882616444,1.895756885016427,-0.8883449785583597
+-67.51270154062145,1,0.94760825861307307,2,3,0,68.485593562276051,1.7516600643612101,-0.89939718855152029
+-65.512280031203744,0.99409856096554938,0.94760825861307307,2,3,0,67.571604530384704,1.4822708600473693,-0.49786923147892836
+-65.482235231826721,1,0.94760825861307307,2,3,0,65.545204613024438,1.1462647359232709,-0.5074691172076693
+-66.095959147359082,0.85617475143011179,0.94760825861307307,1,1,0,66.108277970667672,1.02414576064546,-0.50254510342427217
+-65.369466822280742,1,0.94760825861307307,2,3,0,66.208781247560125,1.2440321650912838,-0.61391621751487824
+-65.753914015124664,0.92993837534926238,0.94760825861307307,1,3,0,65.82728960571589,1.1162949327743898,-0.59860920661530626
+-65.730070812416486,1,0.94760825861307307,2,3,0,65.851568682888271,1.5179884318582639,-0.44620365546153307
+-68.876614500469742,0.84435901093967392,0.94760825861307307,2,3,0,68.913586596538934,0.74698167064115517,-0.31703475833561712
+-66.222088419291111,1,0.94760825861307307,2,3,0,68.621395888427472,1.1273204146339355,-0.20268887633882565
+-65.868204167375964,0.96862472501122376,0.94760825861307307,2,7,0,66.65821250672866,1.5088066348205706,-0.74722369915085274
+-66.610090233704952,0.75916462347072411,0.94760825861307307,2,7,0,67.650624465979035,1.6041383741965771,-0.3162439896814746
+-65.372163063757213,1,0.94760825861307307,2,3,0,66.581634714512859,1.4321199428628784,-0.59833828898909702
+-65.259649763523882,0.9943658805109884,0.94760825861307307,2,3,0,65.446707357783296,1.3231018825837235,-0.42523520727858788
+-65.564642435727336,0.97015511812899269,0.94760825861307307,2,7,0,65.573106522842593,1.3967798112300691,-0.71520655644294973
+-65.32592604409038,0.75434173095247059,0.94760825861307307,2,3,0,67.494082360662802,1.4164803923484324,-0.48812261269098356
+# 
+#  Elapsed Time: 0.054 seconds (Warm-up)
+#                0.005 seconds (Sampling)
+#                0.059 seconds (Total)
+# 
diff --git a/test/test_cmdstan_args.py b/test/test_cmdstan_args.py
index 17316f9..434c9ed 100644
--- a/test/test_cmdstan_args.py
+++ b/test/test_cmdstan_args.py
@@ -2,10 +2,14 @@
 
 import os
 import platform
+import logging
 import unittest
 from time import time
 
-from cmdstanpy import _TMPDIR
+from testfixtures import LogCapture
+
+from cmdstanpy import _TMPDIR, cmdstan_path
+from cmdstanpy.utils import cmdstan_version_at
 from cmdstanpy.cmdstan_args import (
     Method,
     SamplerArgs,
@@ -571,6 +575,60 @@ class CmdStanArgsTest(unittest.TestCase):
                     method_args=sampler_args,
                 )
 
+    def test_args_sig_figs(self):
+        sampler_args = SamplerArgs()
+        cmdstan_path()  # sets os.environ['CMDSTAN']
+        good_path = os.environ['CMDSTAN']
+        del os.environ['CMDSTAN']
+        os.environ['CMDSTAN'] = os.path.join(
+            os.path.dirname(good_path), 'cmdstan-2.24.1'
+        )
+        with LogCapture() as log:
+            logging.getLogger()
+            CmdStanArgs(
+                model_name='bernoulli',
+                model_exe='bernoulli.exe',
+                chain_ids=[1, 2, 3, 4],
+                sig_figs=12,
+                method_args=sampler_args,
+            )
+        expect = (
+            'arg sig_figs not valid, CmdStan version must be 2.25 '
+            'or higher, using verson {} in directory {}'
+        ).format(
+            os.path.basename(cmdstan_path()), os.path.dirname(cmdstan_path())
+        )
+        log.check_present(('cmdstanpy', 'WARNING', expect))
+        os.environ['CMDSTAN'] = good_path
+        if cmdstan_version_at(2, 25):
+            cmdstan_args = CmdStanArgs(
+                model_name='bernoulli',
+                model_exe='bernoulli.exe',
+                chain_ids=[1, 2, 3, 4],
+                sig_figs=12,
+                method_args=sampler_args,
+            )
+            cmd = cmdstan_args.compose_command(
+                idx=0, csv_file='bern-output-1.csv'
+            )
+            self.assertIn('sig_figs=', ' '.join(cmd))
+            with self.assertRaises(ValueError):
+                CmdStanArgs(
+                    model_name='bernoulli',
+                    model_exe='bernoulli.exe',
+                    chain_ids=[1, 2, 3, 4],
+                    sig_figs=-1,
+                    method_args=sampler_args,
+                )
+            with self.assertRaises(ValueError):
+                CmdStanArgs(
+                    model_name='bernoulli',
+                    model_exe='bernoulli.exe',
+                    chain_ids=[1, 2, 3, 4],
+                    sig_figs=20,
+                    method_args=sampler_args,
+                )
+
 
 class GenerateQuantitesTest(unittest.TestCase):
     def test_args_fitted_params(self):
diff --git a/test/test_install_cmdstan.py b/test/test_install_cmdstan.py
index 69316d2..b3dca26 100644
--- a/test/test_install_cmdstan.py
+++ b/test/test_install_cmdstan.py
@@ -13,7 +13,6 @@ from cmdstanpy.install_cmdstan import (
 class InstallCmdStanTest(unittest.TestCase):
     def test_is_version_available(self):
         # check http error for bad version
-        self.assertTrue(is_version_available('2.24.1'))
         self.assertFalse(is_version_available('2.222.222-rc222'))
 
     def test_latest_version(self):
@@ -30,6 +29,10 @@ class InstallCmdStanTest(unittest.TestCase):
             CmdStanRetrieveError, 'not available from github.com'
         ):
             retrieve_version('no_such_version')
+        with self.assertRaises(ValueError):
+            retrieve_version(None)
+        with self.assertRaises(ValueError):
+            retrieve_version('')
 
 
 if __name__ == '__main__':
diff --git a/test/test_sample.py b/test/test_sample.py
index b1743e9..0b5aaf2 100644
--- a/test/test_sample.py
+++ b/test/test_sample.py
@@ -19,7 +19,7 @@ except ImportError:
 
 from cmdstanpy import _TMPDIR
 from cmdstanpy.cmdstan_args import Method, SamplerArgs, CmdStanArgs
-from cmdstanpy.utils import EXTENSION
+from cmdstanpy.utils import EXTENSION, cmdstan_version_at
 from cmdstanpy.stanfit import RunSet, CmdStanMCMC
 from cmdstanpy.model import CmdStanModel
 
@@ -1122,6 +1122,108 @@ class CmdStanMCMCTest(unittest.TestCase):
         self.assertEqual(len(bern_fit.stan_variable_dims), 1)
         self.assertEqual(bern_fit.metric_type, 'diag_e')
 
+    def test_validate_sample_sig_figs(self, stanfile='bernoulli.stan'):
+        if cmdstan_version_at(2, 25):
+            stan = os.path.join(DATAFILES_PATH, stanfile)
+            bern_model = CmdStanModel(stan_file=stan)
+
+            jdata = os.path.join(DATAFILES_PATH, 'bernoulli.data.json')
+            bern_fit = bern_model.sample(
+                data=jdata,
+                chains=1,
+                seed=12345,
+                iter_sampling=100,
+            )
+            bern_draws = bern_fit.draws()
+            theta = format(bern_draws[99, 0, 7], '.18g')
+            self.assertFalse(theta.startswith('0.21238045821757600'))
+
+            bern_fit_17 = bern_model.sample(
+                data=jdata,
+                chains=1,
+                seed=12345,
+                iter_sampling=100,
+                sig_figs=17,
+            )
+            bern_draws_17 = bern_fit_17.draws()
+            theta_17 = format(bern_draws_17[99, 0, 7], '.18g')
+            self.assertTrue(theta_17.startswith('0.212380458217576007'))
+            self.assertFalse(theta_17.startswith('0.212380457'))
+
+            bern_fit = bern_model.sample(
+                data=jdata,
+                chains=1,
+                seed=12345,
+                iter_sampling=100,
+                sig_figs=9,
+            )
+            bern_draws = bern_fit.draws()
+            theta_9 = format(bern_draws[99, 0, 7], '.18g')
+            self.assertTrue(theta_9.startswith('0.212380457'))
+
+            with self.assertRaises(ValueError):
+                bern_model.sample(
+                    data=jdata,
+                    chains=1,
+                    seed=12345,
+                    iter_sampling=100,
+                    sig_figs=27,
+                )
+                with self.assertRaises(ValueError):
+                    bern_model.sample(
+                        data=jdata,
+                        chains=1,
+                        seed=12345,
+                        iter_sampling=100,
+                        sig_figs=-1,
+                    )
+
+    def test_validate_summary_sig_figs(self):
+        # construct fit using existing sampler output
+        exe = os.path.join(DATAFILES_PATH, 'logistic' + EXTENSION)
+        rdata = os.path.join(DATAFILES_PATH, 'logistic.data.R')
+        sampler_args = SamplerArgs(iter_sampling=100)
+        cmdstan_args = CmdStanArgs(
+            model_name='logistic',
+            model_exe=exe,
+            chain_ids=[1, 2, 3, 4],
+            seed=12345,
+            data=rdata,
+            output_dir=DATAFILES_PATH,
+            sig_figs=17,
+            method_args=sampler_args,
+        )
+        runset = RunSet(args=cmdstan_args)
+        runset._csv_files = [
+            os.path.join(DATAFILES_PATH, 'logistic_output_1.csv'),
+            os.path.join(DATAFILES_PATH, 'logistic_output_2.csv'),
+            os.path.join(DATAFILES_PATH, 'logistic_output_3.csv'),
+            os.path.join(DATAFILES_PATH, 'logistic_output_4.csv'),
+        ]
+        retcodes = runset._retcodes
+        for i in range(len(retcodes)):
+            runset._set_retcode(i, 0)
+        self.assertTrue(runset._check_retcodes())
+        fit = CmdStanMCMC(runset)
+
+        sum_default = fit.summary()
+        beta1_default = format(sum_default.iloc[1, 0], '.18g')
+        self.assertTrue(beta1_default.startswith('1.3'))
+
+        if cmdstan_version_at(2, 25):
+            sum_17 = fit.summary(sig_figs=17)
+            beta1_17 = format(sum_17.iloc[1, 0], '.18g')
+            self.assertTrue(beta1_17.startswith('1.345767078273258'))
+
+            sum_10 = fit.summary(sig_figs=10)
+            beta1_10 = format(sum_10.iloc[1, 0], '.18g')
+            self.assertTrue(beta1_10.startswith('1.34576707'))
+
+        with self.assertRaises(ValueError):
+            fit.summary(sig_figs=20)
+        with self.assertRaises(ValueError):
+            fit.summary(sig_figs=-1)
+
 
 if __name__ == '__main__':
     unittest.main()
diff --git a/test/test_utils.py b/test/test_utils.py
index fdb2ed4..8bfaf80 100644
--- a/test/test_utils.py
+++ b/test/test_utils.py
@@ -15,6 +15,7 @@ import numpy as np
 from cmdstanpy import _TMPDIR, _DOT_CMDSTAN, _DOT_CMDSTANPY
 from cmdstanpy.utils import (
     cmdstan_path,
+    cmdstan_version_at,
     set_cmdstan_path,
     validate_cmdstan_path,
     get_latest_cmdstan,
@@ -170,6 +171,16 @@ class CmdStanPathTest(unittest.TestCase):
         self.assertEqual(get_latest_cmdstan(tdir), 'cmdstan-2.22.0')
         shutil.rmtree(tdir, ignore_errors=True)
 
+    def test_cmdstan_version_at(self):
+        cmdstan_path()  # sets os.environ['CMDSTAN']
+        good_path = os.environ['CMDSTAN']
+        del os.environ['CMDSTAN']
+        os.environ['CMDSTAN'] = os.path.join(
+            os.path.dirname(good_path), 'cmdstan-2.24.1'
+        )
+        self.assertTrue(cmdstan_version_at(2, 24))
+        self.assertFalse(cmdstan_version_at(2, 25))
+
     def test_dict_to_file(self):
         file_good = os.path.join(DATAFILES_PATH, 'bernoulli_output_1.csv')
         dict_good = {'a': 0.5}