Shredder R package for rstan

We have developed an R package called {shredder} that uses tidy-like verbs to manipulate stanfit objects.

The general idea is to create task specific workflows that promote readability, iteration and exploration without forcing the user to convert fit objects to a rectangular shape to post-process in R.

an example would be:

rats <- shredder::rats_example()

rats%>%
  shredder::stan_select(mu_alpha)%>%
  shredder::stan_sample_frac(0.5)

#> Inference for Stan model: rats.
#> 4 chains, each with iter=1500; warmup=1000; thin=1; 
#> post-warmup draws per chain=500, total post-warmup draws=2000.
#> 
#>            mean se_mean   sd   2.5%    25%    50%    75%  97.5% n_eff Rhat
#> mu_alpha 242.49    0.06 2.74 237.01 240.78 242.56 244.26 247.76  2005    1
#> 
#> Samples were drawn using  at Thu Dec 12 04:01:52 2019.
#> For each parameter, n_eff is a crude measure of effective sample size,
#> and Rhat is the potential scale reduction factor on split chains (at 
#> convergence, Rhat=1).

The current manipulation verbs includes

Dimension

  • chains
    • shredder::stan_retain : extract specific chains
  • pars
    • shredder::stan_select : extract specific pars
    • shredder::stan_contains , shredder::stan_starts_with , shredder::stan_ends_with : partial par extractions (used within shredder::stan_select )
    • shredder::stan_names : return names within the stanfit object
  • post-warmup samples
    • shredder::stan_slice : extract specific samples by index
    • shredder::stan_sample_n : extract random n samples
    • shredder::stan_sample_frac : extract fraction of total samples
    • shredder::stan_filter : extract subset of samples conditional on filter of parameter values

Any feedback on the idea or collaboration is welcome as we develop this package going forward.

Thanks!

8 Likes

Would be great to show some examples.

Seems to have some overlap with the posterior package https://github.com/jgabry/posterior ? Join the forces?

4 Likes

Thank you for the link.

I have seen {posterior} before. It looks very good, from the authors of the package I thought it was geared to be tidybayes 2.0 type of package. shredder was built to integrate with tidybayes originally, it was used in this capacity. Obviously, would be excited to collaborate with @jonah on integrating and improving upon the initial development.

I think the main difference between the two is that shredder’s input is stanfit and returns stanfit objects, while tidybayes/posterior inputs stanfit and return an R S3 data.frame/tibble/matrix. We found that there are many diagnostics and post-processing routines that input stanfit objects, creating the need to manipulate the original fit object, but retain the integrity of the stanfit class.

1 Like

A few examples of what the basic stanfit manipulation {shredder} can do (from this pkgdown article)

library(shredder)
library(rstan)

rats <- shredder::rats_example(nCores = 1)

rats
Standard Output
Inference for Stan model: rats.
4 chains, each with iter=2000; warmup=1000; thin=1; 
post-warmup draws per chain=1000, total post-warmup draws=4000.

                 mean se_mean    sd    2.5%     25%     50%     75%   97.5% n_eff Rhat
alpha[1]       239.94    0.03  2.65  234.72  238.13  239.94  241.73  245.15  7024    1
alpha[2]       247.80    0.04  2.74  242.30  246.01  247.86  249.64  253.05  6023    1
alpha[3]       252.44    0.04  2.58  247.22  250.74  252.43  254.13  257.50  5059    1
alpha[4]       232.60    0.03  2.71  227.23  230.81  232.61  234.38  237.94  7017    1
alpha[5]       231.64    0.03  2.69  226.32  229.85  231.62  233.46  236.90  6477    1
alpha[6]       249.75    0.04  2.65  244.39  248.04  249.75  251.49  255.06  5331    1
alpha[7]       228.70    0.03  2.69  223.51  226.94  228.64  230.42  234.05  7721    1
alpha[8]       248.33    0.04  2.65  243.23  246.52  248.28  250.12  253.61  5596    1
alpha[9]       283.27    0.04  2.68  277.83  281.53  283.28  285.08  288.40  5129    1
alpha[10]      219.27    0.03  2.62  213.97  217.53  219.26  221.05  224.29  6879    1
alpha[11]      258.26    0.03  2.71  252.87  256.49  258.27  260.03  263.85  6760    1
alpha[12]      228.14    0.03  2.74  222.81  226.28  228.09  229.98  233.68  7475    1
alpha[13]      242.41    0.03  2.71  237.15  240.63  242.41  244.15  247.83  6268    1
alpha[14]      268.28    0.04  2.74  262.85  266.42  268.30  270.08  273.56  6108    1
alpha[15]      242.79    0.04  2.69  237.54  241.00  242.82  244.60  248.01  5881    1
alpha[16]      245.30    0.03  2.64  240.14  243.58  245.29  247.01  250.63  6282    1
alpha[17]      232.21    0.04  2.68  226.95  230.44  232.21  233.99  237.44  5517    1
alpha[18]      240.47    0.03  2.72  235.21  238.65  240.47  242.28  245.80  6733    1
alpha[19]      253.76    0.04  2.68  248.54  252.00  253.79  255.54  259.13  5846    1
alpha[20]      241.68    0.03  2.70  236.43  239.86  241.68  243.50  246.96  6563    1
alpha[21]      248.52    0.04  2.67  243.26  246.71  248.56  250.26  253.88  5708    1
alpha[22]      225.29    0.03  2.62  220.21  223.53  225.30  227.03  230.43  6554    1
alpha[23]      228.52    0.03  2.71  223.31  226.76  228.52  230.31  233.96  7679    1
alpha[24]      245.13    0.04  2.64  239.73  243.39  245.12  246.86  250.35  5278    1
alpha[25]      234.51    0.03  2.60  229.37  232.81  234.48  236.24  239.55  5746    1
alpha[26]      254.00    0.03  2.66  248.81  252.22  254.02  255.77  259.24  6521    1
alpha[27]      254.33    0.03  2.65  249.18  252.47  254.30  256.17  259.45  7077    1
alpha[28]      243.00    0.04  2.65  237.95  241.27  243.02  244.68  248.30  5487    1
alpha[29]      217.90    0.03  2.70  212.52  216.02  217.86  219.73  223.26  6188    1
alpha[30]      241.38    0.03  2.60  236.25  239.60  241.41  243.14  246.33  6561    1
beta[1]          6.06    0.00  0.24    5.60    5.90    6.06    6.22    6.52  6351    1
beta[2]          7.05    0.00  0.26    6.54    6.88    7.05    7.22    7.54  6081    1
beta[3]          6.48    0.00  0.24    6.02    6.32    6.49    6.64    6.95  5675    1
beta[4]          5.34    0.00  0.26    4.82    5.17    5.34    5.52    5.85  5389    1
beta[5]          6.57    0.00  0.24    6.10    6.40    6.57    6.72    7.03  5753    1
beta[6]          6.18    0.00  0.24    5.69    6.01    6.18    6.34    6.67  5846    1
beta[7]          5.98    0.00  0.24    5.50    5.81    5.97    6.14    6.45  6277    1
beta[8]          6.42    0.00  0.25    5.93    6.25    6.42    6.58    6.91  5725    1
beta[9]          7.06    0.00  0.26    6.56    6.88    7.06    7.23    7.55  5306    1
beta[10]         5.85    0.00  0.24    5.37    5.69    5.85    6.02    6.32  5511    1
beta[11]         6.80    0.00  0.25    6.31    6.63    6.80    6.97    7.29  5720    1
beta[12]         6.12    0.00  0.25    5.63    5.95    6.12    6.29    6.60  5937    1
beta[13]         6.16    0.00  0.24    5.69    6.00    6.16    6.33    6.61  6602    1
beta[14]         6.69    0.00  0.25    6.20    6.52    6.69    6.86    7.17  6294    1
beta[15]         5.42    0.00  0.24    4.93    5.26    5.42    5.58    5.89  5773    1
beta[16]         5.93    0.00  0.24    5.44    5.76    5.93    6.08    6.40  6010    1
beta[17]         6.27    0.00  0.23    5.82    6.12    6.27    6.43    6.73  4764    1
beta[18]         5.84    0.00  0.25    5.35    5.68    5.85    6.01    6.34  5926    1
beta[19]         6.41    0.00  0.24    5.94    6.24    6.41    6.56    6.88  6205    1
beta[20]         6.05    0.00  0.24    5.59    5.90    6.05    6.21    6.51  6409    1
beta[21]         6.41    0.00  0.25    5.92    6.24    6.41    6.57    6.89  6100    1
beta[22]         5.86    0.00  0.23    5.41    5.70    5.86    6.01    6.31  6723    1
beta[23]         5.75    0.00  0.24    5.28    5.58    5.74    5.90    6.21  5846    1
beta[24]         5.89    0.00  0.24    5.42    5.73    5.89    6.05    6.37  6067    1
beta[25]         6.91    0.00  0.26    6.40    6.74    6.91    7.09    7.42  5229    1
beta[26]         6.55    0.00  0.24    6.08    6.39    6.55    6.71    7.02  5256    1
beta[27]         5.90    0.00  0.24    5.42    5.73    5.90    6.06    6.37  6120    1
beta[28]         5.85    0.00  0.24    5.37    5.68    5.85    6.01    6.32  5674    1
beta[29]         5.67    0.00  0.24    5.19    5.51    5.67    5.83    6.15  7156    1
beta[30]         6.14    0.00  0.25    5.66    5.97    6.14    6.30    6.62  6008    1
mu_alpha       242.45    0.04  2.68  237.17  240.65  242.43  244.22  247.79  5295    1
mu_beta          6.19    0.00  0.11    5.98    6.11    6.19    6.26    6.40  4302    1
sigmasq_y       37.19    0.13  5.68   27.60   33.20   36.71   40.67   49.83  1942    1
sigmasq_alpha  216.80    1.00 63.46  124.16  173.10  205.47  249.85  371.18  4027    1
sigmasq_beta     0.27    0.00  0.10    0.13    0.21    0.26    0.33    0.51  3640    1
sigma_y          6.08    0.01  0.46    5.25    5.76    6.06    6.38    7.06  1963    1
sigma_alpha     14.58    0.03  2.06   11.14   13.16   14.33   15.81   19.27  4324    1
sigma_beta       0.52    0.00  0.09    0.36    0.45    0.51    0.57    0.72  3579    1
alpha0         106.36    0.05  3.53   99.55  104.01  106.36  108.69  113.32  4815    1
lp__          -438.05    0.23  7.05 -453.46 -442.45 -437.57 -433.16 -425.80   978    1

