Skip to contents

Convert posterior data frame to a list of array

Usage

as_posterior_array(d, param = NULL, sample_n = NULL)

Arguments

d

Data frame. Posterior samples returned from stom::extract() or stom::get_pars().

param

String. Name of the parameter to extract (without brackets). By default, NULL, which assumes the input data frame d contains only the columns of the parameter of interest.

sample

Integer. Number of samples to draw from the posterior samples. If NULL, returns the full data frame of the posterior samples.

Value

A list of arrays, with each array corresponding to a draw from the posterior samples (i.e. a row in the posterior data frame).

Examples

fp = system.file("cases", "wine_network", "wine2_normal_first_level2.RDS", package="stom")
m = readRDS(fp)
post = extract(m)
as_posterior_array( post, param="Int", sample_n=5 )
#> [[1]]
#>         [,1]     [,2]
#> [1,] 1.99758 0.015059
#> [2,] 2.14069 0.000000
#> 
#> [[2]]
#>         [,1]      [,2]
#> [1,] 1.39175 -0.559822
#> [2,] 2.02846  0.000000
#> 
#> [[3]]
#>         [,1]        [,2]
#> [1,] 1.32129 -0.00905156
#> [2,] 1.44586  0.00000000
#> 
#> [[4]]
#>         [,1]      [,2]
#> [1,] 1.36939 -0.886437
#> [2,] 2.07201  0.000000
#> 
#> [[5]]
#>         [,1]      [,2]
#> [1,] 1.17571 -0.490894
#> [2,] 1.17411  0.000000
#>