Skip to contents

extract2() provides an object-oriented interface to the posterior samples extracted from a Stan model. In particular, high dimensional parameters (i.e., vectors, matrices, and arrays) are gathered into arrays of corresponding dimensions in R. These restructured high dimensional parameters, as well as other scalar parameters, are exposed as public methods in the returned R6 object. See below for an example.

Usage

extract2(fit, ...)

Arguments

fit

A CmdStanFit object passed to extract().

...

Arguments passed to extract().

Value

An R6, postParams object.

Examples

fp_mod = system.file("cases", "treatment_dynamics", "1-simplified-normal-model", "m1.RDS", package="stom")
m = readRDS(fp_mod)  # CmdStanFit model cache
post = extract2(m)
str(post)
#> Classes 'postParams', 'R6' <postParams>
#>   Public:
#>     .chain: function (idx = NULL) 
#>     .draw: function (idx = NULL) 
#>     .iteration: function (idx = NULL) 
#>     B_AD: function (idx = NULL) 
#>     B_AE: function (idx = NULL) 
#>     B_ED: function (idx = NULL) 
#>     B_TD: function (idx = NULL) 
#>     B_TE: function (idx = NULL) 
#>     E: function (idx = NULL) 
#>     E_raw: function (idx = NULL) 
#>     I: function (idx = NULL) 
#>     alpha: function (idx = NULL) 
#>     clone: function (deep = FALSE) 
#>     gamma: function (idx = NULL) 
#>     initialize: function (post, par_info) 
#>     kappa: function (idx = NULL) 
#>     lp__: function (idx = NULL) 
#>     sigma_D: function (idx = NULL) 
#>     sigma_ET: function (idx = NULL) 
#>     sigma_I: function (idx = NULL) 
#>     zI_raw: function (idx = NULL) 
#>   Private:
#>     .cache: list
#>     .par_info: list
#>     .post: draws_df, draws, tbl_df, tbl, data.frame
#>     add_function: function (name, meth) 
#>     get_param: function (p)  