Samples were drawn using NUTS(diag_e) at Fri Dec 13 08:38:41 2019.
For each parameter, n_eff is a crude measure of effective sample size,
and Rhat is the potential scale reduction factor on split chains (at 
convergence, Rhat=1).

The Stan Script
data {
  int<lower=0> N;
  int<lower=0> T;
  real x[T];
  real y[N,T];
  real xbar;
}
parameters {
  real alpha[N];
  real beta[N];

  real mu_alpha;
  real mu_beta;          // beta.c in original bugs model

  real<lower=0> sigmasq_y;
  real<lower=0> sigmasq_alpha;
  real<lower=0> sigmasq_beta;
}
transformed parameters {
  real<lower=0> sigma_y;       // sigma in original bugs model
  real<lower=0> sigma_alpha;
  real<lower=0> sigma_beta;

  sigma_y = sqrt(sigmasq_y);
  sigma_alpha = sqrt(sigmasq_alpha);
  sigma_beta = sqrt(sigmasq_beta);
}
model {
  mu_alpha ~ normal(0, 100);
  mu_beta ~ normal(0, 100);
  sigmasq_y ~ inv_gamma(0.001, 0.001);
  sigmasq_alpha ~ inv_gamma(0.001, 0.001);
  sigmasq_beta ~ inv_gamma(0.001, 0.001);
  alpha ~ normal(mu_alpha, sigma_alpha); // vectorized
  beta ~ normal(mu_beta, sigma_beta);  // vectorized
  for (n in 1:N)
    for (t in 1:T) 
      y[n,t] ~ normal(alpha[n] + beta[n] * (x[t] - xbar), sigma_y);

}
generated quantities {
  real alpha0;
  alpha0 = mu_alpha - xbar * mu_beta;
}

Pars

Names

rats%>%
  stan_names()

 [1] "alpha"         "beta"          "mu_alpha"      "mu_beta"       "sigmasq_y"    
 [6] "sigmasq_alpha" "sigmasq_beta"  "sigma_y"       "sigma_alpha"   "sigma_beta"   
[11] "alpha0"        "lp__"         

rats%>%
  stan_names(expand = TRUE)

 [1] "alpha[1]"      "alpha[2]"      "alpha[3]"      "alpha[4]"      "alpha[5]"     
 [6] "alpha[6]"      "alpha[7]"      "alpha[8]"      "alpha[9]"      "alpha[10]"    
[11] "alpha[11]"     "alpha[12]"     "alpha[13]"     "alpha[14]"     "alpha[15]"    
[16] "alpha[16]"     "alpha[17]"     "alpha[18]"     "alpha[19]"     "alpha[20]"    
[21] "alpha[21]"     "alpha[22]"     "alpha[23]"     "alpha[24]"     "alpha[25]"    
[26] "alpha[26]"     "alpha[27]"     "alpha[28]"     "alpha[29]"     "alpha[30]"    
[31] "beta[1]"       "beta[2]"       "beta[3]"       "beta[4]"       "beta[5]"      
[36] "beta[6]"       "beta[7]"       "beta[8]"       "beta[9]"       "beta[10]"     
[41] "beta[11]"      "beta[12]"      "beta[13]"      "beta[14]"      "beta[15]"     
[46] "beta[16]"      "beta[17]"      "beta[18]"      "beta[19]"      "beta[20]"     
[51] "beta[21]"      "beta[22]"      "beta[23]"      "beta[24]"      "beta[25]"     
[56] "beta[26]"      "beta[27]"      "beta[28]"      "beta[29]"      "beta[30]"     
[61] "mu_alpha"      "mu_beta"       "sigmasq_y"     "sigmasq_alpha" "sigmasq_beta" 
[66] "sigma_y"       "sigma_alpha"   "sigma_beta"    "alpha0"        "lp__"         

Select

rats%>%
  stan_select(mu_alpha)

Inference for Stan model: rats.
4 chains, each with iter=2000; warmup=1000; thin=1; 
post-warmup draws per chain=1000, total post-warmup draws=4000.

           mean se_mean   sd   2.5%    25%    50%    75%  97.5% n_eff Rhat
mu_alpha 242.45    0.04 2.68 237.17 240.65 242.43 244.22 247.79  5295    1

Samples were drawn using  at Fri Dec 13 08:38:41 2019.
For each parameter, n_eff is a crude measure of effective sample size,
and Rhat is the potential scale reduction factor on split chains (at 
convergence, Rhat=1).

rats%>%
  stan_select(mu_alpha,mu_beta)

Inference for Stan model: rats.
4 chains, each with iter=2000; warmup=1000; thin=1; 
post-warmup draws per chain=1000, total post-warmup draws=4000.

           mean se_mean   sd   2.5%    25%    50%    75%  97.5% n_eff Rhat
mu_alpha 242.45    0.04 2.68 237.17 240.65 242.43 244.22 247.79  5295    1
mu_beta    6.19    0.00 0.11   5.98   6.11   6.19   6.26   6.40  4302    1

Samples were drawn using  at Fri Dec 13 08:38:41 2019.
For each parameter, n_eff is a crude measure of effective sample size,
and Rhat is the potential scale reduction factor on split chains (at 
convergence, Rhat=1).

rats%>%
  stan_select(!!!rlang::syms(c('mu_alpha','mu_beta')))

Inference for Stan model: rats.
4 chains, each with iter=2000; warmup=1000; thin=1; 
post-warmup draws per chain=1000, total post-warmup draws=4000.

           mean se_mean   sd   2.5%    25%    50%    75%  97.5% n_eff Rhat
mu_alpha 242.45    0.04 2.68 237.17 240.65 242.43 244.22 247.79  5295    1
mu_beta    6.19    0.00 0.11   5.98   6.11   6.19   6.26   6.40  4302    1

Samples were drawn using  at Fri Dec 13 08:38:41 2019.
For each parameter, n_eff is a crude measure of effective sample size,
and Rhat is the potential scale reduction factor on split chains (at 
convergence, Rhat=1).

rats%>%
  stan_select(alpha[1],alpha[2])

Inference for Stan model: rats.
4 chains, each with iter=2000; warmup=1000; thin=1; 
post-warmup draws per chain=1000, total post-warmup draws=4000.

           mean se_mean   sd   2.5%    25%    50%    75%  97.5% n_eff Rhat
alpha[1] 239.94    0.03 2.65 234.72 238.13 239.94 241.73 245.15  7024    1
alpha[2] 247.80    0.04 2.74 242.30 246.01 247.86 249.64 253.05  6023    1

Samples were drawn using  at Fri Dec 13 08:38:41 2019.
For each parameter, n_eff is a crude measure of effective sample size,
and Rhat is the potential scale reduction factor on split chains (at 
convergence, Rhat=1).

rats%>%
  stan_select(!!!rlang::syms(sprintf('alpha[%s]',1:5)))

Inference for Stan model: rats.
4 chains, each with iter=2000; warmup=1000; thin=1; 
post-warmup draws per chain=1000, total post-warmup draws=4000.

           mean se_mean   sd   2.5%    25%    50%    75%  97.5% n_eff Rhat
alpha[1] 239.94    0.03 2.65 234.72 238.13 239.94 241.73 245.15  7024    1
alpha[2] 247.80    0.04 2.74 242.30 246.01 247.86 249.64 253.05  6023    1
alpha[3] 252.44    0.04 2.58 247.22 250.74 252.43 254.13 257.50  5059    1
alpha[4] 232.60    0.03 2.71 227.23 230.81 232.61 234.38 237.94  7017    1
alpha[5] 231.64    0.03 2.69 226.32 229.85 231.62 233.46 236.90  6477    1

Samples were drawn using  at Fri Dec 13 08:38:41 2019.
For each parameter, n_eff is a crude measure of effective sample size,
and Rhat is the potential scale reduction factor on split chains (at 
convergence, Rhat=1).

Select with Partials

rats%>%
  stan_select(stan_contains('alpha'))
Select all Parameters that contain “alpha”
Inference for Stan model: rats.
4 chains, each with iter=2000; warmup=1000; thin=1; 
post-warmup draws per chain=1000, total post-warmup draws=4000.

                mean se_mean    sd   2.5%    25%    50%    75%  97.5% n_eff Rhat
