1 · Prepare the data¶
layerbn requires an analysis-ready table. Prepare the data in your own software, such as SPSS, Stata, R or Excel, before you use layerbn. This includes deriving the outcome, choosing the follow-up period, recoding categories and imputing missing values.
Table format¶
Use one row per participant and one column per variable, with the column names in the first row:
| ID | AGE | SEX | SMOKING | SBP | SCORE_A | EVENT |
|---|---|---|---|---|---|---|
| 1001 | 63.5 | Female | Never | 142 | 27 | No |
| 1002 | 71.2 | Male | Current | 158 | 22 | Yes |
| 1003 | 58.9 | Female | Former | 131 | 29 | No |
Checklist¶
Check the following before you copy the file to the project folder.
- Column names are in the first row, short and without spaces, for example
AGE,SBPorSCORE_A. The names invariables.xlsxmust match them exactly, including upper and lower case. - The table contains only the participants to be analysed. Apply the inclusion and exclusion criteria beforehand.
- Missing values are empty cells. Codes such as
-99,999,.orNAare read as values. Replace them with empty cells. For each variable, you can then model missing values as a separate state (Missing), exclude the participants concerned, or impute the values beforehand. See Missing values. - Categories are stored as text where possible, for example
Female/Male,No/YesorNever/Former/Current. These labels are used in the figures. Numeric codes such as0/1are also accepted: a numeric column with at most 10 distinct values is treated as categorical. - Continuous variables are numbers without units or text, for example
63.5and not63.5 years. By default, they are divided into 4 groups of equal size. You can set the number of groups or the cut-off values for each variable. - The outcome is a single column, for example
No/Yesfor an event during follow-up. layerbn does not process dates or time-to-event data, so derive the outcome beforehand. - The table does not contain near-duplicate variables. If two versions of the same measurement are included, such as a raw and a standardised score, they compete for the same arcs. Include only one.
- Additional columns are allowed. Columns that are not listed in
variables.xlsx, such as an ID column, are ignored. The run lists the columns that were not used.
Loss to follow-up
Participants without an outcome can be excluded (drop_rows) or kept with the outcome
Missing (category). You can also code the reason as a category, for
example No / Yes / Lost to follow-up. The last two options keep all participants,
and the network then shows which variables are associated with loss to follow-up.
Sample size¶
Each variable has a probability table with one cell for each combination of its own groups and the groups of its parents. More variables, groups and parents require more participants.
Guideline
A few hundred participants for 15 to 20 variables with 4 groups each. With fewer
participants, use fewer variables, fewer groups (bins: 3) and fewer parents
(max_parents: 3), and expect lower arc stability. Start with a small network of about
10 variables.
Save the table¶
Save the table in one of the following formats and copy it to the data folder of the
project.
Save the file as .xlsx. The data must be on the first sheet, with the column names
in row 1. Do not add titles or merged cells above the table.
Alternatively, use File → Save As → CSV. CSV files with semicolons as separators and commas as decimal marks, as written by Excel with Dutch or German regional settings, are supported.
Save the file as .sav. Value labels are used as category names. Reading .sav files
requires an additional package: python -m pip install pyreadstat.
Alternatively, use File → Export → CSV Data and select Save value labels where defined.
Save the file with save "my_cohort.dta". Value labels are used as category names.
na = "" writes missing values as empty cells. Factors that are stored as numbers can be
converted with as.character() first, so that the labels are written.
To check that the file is in the right place, enter in the terminal:
The output lists the file, for example my_cohort.csv. You enter this name in
settings.yml in step 4.
Variables measured at several time points
Use a separate column for each variable and time point, with the time point as a suffix,
for example SCORE_T0 and SCORE_T1. See Measurements over time.
Variables measured once do not need a suffix.