post$B_AD() |> str()
#>  num [1:3000] 0.7 0.662 0.87 0.693 0.543 ...
post$B_TE() |> str()
#> List of 3000
#>  $ : num [1:3(1d)] 0.651 0.922 1.687
#>  $ : num [1:3(1d)] 0.609 0.707 1.697
#>  $ : num [1:3(1d)] 0.521 0.808 1.59
#>  $ : num [1:3(1d)] 0.689 0.741 1.839
#>  $ : num [1:3(1d)] 0.559 0.936 1.905
#>  $ : num [1:3(1d)] 0.556 0.901 1.878
#>  $ : num [1:3(1d)] 0.659 0.829 1.807
#>  $ : num [1:3(1d)] 0.713 0.525 1.406
#>  $ : num [1:3(1d)] 0.538 0.695 1.596
#>  $ : num [1:3(1d)] 0.66 0.601 1.527
#>  $ : num [1:3(1d)] 0.312 0.766 1.486
#>  $ : num [1:3(1d)] 0.524 0.623 1.622
#>  $ : num [1:3(1d)] 0.404 0.802 1.547
#>  $ : num [1:3(1d)] 0.61 0.866 1.644
#>  $ : num [1:3(1d)] 0.48 0.47 1.55
#>  $ : num [1:3(1d)] 0.564 0.918 1.583
#>  $ : num [1:3(1d)] 0.551 0.797 1.594
#>  $ : num [1:3(1d)] 0.484 0.525 1.362
#>  $ : num [1:3(1d)] 0.49 0.694 1.673
#>  $ : num [1:3(1d)] 0.593 0.658 1.456
#>  $ : num [1:3(1d)] 0.623 0.783 1.833
#>  $ : num [1:3(1d)] 0.575 0.757 1.8
#>  $ : num [1:3(1d)] 0.501 0.552 1.466
#>  $ : num [1:3(1d)] 0.558 0.542 1.509
#>  $ : num [1:3(1d)] 0.53 0.836 1.626
#>  $ : num [1:3(1d)] 0.196 0.655 1.681
#>  $ : num [1:3(1d)] 0.54 0.907 1.626
#>  $ : num [1:3(1d)] 0.658 0.731 1.714
#>  $ : num [1:3(1d)] 0.492 0.581 1.429
#>  $ : num [1:3(1d)] 0.395 0.844 1.642
#>  $ : num [1:3(1d)] 0.499 0.6 1.54
#>  $ : num [1:3(1d)] 0.288 0.512 1.589
#>  $ : num [1:3(1d)] 0.54 0.629 1.512
#>  $ : num [1:3(1d)] 0.487 0.618 1.475
#>  $ : num [1:3(1d)] 0.486 0.586 1.446
#>  $ : num [1:3(1d)] 0.47 0.613 1.447
#>  $ : num [1:3(1d)] 0.407 0.657 1.445
#>  $ : num [1:3(1d)] 0.583 0.689 1.602
#>  $ : num [1:3(1d)] 0.469 0.78 1.64
#>  $ : num [1:3(1d)] 0.368 0.513 1.486
#>  $ : num [1:3(1d)] 0.756 0.882 1.728
#>  $ : num [1:3(1d)] 0.707 0.891 1.687
#>  $ : num [1:3(1d)] 0.7 0.837 1.706
#>  $ : num [1:3(1d)] 0.459 0.73 1.544
#>  $ : num [1:3(1d)] 0.439 0.676 1.77
#>  $ : num [1:3(1d)] 0.526 0.599 1.515
#>  $ : num [1:3(1d)] 0.484 0.666 1.673
#>  $ : num [1:3(1d)] 0.399 0.756 1.548
#>  $ : num [1:3(1d)] 0.547 0.624 1.601
#>  $ : num [1:3(1d)] 0.617 0.884 1.717
#>  $ : num [1:3(1d)] 0.374 0.681 1.318
#>  $ : num [1:3(1d)] 0.436 0.726 1.488
#>  $ : num [1:3(1d)] 0.365 0.643 1.576
#>  $ : num [1:3(1d)] 0.402 0.652 1.593
#>  $ : num [1:3(1d)] 0.468 0.896 1.693
#>  $ : num [1:3(1d)] 0.547 0.689 1.644
#>  $ : num [1:3(1d)] 0.523 0.654 1.579
#>  $ : num [1:3(1d)] 0.491 0.774 1.632
#>  $ : num [1:3(1d)] 0.634 0.629 1.645
#>  $ : num [1:3(1d)] 0.566 0.775 1.625
#>  $ : num [1:3(1d)] 0.453 0.597 1.685
#>  $ : num [1:3(1d)] 0.355 0.635 1.416
#>  $ : num [1:3(1d)] 0.282 0.608 1.492
#>  $ : num [1:3(1d)] 0.354 0.559 1.516
#>  $ : num [1:3(1d)] 0.275 0.583 1.553
#>  $ : num [1:3(1d)] 0.374 0.603 1.552
#>  $ : num [1:3(1d)] 0.552 0.878 1.763
#>  $ : num [1:3(1d)] 0.44 0.577 1.677
#>  $ : num [1:3(1d)] 0.48 0.799 1.535
#>  $ : num [1:3(1d)] 0.436 0.445 1.563
#>  $ : num [1:3(1d)] 0.362 0.531 1.555
#>  $ : num [1:3(1d)] 0.452 0.758 1.654
#>  $ : num [1:3(1d)] 0.512 0.642 1.633
#>  $ : num [1:3(1d)] 0.481 0.798 1.705
#>  $ : num [1:3(1d)] 0.415 0.547 1.552
#>  $ : num [1:3(1d)] 0.571 0.726 1.806
#>  $ : num [1:3(1d)] 0.457 0.655 1.495
#>  $ : num [1:3(1d)] 0.5 0.633 1.635
#>  $ : num [1:3(1d)] 0.402 0.758 1.666
#>  $ : num [1:3(1d)] 0.48 0.809 1.698
#>  $ : num [1:3(1d)] 0.339 0.757 1.517
#>  $ : num [1:3(1d)] 0.371 0.743 1.563
#>  $ : num [1:3(1d)] 0.5 0.75 1.53
#>  $ : num [1:3(1d)] 0.542 0.752 1.721
#>  $ : num [1:3(1d)] 0.467 0.738 1.703
#>  $ : num [1:3(1d)] 0.432 0.652 1.676
#>  $ : num [1:3(1d)] 0.583 0.883 1.629
#>  $ : num [1:3(1d)] 0.38 0.508 1.424
#>  $ : num [1:3(1d)] 0.543 0.833 1.74
#>  $ : num [1:3(1d)] 0.398 0.673 1.39
#>  $ : num [1:3(1d)] 0.604 0.709 1.562
#>  $ : num [1:3(1d)] 0.52 0.901 1.581
#>  $ : num [1:3(1d)] 0.524 0.734 1.534
#>  $ : num [1:3(1d)] 0.503 0.883 1.564
#>  $ : num [1:3(1d)] 0.502 0.671 1.618
#>  $ : num [1:3(1d)] 0.599 0.835 1.723
#>  $ : num [1:3(1d)] 0.461 0.736 1.65
#>  $ : num [1:3(1d)] 0.535 0.736 1.643
#>  $ : num [1:3(1d)] 0.5 0.662 1.543
#>   [list output truncated]
post$E() |> str()
#> List of 3000
#>  $ : num [1:30, 1:4] -1.62 -2.13 -3.78 -1.37 -2.9 ...
#>  $ : num [1:30, 1:4] -0.34 -0.439 -3.138 -2.625 -1.887 ...
#>  $ : num [1:30, 1:4] -1.31 -1.59 -3.44 -1.83 -1.73 ...
#>  $ : num [1:30, 1:4] -0.852 -0.757 -2.589 -1.83 -2.185 ...
#>  $ : num [1:30, 1:4] -1.753 -0.656 -3.35 -1.891 -1.983 ...
#>  $ : num [1:30, 1:4] -1.632 -0.703 -3.208 -1.953 -2.077 ...
#>  $ : num [1:30, 1:4] -1.51 -1.17 -3.35 -2.17 -2.1 ...
#>  $ : num [1:30, 1:4] -0.0849 -1.1387 -3.2079 -1.9074 -3.2873 ...
#>  $ : num [1:30, 1:4] -1.63 -1.11 -3.42 -1.89 -1.23 ...
#>  $ : num [1:30, 1:4] -0.193 -1.402 -3.193 -1.739 -2.971 ...
#>  $ : num [1:30, 1:4] -1.573 -0.826 -3.591 -1.695 -1.496 ...
#>  $ : num [1:30, 1:4] -0.157 -1.466 -2.985 -1.906 -2.772 ...
#>  $ : num [1:30, 1:4] -0.786 -1.094 -3.482 -1.621 -2.465 ...
#>  $ : num [1:30, 1:4] -0.527 -1.304 -3.394 -2.155 -1.558 ...
#>  $ : num [1:30, 1:4] -0.792 -0.818 -2.652 -1.843 -2.525 ...
#>  $ : num [1:30, 1:4] -0.811 -1.492 -4.274 -1.906 -1.719 ...
#>  $ : num [1:30, 1:4] -1.065 -0.883 -2.585 -1.942 -2.681 ...
#>  $ : num [1:30, 1:4] -0.652 -1.522 -3.776 -1.736 -1.586 ...
#>  $ : num [1:30, 1:4] -1.048 -0.819 -2.582 -1.849 -2.633 ...
#>  $ : num [1:30, 1:4] -0.528 -1.13 -3.477 -1.372 -2.153 ...
#>  $ : num [1:30, 1:4] -1.4 -1.43 -3.48 -2.1 -2.23 ...
#>  $ : num [1:30, 1:4] -1.24 -1.28 -3.41 -1.96 -2.13 ...
#>  $ : num [1:30, 1:4] -0.699 -1.128 -2.879 -1.731 -2.509 ...
#>  $ : num [1:30, 1:4] -0.937 -1.29 -2.895 -1.98 -2.221 ...
#>  $ : num [1:30, 1:4] -1 -1.4 -2.85 -1.3 -2.81 ...
#>  $ : num [1:30, 1:4] -0.489 -1.135 -3.656 -2.497 -1.799 ...
#>  $ : num [1:30, 1:4] -1.36 -1.29 -3.02 -1.3 -2.67 ...
#>  $ : num [1:30, 1:4] -0.431 -1.475 -3.003 -1.933 -1.682 ...
#>  $ : num [1:30, 1:4] -1.12 -1.07 -3.36 -1.67 -2.5 ...
#>  $ : num [1:30, 1:4] -0.948 -1.397 -3.561 -2.184 -1.74 ...
#>  $ : num [1:30, 1:4] -1.05 -1.16 -3.97 -1.8 -1.23 ...
#>  $ : num [1:30, 1:4] -0.576 -1.415 -2.609 -1.414 -2.843 ...
#>  $ : num [1:30, 1:4] -0.736 -0.946 -3.273 -2.348 -2.079 ...
#>  $ : num [1:30, 1:4] -1.01 -1.26 -3.45 -1.2 -2.04 ...
#>  $ : num [1:30, 1:4] -1.01 -1.32 -3.41 -1.34 -2.09 ...
#>  $ : num [1:30, 1:4] -0.852 -1.328 -3.131 -1.122 -2.023 ...
#>  $ : num [1:30, 1:4] -1.044 -0.834 -3.396 -2.381 -2.16 ...
#>  $ : num [1:30, 1:4] -0.884 -1.537 -3.168 -1.299 -2.053 ...
#>  $ : num [1:30, 1:4] -0.882 -0.858 -3.327 -2.155 -2.568 ...
#>  $ : num [1:30, 1:4] -0.919 -1.587 -3.151 -1.552 -1.89 ...
#>  $ : num [1:30, 1:4] -0.966 -0.919 -3.344 -2.199 -2.412 ...
#>  $ : num [1:30, 1:4] -1.175 -0.737 -2.896 -2.225 -1.879 ...
#>  $ : num [1:30, 1:4] -1.258 -0.639 -3.521 -2.097 -2.308 ...
#>  $ : num [1:30, 1:4] -0.551 -1.863 -3.125 -1.701 -2.304 ...
#>  $ : num [1:30, 1:4] -1.1 -1.18 -3.27 -2.11 -2.46 ...
#>  $ : num [1:30, 1:4] -0.689 -0.39 -2.511 -1.562 -1.835 ...
#>  $ : num [1:30, 1:4] -1.12 -2.07 -4.06 -1.98 -2.52 ...
#>  $ : num [1:30, 1:4] -1.21 -1.18 -3.83 -2.03 -2.39 ...
#>  $ : num [1:30, 1:4] -0.471 -1.546 -3.313 -1.748 -1.882 ...
#>  $ : num [1:30, 1:4] -1.42 -1.29 -3.38 -2.29 -2.16 ...
#>  $ : num [1:30, 1:4] -0.761 -1.201 -3.122 -1.752 -2.726 ...
#>  $ : num [1:30, 1:4] -0.415 -1.098 -3.267 -1.766 -2.174 ...
#>  $ : num [1:30, 1:4] -1.21 -1.15 -3.26 -1.82 -2.16 ...
#>  $ : num [1:30, 1:4] -0.86 -1.49 -2.72 -1.55 -2.37 ...
#>  $ : num [1:30, 1:4] -0.897 -0.696 -3.674 -2.119 -2.079 ...
#>  $ : num [1:30, 1:4] -0.936 -1.317 -3.013 -1.321 -1.741 ...
#>  $ : num [1:30, 1:4] -1.02 -1.83 -3.5 -1.8 -1.89 ...
#>  $ : num [1:30, 1:4] -0.81 -0.55 -3.13 -1.81 -2.42 ...
#>  $ : num [1:30, 1:4] -0.943 -1.859 -3.697 -1.793 -1.909 ...
#>  $ : num [1:30, 1:4] -0.856 -1.275 -2.846 -2.051 -2.426 ...
#>  $ : num [1:30, 1:4] -1.06 -1.28 -4.16 -1.61 -1.91 ...
#>  $ : num [1:30, 1:4] -0.895 -0.452 -2.246 -2.261 -2.21 ...
#>  $ : num [1:30, 1:4] -0.855 -0.785 -2.396 -2.369 -2.294 ...
#>  $ : num [1:30, 1:4] -1.02 -1.62 -3.56 -1.99 -2.18 ...
#>  $ : num [1:30, 1:4] -1.03 -1.29 -3.88 -2.09 -2.3 ...
#>  $ : num [1:30, 1:4] -1.192 -0.736 -3.95 -2.238 -1.373 ...
#>  $ : num [1:30, 1:4] -0.371 -1.472 -2.722 -1.459 -2.839 ...
#>  $ : num [1:30, 1:4] -1.75 -1.17 -4.57 -2.23 -2.08 ...
#>  $ : num [1:30, 1:4] -0.0985 -1.075 -2.1892 -1.629 -2.1368 ...
#>  $ : num [1:30, 1:4] -1.67 -1.32 -4.33 -1.9 -2.09 ...
#>  $ : num [1:30, 1:4] -0.695 -1.049 -3.883 -2.133 -2.194 ...
#>  $ : num [1:30, 1:4] -1.2 -1.21 -2.56 -1.56 -2.83 ...
#>  $ : num [1:30, 1:4] -0.627 -1.206 -4.051 -2.178 -1.558 ...
#>  $ : num [1:30, 1:4] -1.26 -1.28 -2.6 -1.69 -3.04 ...
#>  $ : num [1:30, 1:4] -0.737 -1.357 -3.313 -1.516 -2.517 ...
#>  $ : num [1:30, 1:4] -0.727 -0.9 -3.1 -2.178 -1.733 ...
#>  $ : num [1:30, 1:4] -1.25 -1.65 -3.69 -1.63 -2.74 ...
#>  $ : num [1:30, 1:4] -0.408 -0.471 -2.732 -2.124 -1.831 ...
#>  $ : num [1:30, 1:4] -0.145 -0.612 -3.008 -1.987 -1.943 ...
#>  $ : num [1:30, 1:4] -1.11 -1.81 -3.88 -2.42 -1.82 ...
#>  $ : num [1:30, 1:4] -0.986 -0.766 -3.086 -1.728 -2.304 ...
#>  $ : num [1:30, 1:4] -1.005 -0.339 -2.91 -2.057 -1.562 ...
#>  $ : num [1:30, 1:4] -0.548 -1.998 -3.48 -1.47 -2.708 ...
#>  $ : num [1:30, 1:4] -1.257 -0.455 -3.175 -1.612 -1.371 ...
#>  $ : num [1:30, 1:4] -0.609 -1.686 -3.241 -2.453 -2.318 ...
#>  $ : num [1:30, 1:4] -0.427 -1.467 -3.321 -2.607 -2.519 ...
#>  $ : num [1:30, 1:4] -1.31 -1.98 -3.25 -1.64 -2.56 ...
#>  $ : num [1:30, 1:4] -0.659 -0.859 -3.117 -2.616 -1.913 ...
#>  $ : num [1:30, 1:4] -1.33 -1.8 -3.34 -1.73 -2.4 ...
#>  $ : num [1:30, 1:4] -1.07 -1.87 -3.26 -1.63 -2.2 ...
#>  $ : num [1:30, 1:4] -1.33 -1.24 -3.41 -1.79 -2.02 ...
#>  $ : num [1:30, 1:4] -0.601 -1.247 -3.394 -2.029 -2.559 ...
#>  $ : num [1:30, 1:4] -1.21 -1.33 -3.3 -1.84 -1.94 ...
#>  $ : num [1:30, 1:4] -0.685 -1.148 -3.481 -2.18 -2.494 ...
#>  $ : num [1:30, 1:4] -0.777 -1.37 -3.54 -1.794 -1.966 ...
#>  $ : num [1:30, 1:4] -1.456 -0.434 -3.003 -2.351 -1.941 ...
#>  $ : num [1:30, 1:4] -1.11 -1.73 -3.38 -1.89 -3.52 ...
#>  $ : num [1:30, 1:4] -0.789 -0.713 -3.335 -1.924 -1.157 ...
#>  $ : num [1:30, 1:4] -0.971 -1.896 -3.284 -1.158 -3.029 ...
#>   [list output truncated]