alpha[1]      239.94    0.03  2.65 234.72 238.13 239.94 241.73 245.15  7024    1
alpha[2]      247.80    0.04  2.74 242.30 246.01 247.86 249.64 253.05  6023    1
alpha[3]      252.44    0.04  2.58 247.22 250.74 252.43 254.13 257.50  5059    1
alpha[4]      232.60    0.03  2.71 227.23 230.81 232.61 234.38 237.94  7017    1
alpha[5]      231.64    0.03  2.69 226.32 229.85 231.62 233.46 236.90  6477    1
alpha[6]      249.75    0.04  2.65 244.39 248.04 249.75 251.49 255.06  5331    1
alpha[7]      228.70    0.03  2.69 223.51 226.94 228.64 230.42 234.05  7721    1
alpha[8]      248.33    0.04  2.65 243.23 246.52 248.28 250.12 253.61  5596    1
alpha[9]      283.27    0.04  2.68 277.83 281.53 283.28 285.08 288.40  5129    1
alpha[10]     219.27    0.03  2.62 213.97 217.53 219.26 221.05 224.29  6879    1
alpha[11]     258.26    0.03  2.71 252.87 256.49 258.27 260.03 263.85  6760    1
alpha[12]     228.14    0.03  2.74 222.81 226.28 228.09 229.98 233.68  7475    1
alpha[13]     242.41    0.03  2.71 237.15 240.63 242.41 244.15 247.83  6268    1
alpha[14]     268.28    0.04  2.74 262.85 266.42 268.30 270.08 273.56  6108    1
alpha[15]     242.79    0.04  2.69 237.54 241.00 242.82 244.60 248.01  5881    1
alpha[16]     245.30    0.03  2.64 240.14 243.58 245.29 247.01 250.63  6282    1
alpha[17]     232.21    0.04  2.68 226.95 230.44 232.21 233.99 237.44  5517    1
alpha[18]     240.47    0.03  2.72 235.21 238.65 240.47 242.28 245.80  6733    1
alpha[19]     253.76    0.04  2.68 248.54 252.00 253.79 255.54 259.13  5846    1
alpha[20]     241.68    0.03  2.70 236.43 239.86 241.68 243.50 246.96  6563    1
alpha[21]     248.52    0.04  2.67 243.26 246.71 248.56 250.26 253.88  5708    1
alpha[22]     225.29    0.03  2.62 220.21 223.53 225.30 227.03 230.43  6554    1
alpha[23]     228.52    0.03  2.71 223.31 226.76 228.52 230.31 233.96  7679    1
alpha[24]     245.13    0.04  2.64 239.73 243.39 245.12 246.86 250.35  5278    1
alpha[25]     234.51    0.03  2.60 229.37 232.81 234.48 236.24 239.55  5746    1
alpha[26]     254.00    0.03  2.66 248.81 252.22 254.02 255.77 259.24  6521    1
alpha[27]     254.33    0.03  2.65 249.18 252.47 254.30 256.17 259.45  7077    1
alpha[28]     243.00    0.04  2.65 237.95 241.27 243.02 244.68 248.30  5487    1
alpha[29]     217.90    0.03  2.70 212.52 216.02 217.86 219.73 223.26  6188    1
alpha[30]     241.38    0.03  2.60 236.25 239.60 241.41 243.14 246.33  6561    1
mu_alpha      242.45    0.04  2.68 237.17 240.65 242.43 244.22 247.79  5295    1
sigmasq_alpha 216.80    1.00 63.46 124.16 173.10 205.47 249.85 371.18  4027    1
sigma_alpha    14.58    0.03  2.06  11.14  13.16  14.33  15.81  19.27  4324    1
alpha0        106.36    0.05  3.53  99.55 104.01 106.36 108.69 113.32  4815    1

Samples were drawn using  at Fri Dec 13 08:38:41 2019.
For each parameter, n_eff is a crude measure of effective sample size,
and Rhat is the potential scale reduction factor on split chains (at 
convergence, Rhat=1).

    rats%>%
      stan_select(stan_contains('alpha\\[1\\]'))

    Inference for Stan model: rats.
    4 chains, each with iter=2000; warmup=1000; thin=1; 
    post-warmup draws per chain=1000, total post-warmup draws=4000.

               mean se_mean   sd   2.5%    25%    50%    75%  97.5% n_eff Rhat
    alpha[1] 239.94    0.03 2.65 234.72 238.13 239.94 241.73 245.15  7024    1

    Samples were drawn using  at Fri Dec 13 08:38:41 2019.
    For each parameter, n_eff is a crude measure of effective sample size,
    and Rhat is the potential scale reduction factor on split chains (at 
    convergence, Rhat=1).
    rats%>%
      stan_select(stan_contains('alpha\\[[1-9]\\]'))

    Inference for Stan model: rats.
    4 chains, each with iter=2000; warmup=1000; thin=1; 
    post-warmup draws per chain=1000, total post-warmup draws=4000.

               mean se_mean   sd   2.5%    25%    50%    75%  97.5% n_eff Rhat
    alpha[1] 239.94    0.03 2.65 234.72 238.13 239.94 241.73 245.15  7024    1
    alpha[2] 247.80    0.04 2.74 242.30 246.01 247.86 249.64 253.05  6023    1
    alpha[3] 252.44    0.04 2.58 247.22 250.74 252.43 254.13 257.50  5059    1
    alpha[4] 232.60    0.03 2.71 227.23 230.81 232.61 234.38 237.94  7017    1
    alpha[5] 231.64    0.03 2.69 226.32 229.85 231.62 233.46 236.90  6477    1
    alpha[6] 249.75    0.04 2.65 244.39 248.04 249.75 251.49 255.06  5331    1
    alpha[7] 228.70    0.03 2.69 223.51 226.94 228.64 230.42 234.05  7721    1
    alpha[8] 248.33    0.04 2.65 243.23 246.52 248.28 250.12 253.61  5596    1
    alpha[9] 283.27    0.04 2.68 277.83 281.53 283.28 285.08 288.40  5129    1

    Samples were drawn using  at Fri Dec 13 08:38:41 2019.
    For each parameter, n_eff is a crude measure of effective sample size,
    and Rhat is the potential scale reduction factor on split chains (at 
    convergence, Rhat=1).
    rats%>%
      stan_select(stan_ends_with('0'))

    Inference for Stan model: rats.
    4 chains, each with iter=2000; warmup=1000; thin=1; 
    post-warmup draws per chain=1000, total post-warmup draws=4000.

             mean se_mean   sd  2.5%    25%    50%    75%  97.5% n_eff Rhat
    alpha0 106.36    0.05 3.53 99.55 104.01 106.36 108.69 113.32  4815    1

    Samples were drawn using  at Fri Dec 13 08:38:41 2019.
    For each parameter, n_eff is a crude measure of effective sample size,
    and Rhat is the potential scale reduction factor on split chains (at 
    convergence, Rhat=1).
    rats%>%
      stan_select(mu_alpha,stan_ends_with('0'),beta[1])

    Inference for Stan model: rats.
    4 chains, each with iter=2000; warmup=1000; thin=1; 
    post-warmup draws per chain=1000, total post-warmup draws=4000.

               mean se_mean   sd   2.5%    25%    50%    75%  97.5% n_eff Rhat
    beta[1]    6.06    0.00 0.24   5.60   5.90   6.06   6.22   6.52  6351    1
    mu_alpha 242.45    0.04 2.68 237.17 240.65 242.43 244.22 247.79  5295    1
    alpha0   106.36    0.05 3.53  99.55 104.01 106.36 108.69 113.32  4815    1

    Samples were drawn using  at Fri Dec 13 08:38:41 2019.
    For each parameter, n_eff is a crude measure of effective sample size,
    and Rhat is the potential scale reduction factor on split chains (at 
    convergence, Rhat=1).
1 Like

Post-warmup samples

Subsetting post warmup samples

  rats%>%
    stan_slice(1:50,inc_warmup = TRUE)
First 50 with warmup samples
Inference for Stan model: rats.
4 chains, each with iter=1050; warmup=1000; thin=1; 
post-warmup draws per chain=50, total post-warmup draws=200.

                 mean se_mean    sd    2.5%     25%     50%     75%   97.5% n_eff Rhat
