| Type: | Package |
| Title: | Relational Event and Durational Event Models |
| Version: | 1.0.0 |
| Date: | 2026-06-18 |
| Author: | Cornelius Fritz [aut, cre] |
| Maintainer: | Cornelius Fritz <corneliusfritz2010@gmail.com> |
| Description: | Model relational and durational events in a counting process framework, with functions for estimating and simulating Relational Event Models (REM) and Durational Event Models (DEM). Includes support for time-varying covariates, windowed statistics, and high-dimensional node-level fixed effects. References include Fritz et al. (2026) "Scalable Durational Event Models: Application to Physical and Digital Interactions" <doi:10.48550/arXiv.2504.00049>. |
| License: | GPL-3 |
| Depends: | R (≥ 4.0.0) |
| Imports: | Rcpp (≥ 1.0.12), data.table, MASS, survival, stats, grDevices, graphics, utils, digest |
| LinkingTo: | Rcpp, RcppProgress, RcppArmadillo |
| Suggests: | testthat (≥ 3.0.0), network, knitr, rmarkdown |
| VignetteBuilder: | knitr |
| Config/testthat/edition: | 3 |
| Encoding: | UTF-8 |
| URL: | https://corneliusfritz.github.io/redeem/ |
| BugReports: | https://github.com/corneliusfritz/redeem/issues |
| Config/roxygen2/version: | 8.0.0 |
| NeedsCompilation: | yes |
| Packaged: | 2026-06-17 21:52:02 UTC; corneliusfritz |
| Repository: | CRAN |
| Date/Publication: | 2026-06-22 16:20:07 UTC |
redeem: Scalable Durational Event Models
Description
The redeem package provides a comprehensive framework for the estimation of Durational Event Models (DEM) and Relational Event Models (REM).
Details
The package is built to handle relational event sequences where interactions have specific start and end times. It implements the scalable block-coordinate ascent algorithm described in Fritz et al. (2026), which allows for the estimation of high-dimensional actor-specific effects and time-varying baseline intensities.
Key functions:
Author(s)
Cornelius Fritz
References
Fritz, C., Rastelli, R., Fop, M., & Caimo, A. (2026). Scalable Durational Event Models: Application to Physical and Digital Interactions. arXiv:2504.00049.
See Also
Useful links:
Report bugs at https://github.com/corneliusfritz/redeem/issues
Initialize redeem Model Terms
Description
This is an internal dispatcher that calls the appropriate term initialization function.
Usage
InitRedeemTerm(
term_name,
arglist,
model_type,
process,
n_nodes,
directed = FALSE
)
Arguments
term_name |
The name of the term. |
arglist |
A list of arguments passed to the term in the formula. |
model_type |
Either "dem" or "rem". |
process |
Either "0-1" (incidence) or "1-0" (duration). |
n_nodes |
Number of nodes in the network. |
directed |
Logical; if TRUE, the model is directed. Used for term-specific logic. |
Internal helper to calculate predictions for gof
Description
Internal helper to calculate predictions for gof
Usage
calculate_predictions_helper(model, data)
Arguments
model |
A redeem_result object. |
data |
A data.table containing the covariates. |
Check Arguments for redeem Model Terms
Description
Internal helper to validate arguments and set defaults.
Usage
check.RedeemTerm(
arglist,
expected = list(),
defaults = list(),
allowed_processes = c("0-1", "1-0"),
allowed_models = c("dem", "rem"),
model_type = "dem",
directed = NULL,
directed_only = FALSE,
undirected_only = FALSE
)
Arguments
arglist |
List of arguments. |
expected |
List of expected types/values. |
defaults |
List of default values. |
allowed_processes |
Vector of allowed processes ("0-1", "1-0"). |
model_type |
Current model type. |
Validate the Structure of a Durational Event List
Description
This function checks the validity of a dyadic interaction matrix by ensuring that each interaction start event has a corresponding end event, that no interactions overlap within a dyad, and that no missing values are present.
Usage
check_matrix(df, return_matrix = FALSE, start_time = NULL)
Arguments
df |
A data frame with at least four columns, representing events, where:
|
return_matrix |
Logical; if TRUE, returns the (potentially repaired) event matrix.
Defaults to FALSE, in which case the function returns |
start_time |
Numeric; optional reference time for adding missing start events. Defaults to NULL, in which case the earliest time in the data is used. |
Details
The function performs the following checks:
Missing values: If any are found, a warning is issued and
FALSEis returned.Interaction pairing: Each start event (1) must have a corresponding end event (0) without overlap.
Non-overlapping intervals: Ensures that no start event occurs while another interaction is active.
Value
Logical; TRUE if all interactions are valid, FALSE otherwise.
If the data contains missing values, the function issues a warning and returns FALSE.
Examples
# Create a valid event matrix with durational events (start=1, end=0)
df <- matrix(c(
1.0, 1, 2, 1,
2.0, 1, 2, 0,
1.5, 3, 4, 1,
3.0, 3, 4, 0
), ncol = 4, byrow = TRUE)
colnames(df) <- c("time", "from", "to", "type")
# Check if the event matrix is valid
check_matrix(df)
Control Parameters for REDEEM Models
Description
Unified control object to manage estimation parameters for rem
and dem functions.
Usage
control.redeem(
it_max = 100,
tol = 1e-10,
accelerated = FALSE,
verbose = FALSE,
weighting = TRUE,
subsample = 1,
build_time = NULL,
use_glm = FALSE,
return_data = FALSE,
save_hist = TRUE,
estimate = "Blockwise",
legacy = FALSE,
check_matrix = FALSE,
inf_unidentifiable = TRUE
)
Arguments
it_max |
Integer; maximum number of iterations for the algorithm. Defaults to 100. |
tol |
Numeric; convergence tolerance. Defaults to 1e-10. |
accelerated |
Logical; if |
verbose |
Logical; if |
weighting |
Logical; whether to use weighting to group identical observations. Defaults to TRUE. |
subsample |
Numeric; proportion of data to subsample for internal GLM checks. Defaults to 1. |
build_time |
Numeric; time at which to start building the estimation dataset. Events before this time are used to compute statistics but not included as observations. Defaults to NULL, in which case all events are included. |
use_glm |
Logical; if |
return_data |
Logical; whether to return preprocessed data frames in the result. Defaults to FALSE. |
save_hist |
Logical; whether to save the iteration history of coefficients. Defaults to TRUE. |
estimate |
Character; estimation method for |
legacy |
Logical; if |
check_matrix |
Logical; whether to apply |
inf_unidentifiable |
Logical; whether to set unidentifiable
coefficients (e.g., actors with 0 event counts, globally
invariant/collinear covariates) to |
Value
A list of class "redeem_control" containing the specified
parameters.
Durational Event Model (DEM) Estimation
Description
Estimates a Durational Event Model (DEM) for relational event sequences where interactions have a duration.
Usage
dem(
events,
training_start = 0,
exogenous_end = NULL,
formula_0_1 = NULL,
formula_1_0 = NULL,
n_nodes = NULL,
directed = FALSE,
estimate_0_1 = NULL,
estimate_1_0 = NULL,
coef_0_1 = NULL,
coef_1_0 = NULL,
semiparametric = FALSE,
simultaneous_interactions = TRUE,
control = control.redeem()
)
Arguments
events |
A matrix of events with columns |
training_start |
Numeric; the time point at which to start the estimation. Defaults to 0. |
exogenous_end |
Numeric; the exogenous time point at which the observational period ends. Defaults to NULL, which implies that time when the final event was observed is taken as the end of the observational period. |
formula_0_1 |
A one-sided |
formula_1_0 |
A one-sided |
n_nodes |
Integer; the total number of actors in the network. If |
directed |
Logical; whether the interaction events are directed. Defaults to FALSE. |
estimate_0_1 |
Logical; whether to estimate the formation process.
Defaults to NULL, in which case it is estimated if |
estimate_1_0 |
Logical; whether to estimate the dissolution process.
Defaults to NULL, in which case it is estimated if |
coef_0_1 |
Numeric vector; initial coefficients for the formation model. If provided, this must be a concatenated vector of:
Defaults to NULL, in which case default starting values are automatically computed. |
coef_1_0 |
Numeric vector; initial coefficients for the dissolution model. If provided, this must be a concatenated vector of:
Defaults to NULL, in which case default starting values are automatically computed. |
semiparametric |
Logical; whether to use a semiparametric baseline. Defaults to FALSE. See the 'Semiparametric Baseline' section for details. |
simultaneous_interactions |
Logical; whether to allow simultaneous interactions (i.e. multiple active events for the same actor or dyad at the same time). Defaults to TRUE. |
control |
A list of control parameters from |
Details
The Durational Event Model (DEM) is a general framework for analyzing durational events, extending standard Relational Event Models (REM) by decoupling the modeling of event incidence from event duration. It characterizes the dynamics via two separate continuous-time counting processes:
- Formation Process (
0 \rightarrow 1) Counts the number of times that actor pair
(i,j)starts an interaction up to timet. The incidence intensity is denoted by\lambda_{i,j}^{0\rightarrow 1}(t | \mathscr{H}_t).- Dissolution Process (
1 \rightarrow 0) Counts the number of times that actor pair
(i,j)stops interacting up to timet. The dissolution intensity is denoted by\lambda_{i,j}^{1\rightarrow 0}(t | \mathscr{H}_t).
Under the assumption that the processes are non-homogeneous Poisson processes, the intensities are modeled as:
\lambda_{i,j}^{0\rightarrow 1}(t | \mathscr{H}_t, \theta^{0\rightarrow 1}) = \exp(s_{i,j}^{0\rightarrow 1}(\mathscr{H}_t)^\top \alpha^{0\rightarrow 1} + \beta_i^{0\rightarrow 1} + \beta_j^{0\rightarrow 1} + f(t, \gamma^{0\rightarrow 1}))
\lambda_{i,j}^{1\rightarrow 0}(t | \mathscr{H}_t, \theta^{1\rightarrow 0}) = \exp(s_{i,j}^{1\rightarrow 0}(\mathscr{H}_t)^\top \alpha^{1\rightarrow 0} + \beta_i^{1\rightarrow 0} + \beta_j^{1\rightarrow 0} + f(t, \gamma^{1\rightarrow 0}))
where:
-
s_{i,j}(\mathscr{H}_t)is a vector of dynamic network statistics capturing the history of past interactions\mathscr{H}_t. -
\alphais a parameter vector determining the covariate effects. -
\beta_iand\beta_jare actor-specific sociality/popularity parameters (degree correction) capturing actor heterogeneity. -
f(t, \gamma)is a piecewise-constant step function modeling temporal baseline fluctuations across a set of changepoints.
To satisfy the Feller criterion and ensure that the continuous-time
counting process remains non-explosive, count-based network statistics
(such as inertia or common partners) are typically log-transformed on
the \log(x + 1) scale.
Value
An object of class dem_object containing model estimates,
log-likelihoods, and preprocessed data. See dem_object
for details on the components of the returned object and S3 methods.
Scalable Estimation Algorithm
The likelihood of the model is separable with respect to
\theta^{0\rightarrow 1} and \theta^{1\rightarrow 0}, allowing
independent estimation of the incidence and duration components.
Traditional maximum likelihood estimation via standard Newton-Raphson
requires computing and inverting an O(N^2) Hessian matrix, which
is computationally prohibitive for larger networks. To bypass this, the
redeem package implements a highly scalable block-coordinate
ascent algorithm that separates parameter updates:
-
Step 1: Update covariate parameters
\alphausing a standard Newton-Raphson update. -
Step 2: Update high-dimensional actor popularity baselines
\betausing Minorization-Maximization (MM) steps, avoiding explicit matrix inversion. -
Step 3: Update baseline step function parameters
\gammavia a closed-form step.
More information is provided in Fritz et at. (2026).
Semiparametric Baseline
When semiparametric = TRUE, the baseline rates for both the formation
(0 \rightarrow 1) and dissolution (1 \rightarrow 0) processes are
left completely unspecified. Both processes are estimated as separate Cox proportional
hazards models using the survival package. In this path:
For the formation process, each start event (1) is treated as a failure, and all inactive dyads at that time constitute the risk set.
For the dissolution process, each end event (0) is treated as a failure, and all currently active interactions constitute the risk set.
The exact waiting times (durations of the active and inactive states) are conditioned out, and estimation is based solely on the ordering of events and the relative dyadic intensities at each transition time.
This approach is highly robust to arbitrary temporal fluctuations in baseline rates since no piecewise-constant temporal baselines or changepoints need to be specified.
-
Limitations: This path does not support the specialized scalable estimation of sender/receiver popularity effects (
degree) or piecewise-constant temporal baselines.
References
Fritz, C., Rastelli, R., Fop, M., & Caimo, A. (2026). Scalable Durational Event Models: Application to Physical and Digital Interactions. arXiv:2504.00049.
Examples
# Simulate some durational data
n <- 20
events <- matrix(c(
1.2, 1, 5, 1,
2.5, 1, 5, 0,
3.1, 2, 8, 1,
4.4, 2, 8, 0
), ncol = 4, byrow = TRUE)
colnames(events) <- c("time", "from", "to", "type")
# Estimate a simple DEM
fit <- dem(
events = events,
n_nodes = n,
formula_0_1 = ~1,
formula_1_0 = ~1,
control = control.redeem(estimate = "Blockwise")
)
summary(fit)
Simulate events based on specified formulas and coefficients
Description
Simulate events based on specified formulas and coefficients
Usage
dem.simulate(
events = matrix(0, 0, 4),
formula_0_1 = NULL,
formula_1_0 = NULL,
coef_0_1 = numeric(0),
coef_1_0 = numeric(0),
coef_degree_0_1 = 0,
coef_degree_1_0 = 0,
n_events = 0,
time = 0,
max_events = 4e+05,
n_nodes,
verbose = FALSE,
baseline_0_1 = NULL,
baseline_1_0 = NULL,
simultaneous_interactions = TRUE,
seed = 123,
directed = FALSE
)
Arguments
events |
A matrix representing the initial events with columns |
formula_0_1 |
A one-sided |
formula_1_0 |
A one-sided |
coef_0_1 |
Numeric vector; coefficients for the formation process ( |
coef_1_0 |
Numeric vector; coefficients for the dissolution process ( |
coef_degree_0_1 |
Numeric; degree coefficient for the formation process ( |
coef_degree_1_0 |
Numeric; degree coefficient for the dissolution process ( |
n_events |
Integer; number of events to simulate. Defaults to 0. |
time |
Numeric; simulation time limit. Defaults to 0. |
max_events |
Integer; maximum number of total events. Defaults to 400000. |
n_nodes |
Integer; the total number of actors in the network. |
verbose |
Logical; if |
baseline_0_1 |
Numeric vector; baseline for the 0 to 1 transition. If the formula for this process
contains an |
baseline_1_0 |
Numeric vector; baseline for the 1 to 0 transition. Similar to |
simultaneous_interactions |
Logical; whether to allow simultaneous interactions (i.e. multiple active events for the same actor or dyad at the same time). Defaults to TRUE. |
seed |
Integer; random seed for simulation. Defaults to 123. |
directed |
Logical; whether the interaction events are directed. Defaults to FALSE. |
Value
A matrix of simulated events.
Note
Multi-stream event models are currently not supported in simulation.
Examples
# Simulate events from a DEM model structure
n <- 10
f_0_1 <- ~ 1 + inertia(transformation = "identity")
f_1_0 <- ~ 1
# Simulating events
evs <- dem.simulate(
formula_0_1 = f_0_1,
formula_1_0 = f_1_0,
n_nodes = n,
time = 2.0,
coef_0_1 = c(1.0, 0.5),
coef_1_0 = c(-0.5),
seed = 42,
max_events = 100
)
head(evs)
The dem Object
Description
An object of class dem returned by the dem function,
representing a fitted Durational Event Model.
Value
A dem object is a list containing the following components:
-
call: The matched call. -
event_numbers: A vector containing the number of events. -
model_0_1: The fitted model for transition 0 -> 1 (formation). -
model_1_0: The fitted model for transition 1 -> 0 (dissolution). -
events: The preprocessed event matrix. -
formula_0_1: The formula for transition 0 -> 1. -
formula_1_0: The formula for transition 1 -> 0. -
n_nodes: The number of nodes. -
simultaneous_interactions: Logical indicating whether simultaneous interactions were allowed. -
directed: Logical indicating whether the events are directed. -
training_start: The start time of the training period. -
build_time: The time at which the estimation dataset started building. -
max_time: The maximum event time. -
exogenous_end: The end time of the exogenous period. -
time_changepoints: Time points where baseline intensity changes. -
labels_changepoints: Labels for the time intervals. -
subsample: Subsample proportion used. -
return_data: Logical indicating whether preprocessed data frames were returned. -
runtime: The estimation runtime. -
window_map: The window map used for calculation. -
preprocessed: Preprocessed data structures.
Methods (S3)
The following S3 methods are implemented for dem objects:
-
print(x, ...): Prints a brief summary of the DEM model.-
x: Ademobject. -
...: Additional arguments passed to printing function.
-
-
summary(object, ...): Summarizes model results, including parameter estimates, standard errors, and fit statistics (AIC/BIC). Returns an object of classsummary.dem.-
object: Ademobject. -
...: Additional arguments passed to summary method.
-
-
plot(x, which = 3, separate = FALSE, baseline = FALSE, ...): Generates trace plots for coefficients and log-likelihood histories.-
x: Ademobject. -
which: Integer indicating transition plots to display. Options are1for formation (0 -> 1),2for dissolution (1 -> 0), or3(default) for both. -
separate: Logical. IfTRUE, each plot is generated in a new window or as a separate sequence. Defaults toFALSE. -
baseline: Logical. IfTRUE, plots the estimated baseline step function. Defaults toFALSE. -
...: Additional arguments passed to the underlying trace plotting method. Supported parameters include:-
coefs: Logical. IfTRUE(default), plots iteration traces for core/fixed coefficients. -
degree: Logical. IfTRUE(default), plots iteration traces for degree/actor effects. -
time: Logical. IfTRUE(default), plots iteration traces for temporal baseline effects. -
llh: Logical. IfTRUE(default), plots trace of log-likelihood history. -
sub_label: Character. Optional subtitle to display at the bottom of the figure.
-
-
-
plot_baseline(x, process = c("formation", "dissolution"), ...): Plots the step function of the estimated baseline intensity.-
x: Ademobject. -
process: Character. Specifies whether to plot the baseline for"formation"(0 -> 1) (default) or the"dissolution"(1 -> 0) process. -
...: Additional graphical parameters passed toplot.
-
-
predict(object, time = NULL, type = c("response", "lp", "terms"), process = c("both", "formation", "dissolution"), ...): Predicts the intensity, linear predictor, or term contributions for a fitted DEM model.-
object: Ademobject. -
time: Numeric vector; optional time point(s) at which to predict. Defaults to NULL. -
type: Character; the type of prediction. Defaults to"response". -
process: Character; the transition process to predict. Defaults to"both". -
...: Additional arguments.
-
MM Algorithm for Durational Event Models with Time-Varying Effects
Description
Implementation of the scalable block-coordinate ascent algorithm for DEMs with time-varying baseline intensities. This function performs iterative Minorization-Maximization (MM) updates for degree and temporal effects while using Newton-Raphson for core covariates.
Usage
estimate_mmt(
data,
indicators,
it_max,
n_nodes,
tol = 1e-10,
accelerated = TRUE,
time_changepoints = NULL,
labels_changepoints = NULL,
subsample = 0.2,
verbose = FALSE,
est_degree = NULL,
est_core = NULL,
est_time = NULL,
estimate_degree = TRUE,
directed = FALSE,
return_data = TRUE,
save_hist = TRUE,
use_glm = FALSE,
inf_unidentifiable = TRUE
)
Arguments
data |
Preprocessed data.table. |
indicators |
Numeric vector of covariate indices. |
it_max |
Maximum number of iterations. |
n_nodes |
Number of nodes. |
tol |
Convergence tolerance. |
accelerated |
Logical; use SQUAREM acceleration for degree effects. |
time_changepoints |
Numeric vector of time changepoints. |
labels_changepoints |
Character vector of labels for time slices. |
subsample |
Subsampling rate for GLM backup estimation. |
verbose |
Logical; print progress. |
est_degree |
Initial degree coefficients. |
est_core |
Initial core coefficients. |
est_time |
Initial time effects. |
estimate_degree |
Logical; estimate degree effects. |
directed |
Logical; whether the network is directed. |
return_data |
Logical; whether to return the preprocessed data in the result. |
save_hist |
Logical; whether to save the iteration history of coefficients. |
use_glm |
Logical; whether to use GLM-based core updates as fallback or control. |
inf_unidentifiable |
Logical; if TRUE, unidentifiable parameters are set to -Inf. |
Details
The algorithm decomposes the log-likelihood and updates blocks of parameters sequentially. Specifically:
Core effects (
\beta) are updated via Newton-Raphson.Degree effects (
\alpha) are updated using an MM step that avoids explicit Hessian inversion for high-dimensional actor sets.Temporal effects (
\gamma) are updated via a similar MM step across defined time changepoints.
Core Estimation Logic for REM and DEM Transitions
Description
This internal helper function encapsulates the estimation routines for a single relational or durational event transition. It is used by both 'rem()' and 'dem()'.
Usage
estimate_transition(
data,
formula_original,
formula_new,
indicators,
n_nodes,
estimate_method,
it_max,
tol,
accelerated,
subsample,
verbose,
estimate_degree,
directed,
semiparametric = FALSE,
labels_changepoints = NULL,
time_changepoints = NULL,
coef_init = NULL,
model_type = "dem",
process = "0-1",
return_data = TRUE,
save_hist = TRUE,
use_glm = FALSE,
legacy = FALSE,
inf_unidentifiable = TRUE,
events = NULL
)
Preprocess Formulas for Model Terms with Event and Node Information
Description
This function processes two model formulas, each of which can specify transformation and data arguments, and combines the preprocessed results with additional event and node information. It identifies unique coefficient names across both formulas, determining which terms to include based on uniqueness, and returns structured lists for data, transformations, and term names.
Usage
formula_preprocess(
formula_0_1 = NULL,
model_type = "dem",
formula_1_0 = NULL,
events = matrix(c(0, 0, 0), nrow = 1),
n_nodes,
exo_breaks = NULL,
directed = FALSE,
simulation = FALSE
)
Arguments
formula_0_1 |
Optional; an R formula for the '0 -> 1' terms. |
model_type |
Either "dem" or "rem". |
formula_1_0 |
Optional; an R formula for the '1 -> 0' terms. |
events |
A data frame or list representing the events. |
n_nodes |
An integer specifying the number of nodes. |
exo_breaks |
Optional; a vector or list specifying external breaks. |
directed |
Logical; if TRUE, the model is directed (defaults to FALSE). |
simulation |
Logical; if TRUE, the formula is being preprocessed for simulation (defaults to FALSE). |
Details
The function first calls 'formula_preprocess_single' on 'formula_1_0' and 'formula_0_1' separately to obtain individual term processing details. It then identifies unique terms across both formulas and combines the term data, transformations, and coefficient names into a single output list, structured for use in further modeling or evaluation.
Value
A list containing the following components:
events |
The events input, retained for use in model estimation or evaluation. |
n_nodes |
The number of nodes specified in the input. |
data_list |
A combined list of matrices for each term’s data, from both formulas, where each matrix corresponds to the data for a specific term. |
transformation_list |
A combined character vector of transformation types for each term, with '"identity"' for terms without specified transformations. |
coef_names |
A character vector of coefficient names for each term, combining terms across both formulas and ensuring uniqueness. |
term_names |
A character vector of term names, ordered to match 'data_list'. |
preprocess_1_0 |
The output list from 'formula_preprocess_single' applied to 'formula_1_0'. |
preprocess_0_1 |
The output list from 'formula_preprocess_single' applied to 'formula_0_1'. |
included_1_0 |
A logical vector indicating whether each term in 'coef_names' comes from 'formula_1_0'. |
included_0_1 |
A logical vector indicating whether each term in 'coef_names' comes from 'formula_0_1'. |
A list containing the preprocessed information.
See Also
Preprocess a single formula for model terms
Description
This function takes an R formula and extracts the necessary information to build the model's design matrix. It identifies special terms, transformations, and associated data.
Usage
formula_preprocess_single(
formula,
n_nodes,
model_type = "dem",
process = "0-1",
directed = FALSE,
simulation = FALSE
)
Arguments
formula |
An R formula object. |
n_nodes |
Number of nodes. |
model_type |
Either "dem" or "rem". |
process |
Either "0-1" (incidence) or "1-0" (duration). |
directed |
Logical; if TRUE, the model is directed (defaults to FALSE). |
simulation |
Logical; if TRUE, the formula is being preprocessed for simulation (defaults to FALSE). |
Out-of-sample Log-Likelihood (Proper Scoring Rule)
Description
This function computes the out-of-sample log-likelihood (a strictly proper scoring rule) for each test event under a fitted REM or DEM.
Usage
get_oos_likelihood(
object,
verbose = FALSE,
edgelist_test,
edgelist_train = NULL,
baseline_method = c("last", "trend", "mean", "beginning"),
loess_span = 0.75
)
Arguments
object |
|
verbose |
Logical; if 'TRUE', prints verbose output. Defaults to FALSE. |
edgelist_test |
A matrix or data frame of test events (timing, from, to, type). |
edgelist_train |
A matrix or data frame of train events (timing, from, to, type). Defaults to 'NULL', in which case it retrieves the training events from the 'object' or the preprocessed data. |
baseline_method |
Character; how to compute the fixed log-baseline intensity used for out-of-sample scoring. One of: '"last"' (uses the last estimated baseline value), '"trend"' (extrapolates a LOESS trend), '"mean"', or '"beginning"'. Defaults to '"last"'. |
loess_span |
Numeric; LOESS span (0, 1] passed to
|
Value
A numeric vector of log-likelihoods for each test event.
See Also
rem_object and dem_object for details on prediction methods.
Get ranking for test events (Out-of-Sample Goodness-of-Fit)
Description
Evaluates the out-of-sample predictive performance of a fitted model on a test event sequence using a ranking-based Goodness-of-Fit (GoF) procedure.
Usage
get_ranking(
object,
verbose = FALSE,
k_max = 1000,
edgelist_test,
edgelist_train = NULL,
ties.method = c("average", "first", "last", "random", "max", "min"),
return_probabilities = FALSE,
baseline_method = c("trend", "mean", "last", "beginning"),
loess_span = 0.75
)
Arguments
object |
|
verbose |
Logical; if 'TRUE', prints verbose output. Defaults to FALSE. |
k_max |
Maximum number of ranked pairs to return. Defaults to 1000. |
edgelist_test |
A matrix of test events (timing, from, to, type). |
edgelist_train |
A matrix of train events (timing, from, to, type). Defaults to NULL. |
ties.method |
Character; the method to handle ties when ranking event intensities,
passed directly to
|
return_probabilities |
Logical; if TRUE, returns the predicted probabilities/scores instead of recall curves. Defaults to FALSE. |
baseline_method |
Character; how to compute the fixed log-baseline
intensity used for out-of-sample scoring. Defaults to
|
loess_span |
Numeric; LOESS span (0, 1] passed to
|
Details
For each event observed in the test period (edgelist_test), the function:
Determines the set of all potential candidate dyads (the risk set) at that event's timestamp.
Computes the predicted event intensities (or probabilities) for all candidate dyads using the fitted model's parameters and the network history up to that moment.
Ranks all candidate dyads in descending order of their predicted intensities.
Determines the rank of the actually observed dyad.
A well-fitting model will consistently assign higher intensities to the dyads that actually interact, ranking them near the top.
The function summarizes the rankings across all test events to compute:
-
Mean Reciprocal Rank (MRR): The average of the reciprocal ranks of the true dyads.
-
Recall at K: The proportion of test events where the true dyad is ranked within the top
Kcandidate dyads. -
Precision at K: The proportion of top
Krecommendations that correspond to true events.
Value
A ranking_redeem data frame with columns:
CutpointInteger value from 0 to
k_max.RecallThe proportion of test events where the true dyad is ranked at or within the cutpoint.
PrecisionThe precision value at the cutpoint.
Additionally, the returned object has the following attributes:
"mrr"Mean Reciprocal Rank (MRR) of the true dyads.
"mean_rank"Mean rank of the true dyads (excluding ranks >
k_max)."median_rank"Median rank of the true dyads (excluding ranks >
k_max)."hits_summary"A data frame summarizing Recall, Precision, and F1 values at K = 1, 5, 10, and 50.
Get residuals for model diagnostics (Cox-Snell Residuals)
Description
Computes Cox-Snell residuals for a fitted model to diagnose goodness-of-fit and calibration.
Usage
get_residuals(object, get_0_1 = TRUE, get_1_0 = TRUE, raw = FALSE)
Arguments
object |
|
get_0_1 |
Logical; if 'TRUE', computes residuals for the formation (0 -> 1) process. Defaults to TRUE. |
get_1_0 |
Logical; if 'TRUE', computes residuals for the dissolution (1 -> 0) process. Defaults to TRUE. |
raw |
Logical; if 'TRUE', returns the raw Cox-Snell residuals. Defaults to FALSE. |
Details
Cox-Snell residuals are a standard diagnostic tool for continuous-time
survival models and counting processes.
Under the true model specification, the integrated cumulative intensity
computed up to the exact time of an observed event
is distributed as a standard exponential random variable, i.e.,
\Lambda_{ij}(t_k) \sim Exp(1).
Consequently, if the model is correctly specified:
The empirical survival function of these residuals should closely match the theoretical survival function of a standard exponential distribution,
S(r) = \exp(-r).Deviations between the empirical Kaplan-Meier curve of the residuals and the theoretical exponential curve signal model misspecification, unmodeled dyadic heterogeneity, or non-stationarity.
The function can compute residuals for both the formation/incidence
(0 \rightarrow 1) process and the dissolution/duration
(1 \rightarrow 0) process.
Value
If 'raw = TRUE', a list containing the raw residuals for the selected process(es). If 'raw = FALSE', a list of data frames containing the Kaplan-Meier coordinates ('time', 'surv') and the corresponding 'theoretical' standard exponential survival values.
References
Cox, D. R., & Snell, E. J. (1968). A general definition of residuals. Journal of the Royal Statistical Society: Series B (Methodological), 30(2), 248-265.
Match user-provided coefficients to internal model names
Description
Match user-provided coefficients to internal model names
Usage
match_coefficients(user_coefs, internal_names, internal_keys = NULL)
Arguments
user_coefs |
Named or unnamed vector of coefficients provided by the user. |
internal_names |
Vector of internal coefficient names (labels). |
internal_keys |
Vector of internal coefficient keys (e.g., intercept, dyadic_cov_identity). |
Value
A numeric vector of the same length as internal_names.
Plot the Estimated Baseline Intensity
Description
Draws a step-function plot of the estimated piecewise-constant baseline
intensity against time. The function dispatches to class-specific methods
for dem, rem, and redeem_result objects.
Usage
plot_baseline(x, ...)
Arguments
x |
|
... |
Additional arguments passed to |
Value
The original object x is returned invisibly. Called
primarily for its side effect of producing a plot.
Predict the baseline intensity trend at one or more future time points
Description
Decomposes the estimated piecewise-constant log-baseline (est_time)
into a smooth trend component (via LOESS) and a seasonal/residual component,
following the same approach used in the application plot script. The fitted
trend is then extrapolated to target_times using
predict.loess() so that the baseline used for out-of-sample scoring
reflects the long-run level of activity rather than any arbitrary fixed
value.
Usage
predict_baseline_trend(model, target_times, loess_span = 0.75)
Arguments
model |
A |
target_times |
Numeric vector: the times at which to predict the trend (typically the unique timestamps of the test events). |
loess_span |
Numeric; the span argument passed to |
Details
The decomposition mirrors the plot code in the application:
Build a data frame of
(time, est_time)using the changepoints stored inmodel$time_changepoints. The first interval [0, changepoint_1) is given time = 0; each subsequent interval gets the corresponding changepoint value.Fit LOESS on the log-scale
est_timevalues.Predict at each
target_times; predictions are clamped to the range of the observedest_timeto avoid wild extrapolation.
Value
A numeric vector of predicted log-baseline (trend component) values,
one per element of target_times. Falls back to
mean(est_time) for each time point if there are fewer than 3
observations or if the LOESS fit fails.
Helper to predict single transition process
Description
Helper to predict single transition process
Usage
predict_transition_helper(model, data, type)
Internal helper to prepare residual plot data
Description
Internal helper to prepare residual plot data
Usage
prepare_residual_plot_data(raw_list)
Arguments
raw_list |
List of raw residuals |
Preprocess Model Terms across Multiple Event Streams
Description
Preprocess Model Terms across Multiple Event Streams
Usage
preprocess_multi_stream(
preprocessed,
n_nodes,
verbose,
directed,
simultaneous_interactions,
build_time = NULL,
max_time = -1,
model_type = "dem",
impute_zero = TRUE,
omit_na = TRUE
)
Arguments
preprocessed |
Standard output from 'formula_preprocess'. |
n_nodes |
Number of nodes. |
verbose |
Logical; if TRUE, print progress. |
directed |
Logical; if TRUE, the model is directed. |
simultaneous_interactions |
Logical; if TRUE, multiple interactions are allowed. |
build_time |
Numeric; time at which to start building the dataset. |
max_time |
Numeric; if positive, events after this time are excluded.
Defaults to |
model_type |
Either "dem" or "rem". |
impute_zero |
Logical; if TRUE, replace NAs in covariates with 0. |
omit_na |
Logical; if TRUE, call na.omit() on the final table. |
Value
A data.table containing the unified preprocessed data.
Process event actor columns and automatically identify or validate n_nodes
Description
Process event actor columns and automatically identify or validate n_nodes
Usage
process_event_actors(events, n_nodes = NULL, directed = TRUE)
Arguments
events |
A matrix or data frame of events with columns |
n_nodes |
Integer; the total number of actors in the network, or |
directed |
Logical; whether the interaction events are directed. Defaults to TRUE. |
Value
A list containing events (potentially modified) and n_nodes.
redeem Model Terms
Description
The help pages of rem and dem describe the model
formulation and estimation details. This page documents all statistics
available to be used in the model formulas, characterizing the intensities
of event formation and dissolution.
In the redeem framework, models like DEM (fitted via dem)
and REM (fitted via rem) are specified using R formulas.
The right-hand side of these formulas defines the structural statistics and
covariates, where each term must be specified separately as an explicit
function call (e.g., ~ inertia() + reciprocity(window = 10)).
All terms support an optional transformation argument f.
The available transformations are:
-
"identity"(default):f(x) = x -
"log":f(x) = \log(x + 1) -
"recip":f(x) = 1/(x+1) -
"bin":f(x) = I(x > 0) -
"sig": sigmoid-like saturation,f(x) = x/(x + K)
Throughout, N_{i,j}(t) denotes the cumulative number of events from
i to j up to (but not including) time t;
N_{i,j}^w(t) is the windowed analogue on (t-w,\,t);
d_i^{\mathrm{out}}(t) = |\{l: N_{i,l}(t)>0\}| is the historical
out-degree of i; and c_i^{\mathrm{out}}(t) = \sum_l N_{i,l}(t)
is the total event count sent by i.
The superscript \mathrm{act} indicates that the quantity is computed
on the currently active DEM network.
The implemented terms are grouped into five categories:
-
Baseline and Nuisance Terms: Intercept, time-varying baseline, and degree fixed effects.
-
Endogenous Dyadic Terms: Inertia, reciprocity, interaction duration, and participation shifts.
-
Triadic Closure and Shared Partners: Common partners and triangle statistics.
-
Degree and Centrality Statistics: Actor degree and event count statistics.
-
Exogenous Covariates: Dyadic and monadic covariate terms.
Arguments
K |
Numeric; the evaluation point or scaling/saturation factor for the sufficient statistic (default is 1). |
transformation |
Character; specifies the transformation to apply to the statistic. One of:
|
event_stream |
Optional matrix or data frame; an alternative event
stream to use for calculating the statistic. If |
window |
Numeric; time window for calculating the statistic (default
|
type |
Character; the specific variation of the statistic or triangle
type (e.g., |
mode |
Character; the participation shift mode (e.g., |
data |
For |
fun |
A function taking two arguments |
change_points |
Optional numeric vector; time points for time-varying
covariates if |
changepoints |
Numeric vector; time points where the baseline intensity is allowed to change. |
labels |
Character vector; optional labels for the resulting time intervals. |
history |
Character; |
count |
Logical; if |
... |
Arguments passed to the underlying initialization function. |
Value
A redeem_term object (a list containing structural information about the statistic) to be used inside model formulas.
Multi-Stream Event Covariates
Most endogenous terms support covariates calculated from multiple event
streams. By providing an event_stream argument to a term (e.g.,
inertia(event_stream = other_events)), users can model one event
process while accounting for the history of another. The package
automatically handles the splintering and union of these timelines.
Baseline and Nuisance Terms
-
Intercept(): Intercept: Constant log-intensity baseline.s_{i,j}(t) = 1. Also available asintercept(). -
baseline(changepoints, labels): Baseline: Stepwise constant log-baseline with user-specified change pointsc_1 < c_2 < \ldots < c_K.s_{i,j}(t) = \sum_{k=1}^{K} I(t \in [c_k, c_{k+1})). Coefficients are treated as nuisance parameters. -
degree/degrees: Degree Fixed Effects: Node-specific sender and receiver baselines\alpha_iand\gamma_jestimated via Minorization-Maximization (MM). Contribution to linear predictor:\alpha_i + \gamma_j. Treated as nuisance parameters.
Endogenous Dyadic Terms
-
inertia(transformation, K, event_stream, window): Inertia: Cumulative count of past events fromitoj.s_{i,j}(t) = f(N_{i,j}(t)); windowed:f(N_{i,j}^w(t)). -
reciprocity(transformation, K, event_stream, window): Reciprocity: Cumulative count of past events fromjtoi.s_{i,j}(t) = f(N_{j,i}(t))(Directed only). -
current_interaction(transformation, K, event_stream): Duration: Time elapsed since the currently active event(i,j)started.s_{i,j}(t) = f(t - t_{\mathrm{start},i,j})(DEM only). Alias:duration(). -
Participation Shifts (for two consecutive events
(A \to B) \to (C \to D), each statistic is 1 if the specified pattern holds, 0 otherwise; REM only, Directed only):-
psABBA(event_stream): PS-ABBA: Receiver responds to sender.s_{C,D}(t) = I(C = B,\, D = A). -
psABBY(event_stream): PS-ABBY: Receiver initiates to a new target.s_{C,D}(t) = I(C = B,\, D \ne A). -
psABAY(event_stream): PS-ABAY: Sender initiates to a new target.s_{C,D}(t) = I(C = A,\, D \ne B). -
psABXA(event_stream): PS-ABXA: Outsider targets original sender.s_{C,D}(t) = I(C \ne A, C \ne B,\, D = A). -
psABXB(event_stream): PS-ABXB: Outsider targets original receiver.s_{C,D}(t) = I(C \ne A, C \ne B,\, D = B). -
psABXY(event_stream): PS-ABXY: Entirely new dyad.s_{C,D}(t) = I(C \ne A, C \ne B,\, D \ne A, D \ne B). -
ps(mode, event_stream): PS Shorthand: Dispatches to one of the six participation shift statistics above based onmode(one of"ABBA","ABBY","ABAY","ABXA","ABXB","ABXY").
-
Triadic Closure and Shared Partners
-
general_common_partners(transformation, K, type,event_stream, window): Historical Common Partners: Number of nodesksharing a historical directed path of the specified type with bothiandj.s_{i,j}(t) = f(|CP_{i,j}^{\mathrm{type}}(t)|).-
"OSP"(Outgoing Shared Partner):N_{i,k}(t)>0andN_{j,k}(t)>0. -
"ISP"(Incoming Shared Partner):N_{k,i}(t)>0andN_{k,j}(t)>0. -
"OTP"(Outgoing Two-Path):N_{i,k}(t)>0andN_{k,j}(t)>0. -
"ITP"(Incoming Two-Path):N_{k,i}(t)>0andN_{j,k}(t)>0.
Aliases:
general_common_partner(),general_common_partner_OSP(),general_common_partner_ISP(),general_common_partner_OTP(),general_common_partner_ITP(). -
-
current_common_partners(transformation, K, type,event_stream): Active Common Partners: Asgeneral_common_partnersbut restricted to currently active edges.s_{i,j}(t) = f(|CP_{i,j}^{\mathrm{type,act}}(t)|)(DEM only). Aliases:current_common_partner(),current_common_partner_OSP(),current_common_partner_ISP(),current_common_partner_OTP(),current_common_partner_ITP(). -
general_triangle(transformation, K, type, event_stream, window): Historical Triangles: Number of closed triads around(i,j)in the historical event network of the specified type.s_{i,j}(t) = f(|\Delta_{i,j}^{\mathrm{type}}(t)|)(Directed only). -
current_triangle(transformation, K, type, event_stream): Active Triangles: Asgeneral_trianglebut restricted to currently active edges. (DEM only, Directed only). -
common_partner(history, type, ...): Common Partner Shorthand: Dispatches togeneral_common_partners()(history="general") orcurrent_common_partners()(history="current"). -
triangle(history, type, ...): Triangle Shorthand: Dispatches togeneral_triangle()(history="general") orcurrent_triangle()(history="current").
Degree and Centrality Statistics
-
general_degree_out_sender(transformation, K, event_stream, window): Sender Out-Degree: Historical out-degree of senderi.s_{i,j}(t) = f(d_i^{\mathrm{out}}(t))(Directed only). -
general_degree_out_receiver(transformation, K, event_stream, window): Receiver Out-Degree: Historical out-degree of receiverj.s_{i,j}(t) = f(d_j^{\mathrm{out}}(t))(Directed only). -
general_degree_in_sender(transformation, K, event_stream, window): Sender In-Degree: Historical in-degree of senderi.s_{i,j}(t) = f(d_i^{\mathrm{in}}(t))(Directed only). -
general_degree_in_receiver(transformation, K, event_stream, window): Receiver In-Degree: Historical in-degree of receiverj.s_{i,j}(t) = f(d_j^{\mathrm{in}}(t))(Directed only). -
general_degree_sum(transformation, K, event_stream, window): Degree Sum: Sum of historical degrees of both endpoints.s_{i,j}(t) = f(d_i(t) + d_j(t))(Undirected only). -
general_degree_absdiff(transformation, K, event_stream, window): Degree Absolute Difference: Absolute difference in historical degrees.s_{i,j}(t) = f(|d_i(t) - d_j(t)|)(Undirected only). -
general_count_out_sender(transformation, K, event_stream, window): Sender Out-Count: Total events sent by senderi.s_{i,j}(t) = f(c_i^{\mathrm{out}}(t))(Directed only). -
general_count_out_receiver(transformation, K, event_stream, window): Receiver Out-Count: Total events sent by receiverj.s_{i,j}(t) = f(c_j^{\mathrm{out}}(t))(Directed only). -
general_count_in_sender(transformation, K, event_stream, window): Sender In-Count: Total events received by senderi.s_{i,j}(t) = f(c_i^{\mathrm{in}}(t))(Directed only). -
general_count_in_receiver(transformation, K, event_stream, window): Receiver In-Count: Total events received by receiverj.s_{i,j}(t) = f(c_j^{\mathrm{in}}(t))(Directed only). -
general_count_sum(transformation, K, event_stream, window): Count Sum: Sum of total event counts of both endpoints.s_{i,j}(t) = f(c_i(t) + c_j(t))(Undirected only). -
general_count_absdiff(transformation, K, event_stream, window): Count Absolute Difference: Absolute difference in total event counts.s_{i,j}(t) = f(|c_i(t) - c_j(t)|)(Undirected only). -
current_degree_out_sender(transformation, K, event_stream): Active Sender Out-Degree: Out-degree ofiin the active DEM network.s_{i,j}(t) = f(d_i^{\mathrm{out,act}}(t))(DEM only, Directed only). -
current_degree_out_receiver(transformation, K, event_stream): Active Receiver Out-Degree: Out-degree ofjin active DEM network.s_{i,j}(t) = f(d_j^{\mathrm{out,act}}(t))(DEM only, Directed only). -
current_degree_in_sender(transformation, K, event_stream): Active Sender In-Degree: In-degree ofiin the active DEM network.s_{i,j}(t) = f(d_i^{\mathrm{in,act}}(t))(DEM only, Directed only). -
current_degree_in_receiver(transformation, K, event_stream): Active Receiver In-Degree: In-degree ofjin active DEM network.s_{i,j}(t) = f(d_j^{\mathrm{in,act}}(t))(DEM only, Directed only). -
current_degree_sum(transformation, K, event_stream): Active Degree Sum: Sum of active degrees of both endpoints.s_{i,j}(t) = f(d_i^{\mathrm{act}}(t) + d_j^{\mathrm{act}}(t))(DEM only, Undirected only). -
current_degree_absdiff(transformation, K, event_stream): Active Degree Absolute Difference: Absolute difference in active degrees.s_{i,j}(t) = f(|d_i^{\mathrm{act}}(t) - d_j^{\mathrm{act}}(t)|)(DEM only, Undirected only). -
current_count_out_sender(transformation, K, event_stream): Active Sender Out-Count: Total active events sent byi.s_{i,j}(t) = f(c_i^{\mathrm{out,act}}(t))(DEM only, Directed only). -
current_count_out_receiver(transformation, K, event_stream): Active Receiver Out-Count: Total active events sent byj.s_{i,j}(t) = f(c_j^{\mathrm{out,act}}(t))(DEM only, Directed only). -
current_count_in_sender(transformation, K, event_stream): Active Sender In-Count: Total active events received byi.s_{i,j}(t) = f(c_i^{\mathrm{in,act}}(t))(DEM only, Directed only). -
current_count_in_receiver(transformation, K, event_stream): Active Receiver In-Count: Total active events received byj.s_{i,j}(t) = f(c_j^{\mathrm{in,act}}(t))(DEM only, Directed only). -
current_count_sum(transformation, K, event_stream): Active Count Sum: Sum of active event counts of both endpoints.s_{i,j}(t) = f(c_i^{\mathrm{act}}(t) + c_j^{\mathrm{act}}(t))(DEM only, Undirected only). -
current_count_absdiff(transformation, K, event_stream): Active Count Absolute Difference: Absolute difference in active event counts.s_{i,j}(t) = f(|c_i^{\mathrm{act}}(t) - c_j^{\mathrm{act}}(t)|)(DEM only, Undirected only). -
degree(history, type, count, transformation, K, event_stream, window): Degree Shorthand: Dispatches to the appropriate degree statistic based onhistory("general"or"current") andtype("out_sender","out_receiver","in_sender","in_receiver","sum","absdiff"). Setcount = TRUEfor weighted (count-based) variants. Alias:degrees(). -
count(history, type, transformation, K, event_stream, window): Count Shorthand: Equivalent todegree(..., count = TRUE).
Exogenous Covariates
-
dyadic_cov(data, change_points): Dyadic Covariate: Time-constant or time-varying external dyadic covariate matrixX.s_{i,j}(t) = X_{i,j}(t). -
monadic_cov(data, fun, change_points): Monadic Covariate: External monadic covariate vectorxconverted to a dyadic matrix via user-supplied functiong.s_{i,j}(t) = g(x_i(t),\, x_j(t)).
Relational Event Model (REM) Estimation
Description
Estimates a Relational Event Model (REM) for network data, focusing on the
incidence of discrete events between pairs of actors.
See dem for the full Durational Event Model, which extends
the REM to handle interactions with non-negligible duration.
Usage
rem(
events,
training_start = 0,
exogenous_end = NULL,
formula = NULL,
n_nodes = NULL,
directed = FALSE,
coef = NULL,
semiparametric = FALSE,
control = control.redeem()
)
Arguments
events |
A matrix of events with columns |
training_start |
Numeric; the time point at which to start the estimation. Defaults to 0. |
exogenous_end |
Numeric; optional end time for exogenous baseline changes. Defaults to NULL. |
formula |
A one-sided |
n_nodes |
Integer; the total number of actors in the network. If |
directed |
Logical; whether the interaction events are directed. Defaults to FALSE. |
coef |
Numeric vector; initial coefficients for the model. If provided, this must be a concatenated vector of:
Defaults to NULL, in which case default starting values are automatically computed. |
semiparametric |
Logical; whether to use a semiparametric baseline. Defaults to FALSE. See the 'Semiparametric Baseline' section for details. |
control |
A list of control parameters from
|
Details
The REM can be viewed as the incidence sub-model of the full
dem, corresponding to the formation process
\lambda^{0\rightarrow 1}. It uses a counting process approach to
estimate the influence of various covariates on the timing and occurrence
of events, assuming that events are instantaneous points in time.
Value
An object of class rem_object containing model estimates
and log-likelihoods. See rem_object for details on the
components of the returned object and S3 methods.
Model Formulation
The Relational Event Model characterizes the instantaneous rate at which
actor pair (i,j) initiates an event. Under the log-linear
specification, the event intensity at time t is:
\lambda_{i,j}(t \mid \mathscr{H}_t,\, \theta) =
\exp\!\bigl(s_{i,j}(\mathscr{H}_t)^\top \alpha +
\beta_i + \beta_j + f(t, \gamma)\bigr)
where:
-
s_{i,j}(\mathscr{H}_t)is a vector of sufficient statistics computed from the event history\mathscr{H}_t; seeredeem_termsfor available terms. -
\alphais the vector of covariate effects. -
\beta_iand\beta_jare optional actor-specific baselines (sender and receiver sociality), included via the bare symboldegreein the formula. -
f(t, \gamma)is an optional piecewise-constant temporal baseline, included viabaseline(changepoints)in the formula.
Semiparametric Baseline
When semiparametric = TRUE, the temporal baseline rate of event occurrence
is left completely unspecified, and the model parameters are estimated via the Cox
partial likelihood using the survival package. In this path:
Each observed event time is treated as a failure time, and all non-occurring dyads at that time constitute the risk set.
The exact waiting times between events are conditioned away, meaning that inference is based solely on the sequence of events and the relative dyadic intensities.
This approach is equivalent to the ordered (or conditional) REM likelihood introduced by Butts (2008). It is highly robust to temporal fluctuations and baseline misspecification since no piecewise baseline or changepoints need to be specified.
-
Limitations: This path does not support the specialized scalable estimation of sender/receiver popularity effects (
degree) or piecewise-constant temporal baselines.
References
Fritz, C., Rastelli, R., Fop, M., & Caimo, A. (2026). Scalable Durational Event Models: Application to Physical and Digital Interactions. arXiv:2504.00049.
Butts, C. T. (2008). A Relational Event Framework for Social Action. Sociological Methodology, 38(1), 155-200.
Examples
# Simulate some relational event data
n <- 20
events <- matrix(c(
1.2, 1, 5,
3.1, 2, 8,
4.5, 1, 3
), ncol = 3, byrow = TRUE)
colnames(events) <- c("time", "from", "to")
# Estimate a simple REM
fit <- rem(
events = events,
n_nodes = n,
formula = ~1,
control = control.redeem(it_max = 50)
)
summary(fit)
Simulate a Relational Event Model (REM)
Description
Simulate a Relational Event Model (REM)
Usage
rem.simulate(
events = matrix(0, 0, 4),
formula,
coef = NULL,
coef_degree = 0,
n_events = 0,
time = 0,
max_events = 4e+05,
n_nodes,
verbose = FALSE,
baseline = NULL,
seed = 123,
block = 1,
directed = FALSE
)
Arguments
events |
A matrix representing the initial events with columns |
formula |
A one-sided |
coef |
Numeric vector; coefficients for the model. Defaults to NULL. |
coef_degree |
Numeric; degree coefficient. Defaults to 0. |
n_events |
Integer; number of events to simulate. Defaults to 0. |
time |
Numeric; simulation time. Defaults to 0. |
max_events |
Integer; maximum number of events. Defaults to 400000. |
n_nodes |
Integer; the total number of actors in the network. |
verbose |
Logical; if |
baseline |
Numeric vector; baseline intensity values for intervals defined by changepoints. Defaults to NULL. |
seed |
Integer; random seed. Defaults to 123. |
block |
An integer vector of length |
directed |
Logical; whether the interaction events are directed. Defaults to FALSE. |
Details
The block parameter allows the user to specify a partition of the nodes into different groups (blocks).
When the vector contains more than one unique block identifier:
The simulation suppresses all within-block dyad intensities by setting them to 0.
Consequently, only events between nodes belonging to different blocks are generated (between-block interactions).
If all nodes belong to the same block (e.g., if a single value or
NULLis passed), no block-level constraints are applied, and all dyads are simulated according to the specified model formula.
Value
A matrix of simulated events.
Note
Multi-stream event models are currently not supported in simulation.
Examples
# Simulate events from a REM model structure
n <- 10
f1 <- ~ 1 + inertia(transformation = "identity")
# Simulating events
evs <- rem.simulate(
formula = f1,
n_nodes = n,
time = 1.0,
coef = c(1.0, 0.5),
seed = 42,
max_events = 100
)
head(evs)
The rem Object
Description
An object of class rem returned by the rem function,
representing a fitted Relational Event Model.
Value
A rem object is a list containing the following components:
-
call: The matched call. -
event_numbers: A vector containing the number of events. -
model: The fitted underlying model. -
events: The preprocessed event matrix. -
formula: The formula used. -
n_nodes: The number of nodes. -
directed: Logical indicating whether the events are directed. -
build_time: The time at which the estimation dataset started building. -
max_time: The maximum event time. -
time_changepoints: Time points where baseline intensity changes. -
labels_changepoints: Labels for the time intervals. -
training_start: The start time of the training period. -
exogenous_end: The end time of the exogenous period. -
subsample: Subsample proportion used. -
return_data: Logical indicating whether preprocessed data frames were returned. -
runtime: The estimation runtime. -
window_map: The window map used for calculation. -
preprocessed: Preprocessed data structures.
Methods (S3)
The following S3 methods are implemented for rem objects:
-
print(x, ...): Prints a brief summary of the fitted REM model.-
x: Aremobject. -
...: Additional arguments passed to printing function.
-
-
summary(object, ...): Summarizes model results, including parameter estimates, standard errors, and fit statistics. Returns an object of classsummary.rem.-
object: Aremobject. -
...: Additional arguments passed to summary method.
-
-
plot(x, baseline = FALSE, ...): Generates trace plots for model coefficients and log-likelihood histories.-
x: Aremobject. -
baseline: Logical. IfTRUE, plots the estimated baseline step function. Defaults toFALSE. -
...: Additional arguments passed to underlying trace plotting method. Supported parameters include:-
coefs: Logical. IfTRUE(default), plots iteration traces for core/fixed coefficients. -
degree: Logical. IfTRUE(default), plots iteration traces for degree/actor effects. -
time: Logical. IfTRUE(default), plots iteration traces for temporal baseline effects. -
llh: Logical. IfTRUE(default), plots trace of log-likelihood history. -
separate: Logical. IfTRUE, each plot is generated in a new window or as a separate sequence. Defaults toFALSE. -
sub_label: Character. Optional subtitle to display at the bottom of the figure.
-
-
-
logLik(object, ...): Extracts the log-likelihood of the fitted model.-
object: Aremobject. -
...: Additional arguments.
-
-
plot_baseline(x, ...): Plots the step function of the estimated baseline intensity.-
x: Aremobject. -
...: Additional graphical parameters passed toplot.
-
-
predict(object, time = NULL, type = c("response", "lp", "terms"), ...): Predicts the intensity, linear predictor, or term contributions for a fitted REM model.-
object: Aremobject. -
time: Numeric vector; optional time point(s) at which to predict. Defaults to NULL. -
type: Character; the type of prediction. Defaults to"response". -
...: Additional arguments.
-
Reconstruct estimation data from a model object
Description
Reconstruct estimation data from a model object
Usage
reproduce_model_data(models, verbose = FALSE)
Arguments
models |
A redeem model object (rem or dem). |
verbose |
Logical. |
Convert right-hand side of a formula to a list of term information
Description
Convert right-hand side of a formula to a list of term information
Usage
rhs_terms_as_list(
formula,
n_nodes,
env = NULL,
evaluate_calls = FALSE,
model_type = "dem",
process = "0-1",
directed = FALSE
)
Arguments
formula |
The formula to parse. |
n_nodes |
Number of nodes. |
env |
The environment in which to evaluate terms. |
evaluate_calls |
Logical; if 'TRUE', evaluates the full calls. |
model_type |
Either "dem" or "rem". |
process |
Either "0-1" or "1-0". |
directed |
Logical; if TRUE, the model is directed. |
Value
A list of term information, including labels, base names, and data.
Standardize Estimation Output for Redeem Models
Description
Standardize Estimation Output for Redeem Models
Usage
standardize_redeem_result(
coefficients,
coef_hist,
covariance,
llh_hist,
data,
prediction,
method = "dem.nr",
n_nodes = NULL,
directed = FALSE,
time_changepoints = NULL,
labels_changepoints = NULL,
full_baseline = FALSE,
return_data = TRUE,
save_hist = TRUE
)
Arguments
coefficients |
Joint coefficient vector. |
coef_hist |
Matrix of coefficient history. |
covariance |
Covariance matrix for core effects. |
llh_hist |
Vector of log-likelihood history. |
data |
Input data. |
prediction |
Predicted values. |
method |
Estimation method name (for class). |
n_nodes |
Number of nodes. |
directed |
Logical; are the interaction events directed? |
time_changepoints |
Numeric vector of time changepoints. |
labels_changepoints |
Character vector of labels for the changepoints. |
return_data |
Logical; should the estimation dataset be returned? |
save_hist |
Logical; should the parameter history be returned? |
Summary of a redeem_result Model Fit
Description
Computes a summary of a fitted redeem_result object, collecting
the estimated fixed effects, log-likelihood, and (if present) degree and
temporal baseline effects into a structured list suitable for printing.
Usage
## S3 method for class 'redeem_result'
summary(object, ...)
Arguments
object |
A 'redeem_result' object. |
... |
Additional arguments (currently unused). |
Value
An object of class summary.redeem_result, which is a list
containing:
-
coefficients: A numeric matrix with one row per fixed-effect covariate and columnsEstimate,Std. Error,t value, andPr(>|t|). -
llh: The log-likelihood of the fitted model (scalar). -
degree_summary: A list with summary statistics (n,n_unidentifiable,mean,sd,range) of the estimated degree effects, only present when more than 10 degree parameters were estimated. -
degree_effects: A named numeric vector of estimated degree effects, only present when 10 or fewer degree parameters were estimated. -
time_summary: A list with summary statistics of the estimated temporal baseline effects, only present when more than 10 time intervals were used. -
time_effects: A named numeric vector of estimated temporal baseline effects, only present when 10 or fewer time intervals were used. -
iter: Integer; the number of iterations performed by the optimizer (NAif history was not saved).
Update core coefficients using R (for correctness assessment)
Description
Update core coefficients using R (for correctness assessment)
Usage
update_core_r(
data,
covarites,
prediction,
est_core,
identifiable,
offset_fixed = NULL
)
Arguments
data |
Preprocessed data.table. |
prediction |
Current predicted intensities. |
est_core |
Initial core coefficients. |
identifiable |
Logical vector indicating identifiable coefficients. |
offset_fixed |
Fixed offset (degree + baseline). |