from_table#

bayesflow.experimental.from_table(graph: SimulationGraph, table, groups: dict[str, str]) → dict[str, NodeSamples][source]#

Reads observed data from a table, so it can be passed as conditions to MultilevelEstimator.sample().

Each row of the table is one observation, and the rows can come in any order. For every repeated node, the table needs a column saying which group the observation belongs to. In the crossed IRT model, a table with the columns school, question, student and obs is read with:

from_table(graph, table, groups={"dataset": "school", "questions": "question", "students": "student"})

Labels only have to be unique within their parent, so students can be numbered from 0 in every school. All other columns, here obs, are taken as the observed variables.

Only works for graphs with a single data node.

Parameters:
graphSimulationGraph

The graph of the model, usually simulator.graph.

tablepandas.DataFrame or dict[str, np.ndarray]

The observed data. The variable columns need the same names as the variables of the data node.

groupsdict[str, str]

The label column of each repeated node. Use the key "dataset" if the table holds several datasets, otherwise the whole table is one dataset.

Returns:
GraphSamples

The rows of every node. Only the data node has values.

Raises:
ValueError

If a repeated node has no label column.