alpha[1]       239.96    0.17  2.84  234.50  237.70  240.19  242.10  244.84   273 0.99
alpha[2]       247.54    0.22  3.09  240.61  245.57  247.86  249.84  252.59   195 0.99
alpha[3]       252.42    0.18  2.50  247.03  250.87  252.39  253.99  256.97   196 1.00
alpha[4]       232.65    0.12  2.47  227.66  231.07  232.77  234.37  237.25   414 0.99
alpha[5]       231.49    0.13  2.79  226.34  229.48  231.15  233.66  236.63   460 1.00
alpha[6]       250.02    0.12  2.63  245.07  248.32  249.98  251.73  255.01   460 0.99
alpha[7]       228.70    0.12  2.51  224.17  226.88  228.56  230.64  233.38   460 0.99
alpha[8]       248.36    0.15  2.57  243.14  246.60  248.33  250.08  252.89   303 0.99
alpha[9]       283.21    0.17  2.27  279.00  281.78  283.13  284.70  287.56   182 1.02
alpha[10]      219.19    0.17  2.61  214.20  217.75  219.13  220.85  223.62   222 1.00
alpha[11]      258.46    0.14  2.93  252.46  256.47  258.51  260.33  264.59   460 0.99
alpha[12]      228.27    0.13  2.85  223.29  226.13  228.26  230.48  233.82   449 0.98
alpha[13]      242.40    0.14  2.97  237.04  240.46  242.32  244.26  249.49   437 0.99
alpha[14]      267.93    0.17  2.46  262.66  266.26  267.82  269.74  272.19   209 1.01
alpha[15]      242.84    0.14  2.90  237.51  240.82  242.82  244.73  248.55   460 0.99
alpha[16]      245.18    0.18  2.42  240.17  243.71  245.19  246.68  250.28   184 1.01
alpha[17]      232.32    0.16  2.75  226.65  230.23  232.52  234.07  237.60   304 1.00
alpha[18]      240.51    0.16  2.59  235.46  239.09  240.45  242.06  245.85   263 0.99
alpha[19]      253.92    0.14  2.78  249.16  251.76  253.96  255.60  260.18   409 0.99
alpha[20]      241.77    0.12  2.51  237.37  239.98  241.86  243.62  246.79   460 0.98
alpha[21]      248.42    0.15  2.46  243.99  246.67  248.50  249.82  252.96   277 0.99
alpha[22]      225.31    0.14  2.49  219.93  223.90  225.36  226.91  229.80   312 1.00
alpha[23]      228.38    0.12  2.37  223.67  226.72  228.47  230.07  232.54   408 0.99
alpha[24]      245.02    0.18  2.99  238.96  243.11  245.16  246.79  251.14   264 0.99
alpha[25]      234.44    0.16  2.86  228.80  232.39  234.59  236.31  240.37   336 0.99
alpha[26]      253.82    0.14  2.89  248.28  251.85  253.87  255.49  259.71   400 0.99
alpha[27]      254.40    0.14  2.63  249.40  252.75  254.41  256.20  260.23   350 0.99
alpha[28]      243.10    0.12  2.62  237.65  241.73  243.24  244.57  248.58   460 0.99
alpha[29]      217.96    0.15  2.34  213.73  216.10  218.03  219.35  222.49   228 1.00
alpha[30]      241.23    0.16  2.65  235.82  239.57  241.16  242.91  246.34   283 0.98
beta[1]          6.08    0.01  0.20    5.74    5.96    6.07    6.21    6.47   375 0.99
beta[2]          7.05    0.01  0.24    6.55    6.86    7.06    7.22    7.50   382 0.99
beta[3]          6.49    0.01  0.24    6.00    6.32    6.50    6.65    6.93   324 0.99
beta[4]          5.33    0.02  0.27    4.82    5.15    5.35    5.51    5.85   242 1.00
beta[5]          6.56    0.01  0.25    6.08    6.38    6.55    6.71    7.13   397 0.99
beta[6]          6.16    0.01  0.22    5.71    6.02    6.18    6.30    6.60   398 0.99
beta[7]          5.95    0.01  0.22    5.57    5.80    5.95    6.08    6.43   376 0.99
beta[8]          6.39    0.01  0.28    5.81    6.23    6.41    6.58    6.92   460 0.99
beta[9]          7.06    0.02  0.26    6.58    6.87    7.08    7.26    7.50   288 0.99
beta[10]         5.83    0.01  0.25    5.32    5.68    5.80    6.02    6.28   384 1.01
beta[11]         6.81    0.01  0.22    6.40    6.66    6.82    6.95    7.20   245 0.99
beta[12]         6.11    0.01  0.26    5.65    5.93    6.09    6.28    6.69   306 0.99
beta[13]         6.15    0.02  0.26    5.70    5.94    6.18    6.35    6.59   248 0.98
beta[14]         6.67    0.01  0.25    6.16    6.52    6.65    6.83    7.19   366 0.99
beta[15]         5.42    0.01  0.28    4.87    5.19    5.45    5.60    5.96   388 0.99
beta[16]         5.94    0.01  0.24    5.43    5.77    5.94    6.10    6.44   371 0.99
beta[17]         6.27    0.01  0.22    5.91    6.11    6.24    6.41    6.72   293 0.99
beta[18]         5.85    0.02  0.26    5.38    5.69    5.84    6.04    6.31   301 1.00
beta[19]         6.41    0.02  0.27    5.89    6.25    6.40    6.58    6.92   285 0.99
beta[20]         6.07    0.01  0.26    5.60    5.91    6.07    6.24    6.59   460 0.98
beta[21]         6.42    0.01  0.22    5.95    6.30    6.42    6.55    6.88   331 0.99
beta[22]         5.87    0.01  0.25    5.40    5.71    5.88    6.04    6.35   306 1.00
beta[23]         5.75    0.01  0.22    5.32    5.57    5.75    5.90    6.18   253 1.01
beta[24]         5.90    0.02  0.27    5.40    5.75    5.89    6.07    6.41   254 1.00
beta[25]         6.90    0.02  0.27    6.42    6.70    6.90    7.09    7.42   299 1.00
beta[26]         6.56    0.01  0.21    6.17    6.40    6.58    6.71    6.95   377 0.99
beta[27]         5.88    0.01  0.24    5.40    5.74    5.88    6.05    6.29   299 1.00
beta[28]         5.85    0.01  0.26    5.36    5.69    5.85    6.02    6.32   303 0.99
beta[29]         5.69    0.02  0.29    5.12    5.50    5.68    5.87    6.23   325 0.98
beta[30]         6.14    0.01  0.28    5.66    5.92    6.13    6.36    6.64   408 0.99
mu_alpha       242.33    0.16  2.51  236.55  240.80  242.34  244.04  246.96   247 1.00
mu_beta          6.18    0.01  0.10    5.99    6.11    6.18    6.25    6.41   161 1.00
sigmasq_y       37.46    0.40  5.38   28.83   34.03   36.89   40.43   49.85   182 1.00
sigmasq_alpha  207.48    3.81 54.89  123.70  166.68  197.83  236.64  322.38   208 1.01
sigmasq_beta     0.28    0.01  0.09    0.13    0.21    0.27    0.33    0.47   198 1.00
sigma_y          6.10    0.03  0.43    5.37    5.83    6.07    6.36    7.06   183 1.00
sigma_alpha     14.29    0.13  1.84   11.12   12.91   14.07   15.38   17.95   207 1.01
sigma_beta       0.52    0.01  0.09    0.37    0.46    0.52    0.58    0.69   191 1.00
alpha0         106.34    0.25  3.52   99.36  104.14  106.51  108.60  112.41   205 0.99
lp__          -438.55    0.82  6.57 -451.07 -442.73 -438.49 -434.54 -425.79    65 1.05

Samples were drawn using  at Fri Dec 13 08:38:41 2019.
For each parameter, n_eff is a crude measure of effective sample size,
and Rhat is the potential scale reduction factor on split chains (at 
convergence, Rhat=1).

  rats%>%
    stan_slice(1:50,inc_warmup = FALSE)
First 50 draws from each chain without warmup samples
Inference for Stan model: rats.
4 chains, each with iter=50; warmup=0; thin=1; 
post-warmup draws per chain=50, total post-warmup draws=200.

                 mean se_mean    sd    2.5%     25%     50%     75%   97.5% n_eff Rhat
alpha[1]       239.96    0.17  2.84  234.50  237.70  240.19  242.10  244.84   273 0.99
alpha[2]       247.54    0.22  3.09  240.61  245.57  247.86  249.84  252.59   195 0.99
alpha[3]       252.42    0.18  2.50  247.03  250.87  252.39  253.99  256.97   196 1.00
alpha[4]       232.65    0.12  2.47  227.66  231.07  232.77  234.37  237.25   414 0.99
alpha[5]       231.49    0.13  2.79  226.34  229.48  231.15  233.66  236.63   460 1.00
alpha[6]       250.02    0.12  2.63  245.07  248.32  249.98  251.73  255.01   460 0.99
alpha[7]       228.70    0.12  2.51  224.17  226.88  228.56  230.64  233.38   460 0.99
alpha[8]       248.36    0.15  2.57  243.14  246.60  248.33  250.08  252.89   303 0.99
alpha[9]       283.21    0.17  2.27  279.00  281.78  283.13  284.70  287.56   182 1.02
alpha[10]      219.19    0.17  2.61  214.20  217.75  219.13  220.85  223.62   222 1.00
alpha[11]      258.46    0.14  2.93  252.46  256.47  258.51  260.33  264.59   460 0.99
alpha[12]      228.27    0.13  2.85  223.29  226.13  228.26  230.48  233.82   449 0.98
alpha[13]      242.40    0.14  2.97  237.04  240.46  242.32  244.26  249.49   437 0.99
alpha[14]      267.93    0.17  2.46  262.66  266.26  267.82  269.74  272.19   209 1.01
alpha[15]      242.84    0.14  2.90  237.51  240.82  242.82  244.73  248.55   460 0.99
alpha[16]      245.18    0.18  2.42  240.17  243.71  245.19  246.68  250.28   184 1.01
alpha[17]      232.32    0.16  2.75  226.65  230.23  232.52  234.07  237.60   304 1.00
alpha[18]      240.51    0.16  2.59  235.46  239.09  240.45  242.06  245.85   263 0.99
alpha[19]      253.92    0.14  2.78  249.16  251.76  253.96  255.60  260.18   409 0.99
alpha[20]      241.77    0.12  2.51  237.37  239.98  241.86  243.62  246.79   460 0.98
alpha[21]      248.42    0.15  2.46  243.99  246.67  248.50  249.82  252.96   277 0.99
alpha[22]      225.31    0.14  2.49  219.93  223.90  225.36  226.91  229.80   312 1.00
alpha[23]      228.38    0.12  2.37  223.67  226.72  228.47  230.07  232.54   408 0.99
alpha[24]      245.02    0.18  2.99  238.96  243.11  245.16  246.79  251.14   264 0.99
alpha[25]      234.44    0.16  2.86  228.80  232.39  234.59  236.31  240.37   336 0.99
alpha[26]      253.82    0.14  2.89  248.28  251.85  253.87  255.49  259.71   400 0.99
alpha[27]      254.40    0.14  2.63  249.40  252.75  254.41  256.20  260.23   350 0.99
alpha[28]      243.10    0.12  2.62  237.65  241.73  243.24  244.57  248.58   460 0.99
alpha[29]      217.96    0.15  2.34  213.73  216.10  218.03  219.35  222.49   228 1.00
alpha[30]      241.23    0.16  2.65  235.82  239.57  241.16  242.91  246.34   283 0.98
beta[1]          6.08    0.01  0.20    5.74    5.96    6.07    6.21    6.47   375 0.99
beta[2]          7.05    0.01  0.24    6.55    6.86    7.06    7.22    7.50   382 0.99
beta[3]          6.49    0.01  0.24    6.00    6.32    6.50    6.65    6.93   324 0.99
beta[4]          5.33    0.02  0.27    4.82    5.15    5.35    5.51    5.85   242 1.00
beta[5]          6.56    0.01  0.25    6.08    6.38    6.55    6.71    7.13   397 0.99
beta[6]          6.16    0.01  0.22    5.71    6.02    6.18    6.30    6.60   398 0.99
beta[7]          5.95    0.01  0.22    5.57    5.80    5.95    6.08    6.43   376 0.99
beta[8]          6.39    0.01  0.28    5.81    6.23    6.41    6.58    6.92   460 0.99
beta[9]          7.06    0.02  0.26    6.58    6.87    7.08    7.26    7.50   288 0.99
beta[10]         5.83    0.01  0.25    5.32    5.68    5.80    6.02    6.28   384 1.01
beta[11]         6.81    0.01  0.22    6.40    6.66    6.82    6.95    7.20   245 0.99
beta[12]         6.11    0.01  0.26    5.65    5.93    6.09    6.28    6.69   306 0.99
beta[13]         6.15    0.02  0.26    5.70    5.94    6.18    6.35    6.59   248 0.98
beta[14]         6.67    0.01  0.25    6.16    6.52    6.65    6.83    7.19   366 0.99
beta[15]         5.42    0.01  0.28    4.87    5.19    5.45    5.60    5.96   388 0.99
beta[16]         5.94    0.01  0.24    5.43    5.77    5.94    6.10    6.44   371 0.99
beta[17]         6.27    0.01  0.22    5.91    6.11    6.24    6.41    6.72   293 0.99
beta[18]         5.85    0.02  0.26    5.38    5.69    5.84    6.04    6.31   301 1.00
beta[19]         6.41    0.02  0.27    5.89    6.25    6.40    6.58    6.92   285 0.99
beta[20]         6.07    0.01  0.26    5.60    5.91    6.07    6.24    6.59   460 0.98
beta[21]         6.42    0.01  0.22    5.95    6.30    6.42    6.55    6.88   331 0.99
beta[22]         5.87    0.01  0.25    5.40    5.71    5.88    6.04    6.35   306 1.00
beta[23]         5.75    0.01  0.22    5.32    5.57    5.75    5.90    6.18   253 1.01
beta[24]         5.90    0.02  0.27    5.40    5.75    5.89    6.07    6.41   254 1.00
beta[25]         6.90    0.02  0.27    6.42    6.70    6.90    7.09    7.42   299 1.00
beta[26]         6.56    0.01  0.21    6.17    6.40    6.58    6.71    6.95   377 0.99
beta[27]         5.88    0.01  0.24    5.40    5.74    5.88    6.05    6.29   299 1.00
beta[28]         5.85    0.01  0.26    5.36    5.69    5.85    6.02    6.32   303 0.99
beta[29]         5.69    0.02  0.29    5.12    5.50    5.68    5.87    6.23   325 0.98
beta[30]         6.14    0.01  0.28    5.66    5.92    6.13    6.36    6.64   408 0.99
mu_alpha       242.33    0.16  2.51  236.55  240.80  242.34  244.04  246.96   247 1.00
mu_beta          6.18    0.01  0.10    5.99    6.11    6.18    6.25    6.41   161 1.00
sigmasq_y       37.46    0.40  5.38   28.83   34.03   36.89   40.43   49.85   182 1.00
sigmasq_alpha  207.48    3.81 54.89  123.70  166.68  197.83  236.64  322.38   208 1.01
sigmasq_beta     0.28    0.01  0.09    0.13    0.21    0.27    0.33    0.47   198 1.00
sigma_y          6.10    0.03  0.43    5.37    5.83    6.07    6.36    7.06   183 1.00
sigma_alpha     14.29    0.13  1.84   11.12   12.91   14.07   15.38   17.95   207 1.01
sigma_beta       0.52    0.01  0.09    0.37    0.46    0.52    0.58    0.69   191 1.00
alpha0         106.34    0.25  3.52   99.36  104.14  106.51  108.60  112.41   205 0.99
lp__          -438.55    0.82  6.57 -451.07 -442.73 -438.49 -434.54 -425.79    65 1.05

