check_temporal_consistency: Check Consistency of Temporal Predictor Data

View source: R/helper_functions.R

check_temporal_consistencyR Documentation

Check Consistency of Temporal Predictor Data

Description

Verifies that the input list 'X' is properly formatted for the main temporal_forest function.

Usage

check_temporal_consistency(X)

Arguments

X

A list of numeric matrices or data frames, where each element is expected to represent a time point, with subjects as rows and predictors as columns.

Details

This helper function is called internally by temporal_forest() to perform critical input validation before any heavy computation begins. It checks for two main conditions:

  1. That the input X is a list containing data for at least two time points.

  2. That all data frames or matrices in the list have identical column names in the exact same order.

This prevents downstream errors during network construction and modeling, and provides a clear, informative error message to the user if their data format is incorrect.

Value

Returns TRUE invisibly if all consistency checks pass. If a check fails, it throws a specific error and stops execution.

Examples

# --- 1. A valid input that will pass ---
mat1 <- matrix(1:4, nrow = 2, dimnames = list(NULL, c("V1", "V2")))
mat2 <- matrix(5:8, nrow = 2, dimnames = list(NULL, c("V1", "V2")))
good_X <- list(mat1, mat2)

# This will run silently and return TRUE
check_temporal_consistency(good_X)

# --- 2. An invalid input that will fail ---
mat3 <- matrix(9:12, nrow = 2, dimnames = list(NULL, c("V1", "V3"))) # Mismatched colnames
bad_X <- list(mat1, mat3)

# This will throw an informative error
# We wrap it in try() to prevent the example from stopping
try(check_temporal_consistency(bad_X))


TemporalForest documentation built on Dec. 23, 2025, 1:06 a.m.