Skip to contents

This function summarizes the posterior distributions of specified parameters from a model fit. Summary includes mean, sd, and specified quantiles, as well as effective sample size (n_eff) and Rhat for estimated parameters. See more examples in the Package Vignette.

Usage

joint_summarize(model_fit, par = "all", probs = c(0.025, 0.975), digits = 3)

Arguments

model_fit

An object of class stanfit.

par

A character vector of parameter names. The default is 'all'.

probs

A numeric vector of quantiles of interest. The default is c(0.025,0.975).

digits

An integer indicating the number of decimal places to round values in summary table. Default value is 3.

Value

A summary table of parameter estimates.

Note

Before fitting the model, this function checks to ensure that the function is possible given the inputs. These checks include:

  • Input model fit is an object of class 'stanfit'.

  • Input probs is a numeric vector.

  • Input par is a character vector.

  • Input par are present in fitted model.

  • Input model fit has converged (i.e. no divergent transitions after warm-up).

If any of these checks fail, the function returns an error message.

Examples

# \donttest{
data(green_crab_data)

# Fit a model
model_fit <- joint_model(data = green_crab_data, family = "negbin", q = TRUE,
                         multicore = FALSE)
#> 
#> SAMPLING FOR MODEL 'joint_count' NOW (CHAIN 1).
#> Chain 1: 
#> Chain 1: Gradient evaluation took 0.000331 seconds
#> Chain 1: 1000 transitions using 10 leapfrog steps per transition would take 3.31 seconds.
#> Chain 1: Adjust your expectations accordingly!
#> Chain 1: 
#> Chain 1: 
#> Chain 1: Iteration:    1 / 3000 [  0%]  (Warmup)
#> Chain 1: Iteration:  500 / 3000 [ 16%]  (Warmup)
#> Chain 1: Iteration:  501 / 3000 [ 16%]  (Sampling)
#> Chain 1: Iteration: 1000 / 3000 [ 33%]  (Sampling)
#> Chain 1: Iteration: 1500 / 3000 [ 50%]  (Sampling)
#> Chain 1: Iteration: 2000 / 3000 [ 66%]  (Sampling)
#> Chain 1: Iteration: 2500 / 3000 [ 83%]  (Sampling)
#> Chain 1: Iteration: 3000 / 3000 [100%]  (Sampling)
#> Chain 1: 
#> Chain 1:  Elapsed Time: 3.645 seconds (Warm-up)
#> Chain 1:                12.612 seconds (Sampling)
#> Chain 1:                16.257 seconds (Total)
#> Chain 1: 
#> 
#> SAMPLING FOR MODEL 'joint_count' NOW (CHAIN 2).
#> Chain 2: 
#> Chain 2: Gradient evaluation took 0.000356 seconds
#> Chain 2: 1000 transitions using 10 leapfrog steps per transition would take 3.56 seconds.
#> Chain 2: Adjust your expectations accordingly!
#> Chain 2: 
#> Chain 2: 
#> Chain 2: Iteration:    1 / 3000 [  0%]  (Warmup)
#> Chain 2: Iteration:  500 / 3000 [ 16%]  (Warmup)
#> Chain 2: Iteration:  501 / 3000 [ 16%]  (Sampling)
#> Chain 2: Iteration: 1000 / 3000 [ 33%]  (Sampling)
#> Chain 2: Iteration: 1500 / 3000 [ 50%]  (Sampling)
#> Chain 2: Iteration: 2000 / 3000 [ 66%]  (Sampling)
#> Chain 2: Iteration: 2500 / 3000 [ 83%]  (Sampling)
#> Chain 2: Iteration: 3000 / 3000 [100%]  (Sampling)
#> Chain 2: 
#> Chain 2:  Elapsed Time: 4.06 seconds (Warm-up)
#> Chain 2:                8.504 seconds (Sampling)
#> Chain 2:                12.564 seconds (Total)
#> Chain 2: 
#> 
#> SAMPLING FOR MODEL 'joint_count' NOW (CHAIN 3).
#> Chain 3: 
#> Chain 3: Gradient evaluation took 0.000363 seconds
#> Chain 3: 1000 transitions using 10 leapfrog steps per transition would take 3.63 seconds.
#> Chain 3: Adjust your expectations accordingly!
#> Chain 3: 
#> Chain 3: 
#> Chain 3: Iteration:    1 / 3000 [  0%]  (Warmup)
#> Chain 3: Iteration:  500 / 3000 [ 16%]  (Warmup)
#> Chain 3: Iteration:  501 / 3000 [ 16%]  (Sampling)
#> Chain 3: Iteration: 1000 / 3000 [ 33%]  (Sampling)
#> Chain 3: Iteration: 1500 / 3000 [ 50%]  (Sampling)
#> Chain 3: Iteration: 2000 / 3000 [ 66%]  (Sampling)
#> Chain 3: Iteration: 2500 / 3000 [ 83%]  (Sampling)
#> Chain 3: Iteration: 3000 / 3000 [100%]  (Sampling)
#> Chain 3: 
#> Chain 3:  Elapsed Time: 3.619 seconds (Warm-up)
#> Chain 3:                9.483 seconds (Sampling)
#> Chain 3:                13.102 seconds (Total)
#> Chain 3: 
#> 
#> SAMPLING FOR MODEL 'joint_count' NOW (CHAIN 4).
#> Chain 4: 
#> Chain 4: Gradient evaluation took 0.000364 seconds
#> Chain 4: 1000 transitions using 10 leapfrog steps per transition would take 3.64 seconds.
#> Chain 4: Adjust your expectations accordingly!
#> Chain 4: 
#> Chain 4: 
#> Chain 4: Iteration:    1 / 3000 [  0%]  (Warmup)
#> Chain 4: Iteration:  500 / 3000 [ 16%]  (Warmup)
#> Chain 4: Iteration:  501 / 3000 [ 16%]  (Sampling)
#> Chain 4: Iteration: 1000 / 3000 [ 33%]  (Sampling)
#> Chain 4: Iteration: 1500 / 3000 [ 50%]  (Sampling)
#> Chain 4: Iteration: 2000 / 3000 [ 66%]  (Sampling)
#> Chain 4: Iteration: 2500 / 3000 [ 83%]  (Sampling)
#> Chain 4: Iteration: 3000 / 3000 [100%]  (Sampling)
#> Chain 4: 
#> Chain 4:  Elapsed Time: 3.668 seconds (Warm-up)
#> Chain 4:                8.421 seconds (Sampling)
#> Chain 4:                12.089 seconds (Total)
#> Chain 4: 
#> Refer to the eDNAjoint guide for visualization tips:  https://ednajoint.netlify.app/tips#visualization-tips 