Samples were drawn using  at Fri Dec 13 08:38:41 2019.
For each parameter, n_eff is a crude measure of effective sample size,
and Rhat is the potential scale reduction factor on split chains (at 
convergence, Rhat=1).

  rats%>%
    stan_sample_n(100)
Sample 100 draws from each Chain
Inference for Stan model: rats.
4 chains, each with iter=1100; warmup=1000; thin=1; 
post-warmup draws per chain=100, total post-warmup draws=400.

                 mean se_mean    sd    2.5%     25%     50%     75%   97.5% n_eff Rhat
alpha[1]       239.85    0.14  2.81  234.51  237.86  239.82  241.80  245.15   410 1.00
alpha[2]       247.88    0.14  2.82  242.64  245.87  248.08  249.67  253.01   390 1.00
alpha[3]       252.42    0.13  2.58  247.35  250.78  252.39  254.15  257.35   391 1.00
alpha[4]       232.41    0.15  2.88  226.58  230.63  232.36  234.20  237.62   377 1.00
alpha[5]       231.68    0.12  2.74  226.38  229.94  231.73  233.54  236.84   497 1.00
alpha[6]       249.78    0.15  2.78  244.57  248.01  249.69  251.43  255.09   354 1.00
alpha[7]       228.80    0.13  2.77  223.81  226.90  228.67  230.43  234.74   453 1.00
alpha[8]       248.11    0.13  2.65  243.12  246.34  248.02  249.86  253.12   397 1.00
alpha[9]       283.52    0.13  2.69  277.82  281.82  283.67  285.19  288.88   458 0.99
alpha[10]      219.33    0.14  2.77  213.95  217.58  219.24  221.17  224.45   398 1.00
alpha[11]      258.45    0.17  2.63  253.16  256.76  258.30  260.29  263.82   238 1.02
alpha[12]      228.26    0.12  2.63  223.05  226.60  228.24  230.07  233.25   458 1.00
alpha[13]      242.20    0.13  2.72  236.96  240.25  242.24  244.17  247.48   419 1.00
alpha[14]      268.16    0.13  2.60  263.15  266.45  268.02  269.85  273.36   425 1.00
alpha[15]      242.80    0.11  2.55  238.10  241.10  242.84  244.32  247.79   523 1.00
alpha[16]      245.22    0.13  2.57  240.31  243.47  245.26  246.92  250.23   398 1.00
alpha[17]      232.21    0.15  2.74  226.84  230.36  232.18  234.11  237.33   315 1.00
alpha[18]      240.54    0.13  2.55  236.22  238.81  240.47  242.37  245.39   381 1.01
alpha[19]      253.92    0.14  2.68  249.01  252.16  253.89  255.64  259.53   391 1.00
alpha[20]      241.62    0.15  2.71  236.30  239.66  241.68  243.47  247.14   308 1.00
alpha[21]      248.57    0.13  2.62  243.30  246.87  248.59  250.36  253.89   385 1.00
alpha[22]      225.36    0.15  2.50  220.48  223.71  225.30  227.07  229.97   273 1.00
alpha[23]      228.67    0.15  2.80  223.48  226.85  228.67  230.46  233.84   341 1.00
alpha[24]      245.11    0.13  2.59  240.33  243.48  244.95  246.77  250.24   429 1.00
alpha[25]      234.25    0.11  2.54  229.48  232.63  234.30  236.01  238.90   535 1.00
alpha[26]      253.99    0.15  2.61  248.98  252.22  254.14  255.74  258.91   289 1.00
alpha[27]      254.15    0.14  2.71  248.94  252.38  254.01  255.95  259.72   386 1.00
alpha[28]      243.03    0.19  2.65  238.05  241.21  243.01  244.66  248.33   204 1.02
alpha[29]      217.75    0.13  2.68  212.48  215.84  217.61  219.61  222.85   413 1.00
alpha[30]      241.48    0.15  2.54  236.50  239.91  241.65  243.20  245.98   297 0.99
beta[1]          6.07    0.01  0.25    5.58    5.89    6.06    6.23    6.52   434 0.99
beta[2]          7.07    0.01  0.25    6.58    6.90    7.08    7.24    7.57   406 1.00
beta[3]          6.50    0.01  0.25    6.02    6.33    6.50    6.68    6.98   367 0.99
beta[4]          5.34    0.02  0.27    4.79    5.17    5.36    5.53    5.82   300 1.01
beta[5]          6.57    0.01  0.22    6.13    6.41    6.58    6.72    6.98   448 0.99
beta[6]          6.17    0.01  0.25    5.68    6.00    6.17    6.34    6.70   414 1.00
beta[7]          5.99    0.01  0.24    5.49    5.83    5.99    6.15    6.40   405 1.00
beta[8]          6.42    0.01  0.24    5.95    6.24    6.42    6.60    6.89   371 1.02
beta[9]          7.06    0.01  0.26    6.58    6.88    7.07    7.23    7.58   431 1.00
beta[10]         5.85    0.01  0.24    5.40    5.69    5.85    6.01    6.31   416 0.99
beta[11]         6.81    0.01  0.25    6.37    6.65    6.81    6.98    7.33   399 1.00
beta[12]         6.12    0.01  0.25    5.64    5.96    6.11    6.30    6.59   447 1.00
beta[13]         6.17    0.01  0.23    5.70    6.00    6.16    6.34    6.61   383 0.99
beta[14]         6.71    0.01  0.25    6.25    6.53    6.70    6.88    7.19   410 1.00
beta[15]         5.41    0.01  0.24    4.93    5.25    5.42    5.56    5.89   411 1.00
beta[16]         5.94    0.01  0.26    5.42    5.75    5.95    6.12    6.39   404 1.00
beta[17]         6.27    0.01  0.23    5.84    6.10    6.28    6.43    6.70   439 1.00
beta[18]         5.85    0.02  0.26    5.30    5.68    5.86    6.02    6.34   269 1.00
beta[19]         6.40    0.01  0.25    5.93    6.24    6.41    6.56    6.87   366 1.01
beta[20]         6.06    0.01  0.25    5.57    5.90    6.07    6.23    6.54   457 1.00
beta[21]         6.41    0.01  0.25    5.93    6.24    6.40    6.60    6.89   365 1.01
beta[22]         5.87    0.01  0.23    5.40    5.71    5.87    6.01    6.29   357 1.00
beta[23]         5.76    0.01  0.25    5.28    5.57    5.76    5.95    6.23   365 1.01
beta[24]         5.90    0.01  0.24    5.43    5.72    5.91    6.06    6.38   381 1.00
beta[25]         6.90    0.01  0.26    6.38    6.71    6.90    7.08    7.36   435 1.01
beta[26]         6.56    0.01  0.24    6.10    6.39    6.56    6.72    7.03   357 1.00
beta[27]         5.90    0.01  0.24    5.46    5.73    5.89    6.06    6.34   430 1.00
beta[28]         5.87    0.01  0.25    5.35    5.71    5.89    6.05    6.30   440 1.00
beta[29]         5.66    0.01  0.24    5.19    5.49    5.67    5.82    6.10   415 1.00
beta[30]         6.15    0.01  0.26    5.67    5.98    6.13    6.30    6.64   483 1.00
mu_alpha       242.52    0.17  2.71  236.50  240.75  242.62  244.24  247.63   253 1.01
mu_beta          6.19    0.01  0.12    5.96    6.12    6.20    6.27    6.41   388 1.01
sigmasq_y       37.65    0.28  5.62   28.24   33.81   37.02   41.16   50.63   390 1.00
sigmasq_alpha  215.70    3.24 58.65  122.85  173.88  209.42  247.58  359.38   327 1.00
sigmasq_beta     0.29    0.01  0.11    0.13    0.21    0.26    0.34    0.56   407 1.01
sigma_y          6.12    0.02  0.45    5.31    5.81    6.08    6.42    7.12   387 1.00
sigma_alpha     14.56    0.11  1.94   11.08   13.19   14.47   15.73   18.96   333 1.00
sigma_beta       0.53    0.00  0.10    0.36    0.46    0.51    0.59    0.75   402 1.01
alpha0         106.36    0.20  3.81   98.61  103.92  106.32  108.83  113.63   346 1.00
lp__          -438.42    0.33  6.80 -453.11 -442.44 -437.77 -433.93 -426.43   423 1.00

