Package {MariNET}


Title: Build Networks from EHRs and Omics Data Using Linear Mixed Models
Version: 2.0.0
Description: Analyzing longitudinal clinical data from Electronic Health Records (EHRs) using linear mixed models (LMM) and visualizing the results as networks. It includes functions for fitting LMM, normalizing adjacency matrices, and comparing networks. It also allows the integration of omics data (e.g. gene expression or protein abundance) with longitudinal clinical variables, building networks of molecular feature-clinical relationships. The package is designed for researchers in clinical and biomedical fields who need to model longitudinal data and explore relationships between variables. For more details see Bates et al. (2015) <doi:10.18637/jss.v067.i01>.
License: GPL-3
Imports: dplyr, lme4, qgraph
Encoding: UTF-8
RoxygenNote: 7.3.2
Suggests: knitr, rmarkdown, BiocStyle
VignetteBuilder: knitr
Depends: R (≥ 3.5)
LazyData: true
NeedsCompilation: no
Packaged: 2026-11-19 17:23:10 UTC; mvargas
Author: Vargas-Fernández Marina [aut, cre], Martorell-Marugán Jordi [aut], Carmona-Sáez Pedro [aut]
Maintainer: Vargas-Fernández Marina <marinavf1998@gmail.com>
Repository: CRAN
Date/Publication: 2026-11-19 18:50:02 UTC

Subtract Two Adjacency Matrices

Description

This function returns difference matrix between two networks. It is useful for comparing two networks represented by adjacency matrices.

Usage

differentiation(matrix1, matrix2)

Arguments

matrix1

The first adjacency matrix.

matrix2

The second adjacency matrix.

Value

a normalized matrix containing values between 0 and 1.


Example Dataset: Psychological and Behavioral Responses

Description

This dataset contains self-reported psychological and behavioral responses from individuals.

Usage

example_data

Format

A data frame with multiple rows and 17 variables:

id

Unique participant identifier (integer).

Relax

Self-reported relaxation level (integer scale).

Irritable

Self-reported irritability level (integer scale).

Worry

Level of worry experienced (integer scale).

Nervous

Self-reported nervousness (integer scale).

Future

Concerns about the future (integer scale).

Anhedonia

Self-reported lack of enjoyment (integer scale).

Tired

Level of tiredness (integer scale).

Hungry

Self-reported hunger level (integer scale).

Alone

Feeling of loneliness (integer scale).

Angry

Level of anger experienced (integer scale).

Social_offline

Offline social interactions (integer scale).

Social_online

Online social interactions (integer scale).

Music

Time spent listening to music (integer scale).

Procrastinate

Self-reported procrastination (integer scale).

Outdoors

Time spent outdoors (integer scale).

C19_occupied

Engagement in activities during COVID-19 (integer scale).

C19_worry

Level of worry related to COVID-19 (integer scale).

Home

Time spent at home (integer scale).

day

Day number of the study (integer).

beep

Moment within the day when data was collected (integer).

conc

Self-reported concentration level (integer scale).

Details

This dataset was collected from a study examining psychological and behavioral responses to various daily experiences. Each row represents a unique moment of self-reporting.

Source

Reproducible figure for Nature Methods primer paper, Borsboom et al. 2021. This examples contains a subset of variables collected and modeled in our covid19 paper. This paper, with full data is available on https://journals.sagepub.com/doi/10.1177/21677026211017839. Eiko Fried, March 14 2021

Examples

data(example_data)
head(example_data)


Example Dataset: Simulated Longitudinal Clinical and Omics Data

Description

This dataset contains fully simulated longitudinal clinical measurements and molecular features (e.g. gene expression) for 80 participants with up to 4 visits. It is intended to illustrate the integration of molecular features with clinical variables using lmm_integration_analysis().

Usage

example_omics

Format

A data frame with 296 rows and 18 variables:

participant_id

Unique participant identifier (character).

visit_month

Month of the visit since baseline (0, 12, 24 or 36).

sex

Sex of the participant (Female or Male).

age

Age of the participant at baseline (years).

Systolic_BP

Systolic blood pressure (mmHg).

