Use element names to place vector elements in the appropriate location of an array.

array_format(v)

Arguments

v

A vector with names indicating the index location of each element in a new array. See the details (particularly the example) for more about what this means.

Value

An array with elements of v placed in the appropriate location based on their index names.

Details

Suppose you have an AxB matrix in your model, and you would like to create an object that stores the posterior means in the same AxB matrix as found in the model. For an AxB matrix, this is not too difficult to do "by-hand". However, if there are also dimensions C, D, and E, missing values, etc. it becomes more difficult.

Note

Up to 10 dimensions are currently supported. Please submit an issue should you find that you need more dimensions.

Examples

# load example mcmc.list data(cjs) # find an array node from your model match_params(cjs, "SIG")
#> [1] "SIG[1,1]" "SIG[2,1]" "SIG[1,2]" "SIG[2,2]"
# extract the posterior mean of it SIG_mean = post_summ(cjs, "SIG")["mean",] # note that it has element names SIG_mean
#> SIG[1,1] SIG[2,1] SIG[1,2] SIG[2,2] #> 1.09447098 0.04547222 0.04547222 0.12787612
# create a matrix with elements in the proper place array_format(SIG_mean)
#> [,1] [,2] #> [1,] 1.09447098 0.04547222 #> [2,] 0.04547222 0.12787612