Samples were drawn using  at Fri Dec 13 08:38:41 2019.
For each parameter, n_eff is a crude measure of effective sample size,
and Rhat is the potential scale reduction factor on split chains (at 
convergence, Rhat=1).

  rats%>%
    stan_sample_frac(0.5)
Sample 50% of the Samples From each Chain
Inference for Stan model: rats.
4 chains, each with iter=1500; warmup=1000; thin=1; 
post-warmup draws per chain=500, total post-warmup draws=2000.

                 mean se_mean    sd    2.5%     25%     50%     75%   97.5% n_eff Rhat
alpha[1]       239.93    0.06  2.60  234.85  238.15  239.95  241.68  245.06  1981    1
alpha[2]       247.82    0.07  2.71  242.51  246.04  247.85  249.63  252.99  1744    1
alpha[3]       252.38    0.06  2.63  247.08  250.71  252.35  254.07  257.70  1797    1
alpha[4]       232.58    0.06  2.64  227.37  230.81  232.57  234.29  237.76  1942    1
alpha[5]       231.62    0.06  2.67  226.33  229.90  231.60  233.40  236.97  2112    1
alpha[6]       249.73    0.06  2.59  244.63  248.05  249.76  251.42  255.02  2044    1
alpha[7]       228.68    0.06  2.66  223.56  226.94  228.67  230.40  233.88  1956    1
alpha[8]       248.36    0.06  2.63  243.25  246.57  248.27  250.16  253.65  2001    1
alpha[9]       283.23    0.06  2.71  277.71  281.54  283.24  285.01  288.52  2061    1
alpha[10]      219.18    0.06  2.61  213.84  217.48  219.19  220.90  224.25  1908    1
alpha[11]      258.24    0.06  2.70  253.07  256.47  258.27  259.97  263.86  2162    1
alpha[12]      228.25    0.06  2.73  223.00  226.43  228.19  230.04  233.89  1989    1
alpha[13]      242.43    0.06  2.70  237.19  240.65  242.42  244.17  247.83  2018    1
alpha[14]      268.25    0.06  2.74  262.70  266.39  268.26  270.09  273.41  2146    1
alpha[15]      242.76    0.06  2.70  237.54  240.94  242.82  244.58  247.81  1864    1
alpha[16]      245.31    0.06  2.64  239.98  243.60  245.33  247.02  250.59  2072    1
alpha[17]      232.22    0.06  2.71  226.81  230.45  232.23  234.03  237.43  2078    1
alpha[18]      240.50    0.06  2.80  234.99  238.68  240.51  242.35  246.10  1971    1
alpha[19]      253.77    0.06  2.66  248.44  251.97  253.81  255.52  258.99  1944    1
alpha[20]      241.75    0.06  2.72  236.50  239.94  241.75  243.55  247.00  2202    1
alpha[21]      248.42    0.06  2.66  243.19  246.66  248.43  250.16  253.76  1931    1
alpha[22]      225.42    0.06  2.57  220.43  223.74  225.40  227.19  230.41  1687    1
alpha[23]      228.57    0.06  2.71  223.31  226.79  228.54  230.37  233.92  1971    1
alpha[24]      245.07    0.06  2.64  239.71  243.30  245.10  246.83  250.33  2017    1
alpha[25]      234.51    0.06  2.63  229.35  232.72  234.47  236.28  239.59  1932    1
alpha[26]      253.99    0.06  2.67  248.81  252.21  254.01  255.80  259.19  1903    1
alpha[27]      254.34    0.06  2.61  249.28  252.61  254.30  256.13  259.27  1906    1
alpha[28]      242.93    0.06  2.59  237.99  241.25  242.96  244.59  248.09  2061    1
alpha[29]      217.97    0.06  2.72  212.50  216.15  217.87  219.85  223.42  1976    1
alpha[30]      241.41    0.06  2.61  236.22  239.63  241.45  243.18  246.46  1927    1
beta[1]          6.06    0.01  0.24    5.61    5.90    6.06    6.23    6.52  2014    1
beta[2]          7.05    0.01  0.25    6.54    6.88    7.05    7.22    7.54  2078    1
beta[3]          6.48    0.01  0.24    6.02    6.32    6.49    6.64    6.93  1911    1
beta[4]          5.34    0.01  0.26    4.84    5.17    5.34    5.52    5.85  2044    1
beta[5]          6.56    0.01  0.24    6.11    6.40    6.56    6.72    7.05  2113    1
beta[6]          6.17    0.01  0.24    5.69    6.00    6.17    6.34    6.68  1874    1
beta[7]          5.97    0.01  0.24    5.50    5.81    5.97    6.14    6.46  1958    1
beta[8]          6.42    0.01  0.25    5.92    6.25    6.41    6.58    6.91  1955    1
beta[9]          7.06    0.01  0.26    6.56    6.88    7.06    7.23    7.55  1872    1
beta[10]         5.85    0.01  0.24    5.39    5.69    5.85    6.01    6.33  1509    1
beta[11]         6.80    0.01  0.25    6.31    6.63    6.80    6.96    7.31  1739    1
beta[12]         6.12    0.01  0.25    5.62    5.95    6.11    6.30    6.60  1864    1
beta[13]         6.16    0.01  0.24    5.69    6.00    6.16    6.33    6.62  2020    1
beta[14]         6.69    0.01  0.24    6.20    6.52    6.68    6.85    7.15  2097    1
beta[15]         5.42    0.01  0.24    4.94    5.26    5.42    5.58    5.89  1921    1
beta[16]         5.93    0.01  0.24    5.44    5.77    5.93    6.08    6.40  1976    1
beta[17]         6.27    0.01  0.23    5.81    6.12    6.26    6.43    6.73  2123    1
beta[18]         5.85    0.01  0.25    5.36    5.69    5.85    6.02    6.35  2077    1
beta[19]         6.41    0.01  0.24    5.93    6.25    6.41    6.57    6.88  1806    1
beta[20]         6.06    0.01  0.24    5.58    5.90    6.05    6.22    6.52  1726    1
beta[21]         6.40    0.01  0.25    5.89    6.23    6.41    6.57    6.90  2088    1
beta[22]         5.86    0.01  0.24    5.40    5.70    5.86    6.02    6.31  2097    1
beta[23]         5.75    0.01  0.24    5.29    5.59    5.74    5.91    6.22  2146    1
beta[24]         5.89    0.01  0.25    5.40    5.73    5.89    6.06    6.37  1897    1
beta[25]         6.91    0.01  0.26    6.42    6.73    6.91    7.09    7.43  1983    1
beta[26]         6.55    0.01  0.23    6.08    6.40    6.55    6.70    7.03  1903    1
beta[27]         5.90    0.01  0.24    5.43    5.73    5.90    6.06    6.37  1851    1
beta[28]         5.85    0.01  0.24    5.40    5.68    5.85    6.02    6.30  2003    1
beta[29]         5.67    0.01  0.24    5.21    5.50    5.67    5.83    6.16  2073    1
beta[30]         6.14    0.01  0.25    5.67    5.97    6.15    6.30    6.62  2033    1
mu_alpha       242.47    0.06  2.67  237.17  240.69  242.45  244.22  247.76  2221    1
mu_beta          6.18    0.00  0.11    5.98    6.11    6.19    6.26    6.40  2036    1
sigmasq_y       37.22    0.14  5.68   27.71   33.24   36.78   40.66   50.13  1770    1
sigmasq_alpha  217.77    1.44 63.40  125.44  173.89  206.66  250.97  370.65  1937    1
sigmasq_beta     0.27    0.00  0.10    0.13    0.20    0.26    0.33    0.51  1844    1
sigma_y          6.08    0.01  0.46    5.26    5.77    6.06    6.38    7.08  1769    1
sigma_alpha     14.61    0.05  2.05   11.20   13.19   14.38   15.84   19.25  1931    1
sigma_beta       0.51    0.00  0.09    0.35    0.45    0.51    0.57    0.72  1870    1
alpha0         106.41    0.08  3.53   99.52  104.06  106.38  108.70  113.62  2139    1
lp__          -438.04    0.16  7.13 -453.29 -442.58 -437.67 -433.13 -425.45  2014    1

Samples were drawn using  at Fri Dec 13 08:38:41 2019.
For each parameter, n_eff is a crude measure of effective sample size,
and Rhat is the potential scale reduction factor on split chains (at 
convergence, Rhat=1).

Select and Slice

rats%>%
    stan_select(mu_alpha)%>%
    stan_slice(1:50)

Inference for Stan model: rats.
4 chains, each with iter=1050; warmup=1000; thin=1; 
post-warmup draws per chain=50, total post-warmup draws=200.

           mean se_mean   sd   2.5%   25%    50%    75%  97.5% n_eff Rhat
mu_alpha 242.33    0.16 2.51 236.55 240.8 242.34 244.04 246.96   247    1

Samples were drawn using  at Fri Dec 13 08:38:41 2019.
For each parameter, n_eff is a crude measure of effective sample size,
and Rhat is the potential scale reduction factor on split chains (at 
convergence, Rhat=1).
1 Like

Retain Chains

rats%>%
   stan_retain(chains = 1)