# Create summary table of all parameters
joint_summarize(model_fit$model)
#>           mean se_mean    sd  2.5%  97.5%     n_eff  Rhat
#> mu[1,1]  0.106   0.000 0.027 0.061  0.166 12380.617 1.000
#> mu[1,2]  0.084   0.000 0.023 0.046  0.135 13534.480 1.000
#> mu[2,1]  0.033   0.000 0.032 0.001  0.122 15282.459 1.000
#> mu[2,2]  0.026   0.000 0.025 0.001  0.096 14933.114 1.000
#> mu[3,1]  0.017   0.000 0.017 0.000  0.064 13326.894 1.000
#> mu[3,2]  0.013   0.000 0.014 0.000  0.050 13103.138 1.000
#> mu[4,1]  0.678   0.001 0.106 0.493  0.907  9235.392 1.000
#> mu[4,2]  0.534   0.001 0.089 0.380  0.730 12082.022 1.000
#> mu[5,1]  0.099   0.001 0.107 0.002  0.399 12484.283 1.000
#> mu[5,2]  0.078   0.001 0.085 0.002  0.311 12637.189 1.000
#> mu[6,1]  0.120   0.001 0.135 0.003  0.474 11524.459 1.000
#> mu[6,2]  0.094   0.001 0.106 0.002  0.370 11807.473 1.000
#> mu[7,1]  0.013   0.000 0.013 0.000  0.046 13747.883 1.000
#> mu[7,2]  0.010   0.000 0.010 0.000  0.036 13973.315 1.000
#> mu[8,1]  0.301   0.003 0.287 0.014  1.048 12615.161 1.000
#> mu[8,2]  0.238   0.002 0.229 0.011  0.825 12736.316 1.000
#> mu[9,1]  0.033   0.000 0.032 0.001  0.119 12322.959 1.000
#> mu[9,2]  0.026   0.000 0.025 0.001  0.093 12529.840 1.000
#> mu[10,1] 1.047   0.003 0.246 0.645  1.609  9615.298 1.000
#> mu[10,2] 0.822   0.002 0.193 0.506  1.261 14061.546 1.000
#> mu[11,1] 0.304   0.003 0.288 0.012  1.079 12190.575 1.000
#> mu[11,2] 0.240   0.002 0.227 0.009  0.839 12707.725 1.000
#> mu[12,1] 0.021   0.000 0.021 0.001  0.079 13420.422 1.000
#> mu[12,2] 0.017   0.000 0.017 0.000  0.062 13640.437 1.000
#> mu[13,1] 7.689   0.015 1.320 5.490 10.657  8157.489 1.000
#> mu[13,2] 6.036   0.008 0.987 4.331  8.266 13843.566 1.000
#> mu[14,1] 0.119   0.000 0.020 0.084  0.161  9214.932 1.000
#> mu[14,2] 0.094   0.000 0.016 0.065  0.129 12944.167 1.000
#> mu[15,1] 0.769   0.006 0.556 0.119  2.184  9952.528 1.000
#> mu[15,2] 0.604   0.004 0.435 0.093  1.714 10546.127 1.000
#> mu[16,1] 3.818   0.007 0.661 2.688  5.281  8093.417 1.000
#> mu[16,2] 2.994   0.004 0.470 2.185  4.012 16680.209 1.000
#> mu[17,1] 0.164   0.002 0.186 0.004  0.671 12385.708 1.000
#> mu[17,2] 0.129   0.001 0.146 0.003  0.530 12092.711 1.000
#> mu[18,1] 3.344   0.012 1.120 1.747  6.011  8621.316 1.000
#> mu[18,2] 2.629   0.009 0.880 1.368  4.775 10507.626 1.000
#> mu[19,1] 3.943   0.008 0.727 2.757  5.595  8332.283 1.000
#> mu[19,2] 3.100   0.005 0.576 2.134  4.396 12740.153 1.000
#> mu[20,1] 0.119   0.001 0.069 0.024  0.289 11857.371 1.000
#> mu[20,2] 0.093   0.000 0.054 0.019  0.228 12514.211 1.000
#> q[1]     0.793   0.001 0.103 0.609  1.010  5888.827 1.001
#> p10      0.019   0.000 0.010 0.005  0.042 10345.316 1.000
#> beta[1]  1.264   0.003 0.248 0.782  1.760  7800.821 1.000
#> beta[2]  1.264   0.003 0.248 0.782  1.760  7800.821 1.000
#> beta[3]  1.264   0.003 0.248 0.782  1.760  7800.821 1.000
#> beta[4]  1.264   0.003 0.248 0.782  1.760  7800.821 1.000
#> beta[5]  1.264   0.003 0.248 0.782  1.760  7800.821 1.000
#> beta[6]  1.264   0.003 0.248 0.782  1.760  7800.821 1.000
#> beta[7]  1.264   0.003 0.248 0.782  1.760  7800.821 1.000
#> beta[8]  1.264   0.003 0.248 0.782  1.760  7800.821 1.000
#> beta[9]  1.264   0.003 0.248 0.782  1.760  7800.821 1.000
#> beta[10] 1.264   0.003 0.248 0.782  1.760  7800.821 1.000
#> beta[11] 1.264   0.003 0.248 0.782  1.760  7800.821 1.000
#> beta[12] 1.264   0.003 0.248 0.782  1.760  7800.821 1.000
#> beta[13] 1.264   0.003 0.248 0.782  1.760  7800.821 1.000
#> beta[14] 1.264   0.003 0.248 0.782  1.760  7800.821 1.000
#> beta[15] 1.264   0.003 0.248 0.782  1.760  7800.821 1.000
#> beta[16] 1.264   0.003 0.248 0.782  1.760  7800.821 1.000
#> beta[17] 1.264   0.003 0.248 0.782  1.760  7800.821 1.000
#> beta[18] 1.264   0.003 0.248 0.782  1.760  7800.821 1.000
#> beta[19] 1.264   0.003 0.248 0.782  1.760  7800.821 1.000
#> beta[20] 1.264   0.003 0.248 0.782  1.760  7800.821 1.000
#> alpha[1] 1.264   0.003 0.248 0.782  1.760  7800.821 1.000
#> phi      0.918   0.001 0.132 0.690  1.205  9159.590 1.000

# Summarize just 'p10' parameter
joint_summarize(model_fit$model, par = "p10", probs = c(0.025, 0.975),
                digits = 3)
#>      mean se_mean   sd  2.5% 97.5%    n_eff Rhat
#> p10 0.019       0 0.01 0.005 0.042 10345.32    1
# }