Skip to content

The study

A Study holds everything about one study: who was measured (units, in a hierarchy), what was measured (a data dictionary of variables) and the values, plus its identity, protocol and attached files. It is saved as one .syn file.

Units and levels

A level is a kind of unit (subject, session, trial); a unit is one member of a level, with an id. Levels nest or cross:

study.units.define("site > subject > session")      # sessions within subjects within sites
study.units.define("trial < subject * stimulus")    # a trial belongs to one subject and one stimulus

Ids are stored as given ("trial 1" can repeat under every subject). A unit is always a statistical unit; the unit of measurement of a variable is its measurement_unit ("kg", "ms").

Variables, dimensions and values

A variable is defined once and observed many times: its level, dtype, scale (nominal, ordinal, interval, ratio), optional dimensions (time, channel, condition) and a description. Defining it is optional: the first values define it (with an InferenceNotice to review); after that, validation is strict.

study.variables.define("weight", level="subject", dims=["week"], measurement_unit="kg", scale="ratio")
study.add("weight", weights)                        # columns: subject, week, weight

Each value lives at one address: a unit at the variable's level and a coordinate along each dimension. Replacing a value needs overwrite=True. Units may have different coordinates (no padding).

Where factors live

This one modelling rule lets synaptome read a design instead of being told it:

In statistics In synaptome Example
between-unit factor a variable at the unit's level group of each subject
within-unit factor a dimension of the outcome condition of score
repeated measurements a unit level trial under subject
an ordered axis an ordered dimension (Dim(scale=...)) week, snr, depth_bin

A question comparing across group is then independent; across condition, paired. Repetitions are levels, so collapsing them is an explicit step (reduce={"trial": "mean"}).

Views and storage

to_df(name, with_=[...], reduce={...}) gives a variable as a long pandas table, joined with variables of its level or above; table(level) gives one row per unit. select, drop, rename, copy and concat return new studies.

study.save("trial.syn") writes a zip (or a folder) of Parquet tables and JSON: units, the data dictionary, values, pre-specified questions, attachments. Any Parquet reader opens it; syn.peek reads only the manifest; syn.load(path, variables=[...]) loads part of it. See tutorials 02 to 05.