Inference for Stan model: rats.
1 chains, each with iter=2000; warmup=1000; thin=1; 
post-warmup draws per chain=1000, total post-warmup draws=1000.

                 mean se_mean    sd    2.5%     25%     50%     75%   97.5% n_eff Rhat
alpha[1]       239.97    0.06  2.55  235.07  238.17  239.98  241.68  244.79  1971    1
alpha[2]       247.83    0.06  2.75  242.15  245.99  247.87  249.58  253.29  1834    1
alpha[3]       252.30    0.06  2.64  246.84  250.71  252.32  254.01  257.59  1780    1
alpha[4]       232.64    0.06  2.69  227.22  230.91  232.66  234.32  237.78  2299    1
alpha[5]       231.66    0.06  2.71  226.39  229.85  231.62  233.48  236.94  2086    1
alpha[6]       249.75    0.07  2.87  244.00  247.95  249.76  251.59  255.45  1835    1
alpha[7]       228.62    0.06  2.77  223.13  226.88  228.59  230.29  234.20  2382    1
alpha[8]       248.33    0.06  2.64  243.19  246.55  248.28  250.11  253.61  1788    1
alpha[9]       283.25    0.07  2.68  277.65  281.58  283.34  284.96  288.30  1418    1
alpha[10]      219.27    0.06  2.64  213.95  217.56  219.27  221.05  224.29  2133    1
alpha[11]      258.26    0.06  2.71  253.19  256.46  258.27  259.99  264.09  2107    1
alpha[12]      228.05    0.06  2.84  222.65  226.08  228.00  230.11  233.85  2353    1
alpha[13]      242.39    0.07  2.68  237.13  240.64  242.39  244.14  247.98  1524    1
alpha[14]      268.26    0.07  2.72  263.00  266.45  268.20  270.04  273.54  1570    1
alpha[15]      242.75    0.07  2.72  237.69  240.84  242.69  244.62  248.12  1671    1
alpha[16]      245.32    0.06  2.64  239.93  243.65  245.37  247.00  250.59  1648    1
alpha[17]      232.22    0.08  2.82  226.88  230.23  232.24  234.12  237.91  1252    1
alpha[18]      240.47    0.07  2.85  234.62  238.68  240.60  242.33  246.24  1612    1
alpha[19]      253.71    0.06  2.54  248.74  252.03  253.74  255.41  258.54  1987    1
alpha[20]      241.69    0.07  2.69  236.50  239.92  241.70  243.39  247.02  1596    1
alpha[21]      248.44    0.07  2.72  243.38  246.64  248.42  250.17  254.00  1734    1
alpha[22]      225.27    0.06  2.62  220.43  223.46  225.22  227.02  230.32  1713    1
alpha[23]      228.53    0.06  2.83  223.11  226.72  228.48  230.40  233.96  2640    1
alpha[24]      245.15    0.05  2.71  239.70  243.37  245.28  246.91  250.34  2580    1
alpha[25]      234.51    0.06  2.64  229.10  232.81  234.44  236.34  239.42  1914    1
alpha[26]      253.97    0.06  2.80  248.72  252.07  254.03  255.90  259.33  2546    1
alpha[27]      254.35    0.06  2.72  248.84  252.43  254.35  256.17  259.49  2040    1
alpha[28]      243.05    0.06  2.70  237.70  241.39  243.16  244.82  248.08  1900    1
alpha[29]      218.04    0.06  2.74  212.09  216.28  218.04  219.70  223.56  1817    1
alpha[30]      241.32    0.06  2.55  236.07  239.65  241.34  243.00  246.24  1900    1
beta[1]          6.06    0.01  0.24    5.56    5.91    6.06    6.22    6.50  1479    1
beta[2]          7.05    0.01  0.26    6.55    6.87    7.04    7.22    7.55  1911    1
beta[3]          6.48    0.01  0.23    6.07    6.32    6.48    6.64    6.93  1594    1
beta[4]          5.34    0.01  0.25    4.84    5.18    5.35    5.50    5.85  1505    1
beta[5]          6.57    0.01  0.26    6.08    6.39    6.57    6.74    7.08  1694    1
beta[6]          6.17    0.01  0.25    5.71    6.00    6.17    6.32    6.67  1476    1
beta[7]          5.97    0.01  0.23    5.52    5.81    5.97    6.13    6.43  1795    1
beta[8]          6.42    0.01  0.26    5.89    6.25    6.42    6.59    6.94  1842    1
beta[9]          7.05    0.01  0.27    6.53    6.87    7.05    7.23    7.56  1586    1
beta[10]         5.85    0.01  0.26    5.36    5.68    5.85    6.03    6.37  1565    1
beta[11]         6.80    0.01  0.25    6.32    6.62    6.79    6.96    7.29  1498    1
beta[12]         6.12    0.01  0.26    5.57    5.96    6.13    6.30    6.67  1788    1
beta[13]         6.16    0.01  0.23    5.72    6.00    6.16    6.33    6.56  1680    1
beta[14]         6.69    0.01  0.25    6.17    6.53    6.68    6.85    7.19  1554    1
beta[15]         5.42    0.01  0.24    4.95    5.26    5.43    5.59    5.89  1420    1
beta[16]         5.93    0.01  0.24    5.46    5.77    5.93    6.09    6.41  1852    1
beta[17]         6.27    0.01  0.24    5.83    6.11    6.26    6.43    6.75  1566    1
beta[18]         5.85    0.01  0.25    5.36    5.68    5.84    6.01    6.34  1971    1
beta[19]         6.40    0.01  0.24    5.91    6.24    6.40    6.56    6.86  1738    1
beta[20]         6.05    0.01  0.25    5.56    5.89    6.04    6.21    6.54  1961    1
beta[21]         6.40    0.01  0.24    5.93    6.23    6.40    6.56    6.88  1868    1
beta[22]         5.86    0.01  0.23    5.41    5.70    5.86    6.00    6.29  1826    1
beta[23]         5.75    0.01  0.24    5.28    5.58    5.76    5.91    6.22  1636    1
beta[24]         5.90    0.01  0.25    5.42    5.73    5.89    6.07    6.39  1576    1
beta[25]         6.90    0.01  0.27    6.36    6.72    6.90    7.08    7.43  1316    1
beta[26]         6.55    0.01  0.24    6.09    6.39    6.54    6.71    7.00  1163    1
beta[27]         5.89    0.01  0.24    5.43    5.72    5.88    6.05    6.35  2085    1
beta[28]         5.85    0.01  0.25    5.36    5.68    5.86    6.02    6.33  1728    1
beta[29]         5.67    0.01  0.24    5.20    5.51    5.67    5.84    6.12  2001    1
beta[30]         6.13    0.01  0.24    5.68    5.98    6.13    6.28    6.62  1892    1
mu_alpha       242.43    0.07  2.56  237.52  240.65  242.34  244.12  247.45  1528    1
mu_beta          6.18    0.00  0.11    5.97    6.11    6.19    6.25    6.39  1663    1
sigmasq_y       37.56    0.25  5.95   27.72   33.28   36.99   41.00   51.85   552    1
sigmasq_alpha  215.99    2.05 61.61  125.43  173.26  205.89  247.32  362.54   900    1
sigmasq_beta     0.27    0.00  0.10    0.12    0.21    0.26    0.33    0.50   860    1
sigma_y          6.11    0.02  0.48    5.26    5.77    6.08    6.40    7.20   581    1
sigma_alpha     14.56    0.06  2.01   11.20   13.16   14.35   15.73   19.04   978    1
sigma_beta       0.52    0.00  0.09    0.35    0.45    0.51    0.57    0.71   851    1
alpha0         106.41    0.08  3.43   99.94  104.14  106.37  108.70  113.00  1782    1
lp__          -438.59    0.50  7.37 -454.88 -443.29 -438.02 -433.58 -425.63   220    1

Samples were drawn using NUTS(diag_e) at Fri Dec 13 08:38:41 2019.
For each parameter, n_eff is a crude measure of effective sample size,
and Rhat is the potential scale reduction factor on split chains (at 
convergence, Rhat=1).

rats%>%
   stan_retain(chains = c(1,3))

Inference for Stan model: rats.
2 chains, each with iter=2000; warmup=1000; thin=1; 
post-warmup draws per chain=1000, total post-warmup draws=2000.

                 mean se_mean    sd    2.5%     25%     50%     75%   97.5% n_eff Rhat