Diastolic_BP

Diastolic blood pressure (mmHg).

Heart_rate

Resting heart rate (beats per minute).

BMI

Body mass index (kg/m2).

Glucose

Fasting blood glucose (mg/dL).

Cholesterol

Total blood cholesterol (mg/dL).

GENE1, GENE2, GENE3, GENE4, GENE5, GENE6, GENE7, GENE8

Simulated molecular features (e.g. normalized gene expression).

Details

Data are fully synthetic and do not correspond to any real participant or study. Some molecular features were simulated to be associated with clinical variables: GENE1 with Systolic_BP (positive), GENE2 with Cholesterol (negative), GENE3 with Glucose (positive) and GENE4 with Heart_rate (negative). GENE5 to GENE8 have no association with clinical variables. Around 10% of follow-up visits were removed to mimic missed visits.

Source

Simulated data. The code used to generate the dataset is available in the data-raw folder of the package source.

Examples

data(example_omics)
head(example_omics)


Perform Longitudinal Analysis with Linear Mixed Models (LMM)

Description

This function automates the analysis of longitudinal clinical data using linear mixed models. It models clinical variables and returns a weighted matrix of model coefficient scores.

Usage

lmm_analysis(
  clinical_data,
  variables_to_scale,
  random_effects = "(1 | participant_id)"
)

Arguments

clinical_data

Dataframe containing clinical and metadata for participants, including identifier as participant_id.

variables_to_scale

Character vector of variable names to be analyzed.

random_effects

A character string specifying the random effects formula (default: "(1 | participant_id)").

Value

A matrix of model coefficient scores, where rows represent dependent variables and columns represent independent variables.


Multi-omics Longitudinal Analysis with Linear Mixed Models (LMM)

Description

This function builds a network between molecular features (e.g. genes or proteins) and clinical variables from longitudinal data using linear mixed models. Two sets of models are fitted: each clinical variable is modeled on all other clinical variables and the molecular features, and each molecular feature is modeled on the clinical variables. The weight of a feature-clinical edge is the mean of both t-values. Clinical-clinical and feature-feature edges are set to zero, so the network only contains feature-clinical edges.

Usage

lmm_integration_analysis(
  clinical_data,
  variables_to_scale,
  molecular_features,
  random_effects = "(1 | participant_id)"
)

Arguments

clinical_data

Dataframe containing clinical data, metadata and molecular features (one column per feature, samples merged with clinical data), including identifier as 'participant_id'.

variables_to_scale

Character vector of clinical variable names to be analyzed.

molecular_features

Character vector of molecular feature names (columns of 'clinical_data'). Names that are not syntactically valid in R (e.g. "H1-0") are allowed.

random_effects

A character string specifying the random effects formula (default: "(1 | participant_id)").

Value

A symmetric matrix of model coefficient scores with clinical variables followed by molecular features.

Examples

data(example_omics)
clinical_vars <- c("Systolic_BP", "Diastolic_BP", "Heart_rate", "BMI", "Glucose", "Cholesterol")
molecular_features <- paste0("GENE", 1:8)
net <- lmm_integration_analysis(example_omics, clinical_vars, molecular_features,
                                random_effects = "(1|participant_id)")
round(net[clinical_vars, molecular_features], 2)

Normalization of weighted linear mixed model network matrix.

Description

This function normalizes weighted adjacency matrix derived from lmm.

Usage

normalization(matrix)

Arguments

matrix

The adjacency matrix (to be normalized).

Value

a normalized matrix containing values between 0 and 1.


Compute Score Matrix

Description

This function adjusts an original matrix by copying the lower triangular part from a shifted matrix.

Usage

score_matrix(original_matrix, shifted_matrix)

Arguments

original_matrix

A numeric matrix representing the original data.

shifted_matrix

A numeric matrix that has been transformed using shift_matrix().

Value

A new matrix with adjusted values in the lower triangular part.


Shifted Matrix Transformation

Description

This function modifies the shape of a model weights matrix by shifting its elements.

Usage

shift_matrix(mat)

Arguments

mat

A numeric matrix to be transformed.

Value

A shifted version of the input matrix.