BayES BayES

2.6 Structures

A structure in BayES is a data type used to group together different data types into a single element. For example, it may be convenient to bundle together a set of a matrices and strings, assign an id value to the bundle and use this id value to refer to it in subsequent statements. As an example, suppose that A is a matrix, myModel a model and myData a dataset, all of them being in memory in the current workspace. The statement:

S = { e1 = A, m = myModel, d = myData };

defines a structure S with three elements, the id values of which are e1, m and d. The elements of S can be accessed using the ‘.’ operator. For example, the statement:

print(S.m);

will print on the BayES console the results from the model that has an id value m within structure S. The list of elements contained in a structure is printed on the BayES console using the who() function:

who(S);

The elements of S are copies of the original elements and have their own life: altering the entries of S.e1 in the example above will not affect matrix A in the current workspace. Structures can have other structures as elements and can be infinitely nested.

Structures can be used within a script to make code more succinct. Simple examples of using structures can be found in sample "5Working with structures.bsf", which is located at "$BayESHOME/Samples/1GettingStarted". Although optional in most cases, structures must be used to communicate with programs external to BayES. Initial values are passed to JAGS and OpenBUGS (see Sections 3.2 and 3.3) in the form of structures and the samples located at "$BayESHOME/Samples/3JAGSOpenBUGS" demonstrate their use in this context. Other interface functions provided by BayES (see Sections 3.5 to 3.8) return structures after completion and their use is demonstrated in the samples located at "$BayESHOME/Samples/5Interfaces".

Share this content:
Facebook Twitter LinkedIn Email
© 2016–20 Grigorios Emvalomatis