alpha[1]       239.92    0.05  2.64  234.85  238.08  239.88  241.66  245.09  3098    1
alpha[2]       247.83    0.05  2.77  242.20  246.01  247.94  249.63  253.21  2562    1
alpha[3]       252.41    0.06  2.63  247.15  250.69  252.38  254.15  257.62  2123    1
alpha[4]       232.64    0.05  2.71  227.29  230.84  232.66  234.40  237.78  3511    1
alpha[5]       231.70    0.05  2.67  226.50  229.87  231.68  233.57  236.80  3138    1
alpha[6]       249.72    0.06  2.72  244.24  247.99  249.69  251.50  255.20  2171    1
alpha[7]       228.66    0.04  2.71  223.16  226.93  228.62  230.38  233.92  3660    1
alpha[8]       248.30    0.05  2.70  243.23  246.47  248.20  250.16  253.61  2915    1
alpha[9]       283.23    0.06  2.71  277.65  281.50  283.27  284.98  288.40  2120    1
alpha[10]      219.28    0.04  2.55  214.27  217.59  219.23  221.01  224.10  3376    1
alpha[11]      258.27    0.05  2.64  253.15  256.54  258.27  260.00  263.81  3434    1
alpha[12]      228.10    0.05  2.72  222.94  226.21  228.07  229.96  233.53  3593    1
alpha[13]      242.40    0.05  2.74  237.11  240.55  242.40  244.20  247.99  2544    1
alpha[14]      268.25    0.05  2.79  262.70  266.32  268.23  270.15  273.65  2815    1
alpha[15]      242.78    0.05  2.68  237.58  241.00  242.83  244.61  247.96  2694    1
alpha[16]      245.31    0.05  2.63  240.05  243.63  245.29  247.01  250.57  2989    1
alpha[17]      232.24    0.05  2.72  227.13  230.36  232.24  234.09  237.49  2551    1
alpha[18]      240.48    0.05  2.74  235.18  238.69  240.47  242.28  245.83  3121    1
alpha[19]      253.75    0.05  2.54  248.87  252.03  253.77  255.50  258.63  2606    1
alpha[20]      241.68    0.05  2.71  236.39  239.83  241.67  243.47  246.90  3085    1
alpha[21]      248.49    0.05  2.66  243.11  246.71  248.56  250.21  253.88  2593    1
alpha[22]      225.31    0.05  2.60  220.39  223.57  225.28  227.02  230.33  3145    1
alpha[23]      228.53    0.05  2.74  223.37  226.71  228.51  230.36  233.93  3531    1
alpha[24]      245.14    0.05  2.66  239.73  243.37  245.15  246.87  250.42  2572    1
alpha[25]      234.55    0.05  2.65  229.28  232.81  234.50  236.32  239.64  3051    1
alpha[26]      253.98    0.05  2.71  248.72  252.19  254.04  255.84  259.26  3235    1
alpha[27]      254.33    0.05  2.65  249.12  252.40  254.32  256.14  259.42  3477    1
alpha[28]      243.00    0.05  2.59  237.95  241.36  243.07  244.68  248.10  2461    1
alpha[29]      217.97    0.05  2.70  212.41  216.17  217.97  219.74  223.31  2734    1
alpha[30]      241.31    0.05  2.64  236.10  239.57  241.36  243.10  246.26  3254    1
beta[1]          6.06    0.00  0.23    5.59    5.90    6.05    6.22    6.50  2997    1
beta[2]          7.05    0.00  0.25    6.56    6.88    7.04    7.22    7.54  2760    1
beta[3]          6.48    0.00  0.24    6.02    6.32    6.48    6.64    6.94  2519    1
beta[4]          5.34    0.01  0.26    4.83    5.18    5.35    5.51    5.86  2328    1
beta[5]          6.56    0.00  0.24    6.10    6.40    6.56    6.72    7.05  2790    1
beta[6]          6.18    0.00  0.24    5.69    6.01    6.18    6.33    6.66  2677    1
beta[7]          5.97    0.00  0.24    5.51    5.81    5.97    6.14    6.45  2693    1
beta[8]          6.42    0.01  0.26    5.90    6.25    6.42    6.59    6.94  2514    1
beta[9]          7.06    0.01  0.26    6.56    6.88    7.06    7.23    7.56  2290    1
beta[10]         5.86    0.00  0.25    5.38    5.69    5.85    6.02    6.34  2581    1
beta[11]         6.79    0.00  0.25    6.30    6.62    6.79    6.96    7.29  2781    1
beta[12]         6.12    0.00  0.25    5.63    5.96    6.12    6.30    6.61  2631    1
beta[13]         6.16    0.00  0.25    5.68    5.99    6.16    6.33    6.62  3157    1
beta[14]         6.69    0.00  0.24    6.21    6.53    6.69    6.85    7.15  2843    1
beta[15]         5.42    0.00  0.25    4.94    5.25    5.42    5.58    5.89  2751    1
beta[16]         5.93    0.00  0.24    5.46    5.76    5.92    6.08    6.41  3068    1
beta[17]         6.27    0.01  0.23    5.83    6.11    6.26    6.43    6.73  2008    1
beta[18]         5.84    0.00  0.25    5.34    5.67    5.84    6.00    6.33  2601    1
beta[19]         6.40    0.00  0.24    5.94    6.24    6.40    6.56    6.86  2623    1
beta[20]         6.05    0.00  0.24    5.58    5.89    6.04    6.21    6.52  3536    1
beta[21]         6.40    0.00  0.25    5.94    6.23    6.40    6.57    6.89  3160    1
beta[22]         5.86    0.00  0.23    5.41    5.70    5.86    6.01    6.31  3102    1
beta[23]         5.75    0.00  0.24    5.28    5.58    5.75    5.90    6.21  2737    1
beta[24]         5.89    0.00  0.25    5.39    5.72    5.89    6.06    6.37  2759    1
beta[25]         6.90    0.01  0.26    6.38    6.73    6.90    7.08    7.44  2107    1
beta[26]         6.55    0.00  0.23    6.09    6.40    6.55    6.71    7.01  2302    1
beta[27]         5.89    0.00  0.24    5.42    5.72    5.88    6.05    6.36  2993    1
beta[28]         5.85    0.00  0.25    5.35    5.68    5.86    6.01    6.33  2548    1
beta[29]         5.67    0.00  0.25    5.18    5.50    5.67    5.84    6.15  3431    1
beta[30]         6.13    0.00  0.24    5.66    5.97    6.13    6.28    6.62  3065    1
mu_alpha       242.46    0.05  2.56  237.23  240.72  242.49  244.15  247.62  2442    1
mu_beta          6.18    0.00  0.11    5.97    6.11    6.18    6.25    6.40  2200    1
sigmasq_y       37.32    0.17  5.69   27.80   33.29   36.82   40.79   50.17  1097    1
sigmasq_alpha  216.72    1.61 64.15  123.29  172.55  205.03  249.62  372.27  1584    1
sigmasq_beta     0.28    0.00  0.10    0.13    0.21    0.26    0.33    0.51  1546    1
sigma_y          6.09    0.01  0.46    5.27    5.77    6.07    6.39    7.08  1134    1
sigma_alpha     14.57    0.05  2.07   11.10   13.14   14.32   15.80   19.29  1724    1
sigma_beta       0.52    0.00  0.09    0.35    0.45    0.51    0.58    0.72  1513    1
alpha0         106.45    0.07  3.48   99.59  104.12  106.44  108.77  113.26  2426    1
lp__          -438.21    0.31  7.10 -453.84 -442.73 -437.79 -433.41 -425.47   537    1

Samples were drawn using NUTS(diag_e) at Fri Dec 13 08:38:41 2019.
For each parameter, n_eff is a crude measure of effective sample size,
and Rhat is the potential scale reduction factor on split chains (at 
convergence, Rhat=1).

Filter

Users can filter conditionally on posterior samples. The function will
locate the indicies that the logical expression returns for each chain.
Due to a constraint in rstan::extract with permuted=FALSE chains are
assumed to be of equal size. To keep this assumption the chain size
returned is the length of the shortest conditional chain. If there is a
chain that results in no samples then the chain is dropped with a
warning. If no elements are returned for any chain then NULL is
returned.

rats%>%
   stan_select(mu_alpha,mu_beta)%>%
   stan_filter(mu_beta < 6)

Inference for Stan model: rats.
4 chains, each with iter=1032; warmup=1000; thin=1; 
post-warmup draws per chain=32, total post-warmup draws=128.

           mean se_mean   sd   2.5%    25%    50%    75%  97.5% n_eff Rhat
mu_alpha 242.40    0.23 2.60 236.46 241.01 242.67 244.08 246.88   127 1.02
mu_beta    5.95    0.01 0.05   5.83   5.94   5.97   5.98   6.00    86 1.04

Samples were drawn using  at Fri Dec 13 08:38:41 2019.
For each parameter, n_eff is a crude measure of effective sample size,
and Rhat is the potential scale reduction factor on split chains (at 
convergence, Rhat=1).
1 Like

Thanks for the additional examples. I think there is a lot common and some collaboration would make sense.

How do you compute n_eff and Rhat for this result? Sampling can invalidate the usual estimates

1 Like

Thank you for the comment.

At this point, we leverage the rstan summary method to do all the re-estimation the summary statistics after sampling subsets. ie the cache of the summary in the stanfit object is reset on.exit in shredder verbs

There is some hope if you keep the order, but if you randomize the order when sampling, then all hope is lost.

What is the use case for random sampling instead of regular thinning?

The order is kept, the index id is sampled the sorted before subsetting.

Thinning is set prerun and this sampling is post run. This way we can run a single “full run” that we can manipulate for several different types of tasks/outputs that do not all need all the post warmup samples.

A few example use cases

Use case 1:

We iterate over developing the post process script right on a small subset of the post warmups while not needing to precommit to a thinning. Once the script is set we can release the sampling call.

Use case 2:

There are times that the postprocessing plot output cannot handle the amount of information in the postwarmup samples and creates a huge/unworkable plot/filesize for reports, we found that slicing/sampling gives the us flexibility to make fit subsets that are size specific to the task at hand while not needing to rerun the original model.

You can do thinning also post run. Thinning refers to selecting every kth iteration instead of selecting randomly. I don’t see reason for doing it randomized as deterministic selection produces more efficient estimates.

In you case examples instead of random sampling, it would be better to use deterministic post-run thinning/slicing and then you would get better estimates, better n_eff estimates, and more representative plots. With random sampling you get less efficiency.

2 Likes

Thank you for the clarification. I didn’t know that is possible. How can I thin the stanfit object with rstan functions?

1 Like

You can thin by using your shredder package just by replacing random sampling with a call to seq(1,niter,by=t), where niter is the number of iterations per chain and t is the desired thin value.

Yes, thank you for the suggestion.

You can do this with stan_slice.

fit%>%stan_slice(seq(1,niter,by=t))

But i can see a more natural rstan verb shredder::stan_thin(t) that is a wrapper for stan_slice.

I also recommend that in the documentation it would be explicitly stated that shredder::stan_thin is preferred over shredder::stan_sample, because stan_sample has higher variance for all parameter estimates and n_eff and Rhat diagnostics are less reliable.

1 Like

It was easier just to replace stan_sample_* with stan_thin_*, it achieves the same goal and makes more sense in the context of application.

stan_thin documentation

Thank you for clarifying the distinction.

2 Likes

A PR was created in the repository for a hex sticker by a rstats community member that liked the package.

I merged it in last night, but wanted to pass it by the stan maintainers @avehtari @jonah, since it contains the Stan logo in it.



Is this ok? Or should it be edited out?

2 Likes

Looks cool, but as Stan logo is trademarked you need ask permission from Stan Governing Body.

3 Likes

Thank you for the direction, will do.