Estimation API Reference

This page documents the functions for data loading, observation generation, and model fitting.

Data Loading

load_events

REM.load_eventsFunction
load_events(filepath::String; kwargs...) -> EventSequence

Load events from a CSV file.

Arguments

  • filepath: Path to the CSV file

Keyword Arguments

  • sender_col::Symbol=:sender: Column name for sender IDs
  • receiver_col::Symbol=:receiver: Column name for receiver IDs
  • time_col::Symbol=:time: Column name for timestamps
  • type_col::Union{Symbol,Nothing}=nothing: Column name for event types
  • weight_col::Union{Symbol,Nothing}=nothing: Column name for event weights
  • time_type::Type=Float64: Type to parse timestamps as
  • actor_names::Bool=false: If true, treat sender/receiver as names and assign numeric IDs

Returns

  • EventSequence: Sequence of loaded events
source
load_events(df::DataFrame; kwargs...) -> EventSequence

Load events from a DataFrame.

source

Observation Generation

CaseControlSampler

REM.CaseControlSamplerType
CaseControlSampler

Generates observations using case-control sampling. For each observed event (case), samples a specified number of non-events (controls) from the risk set.

Fields

  • n_controls::Int: Number of control samples per case
  • exclude_self_loops::Bool: Whether to exclude self-loops from sampling
  • seed::Union{Int, Nothing}: Random seed for reproducibility
source

generate_observations

REM.generate_observationsFunction
generate_observations(seq::EventSequence, stats::Vector{<:AbstractStatistic},
                      sampler::CaseControlSampler; kwargs...) -> DataFrame

Generate observations for model estimation using case-control sampling.

Arguments

  • seq::EventSequence: The event sequence to analyze
  • stats::Vector{<:AbstractStatistic}: Statistics to compute
  • sampler::CaseControlSampler: Sampling configuration

Keyword Arguments

  • start_index::Int=1: Index of first event to include
  • end_index::Int=length(seq): Index of last event to include
  • decay::Float64=0.0: Exponential decay rate for network state
  • at_risk::Union{Nothing, Set{Int}}=nothing: Set of actors "at risk" (if nothing, all actors)

Returns

  • DataFrame: Observations with columns for each statistic, plus is_event and stratum
source

compute_statistics

REM.compute_statisticsFunction
compute_statistics(seq::EventSequence, stats::Vector{<:AbstractStatistic};
                   decay::Float64=0.0) -> DataFrame

Compute statistics for all events in a sequence (without sampling controls).

Returns

  • DataFrame: One row per event with computed statistics
source

Model Fitting

fit_rem

REM.fit_remFunction
fit_rem(observations::DataFrame, stat_names::Vector{String}; kwargs...) -> REMResult

Fit a relational event model using stratified Cox regression.

Arguments

  • observations::DataFrame: Output from generate_observations
  • stat_names::Vector{String}: Names of statistic columns to include in the model

Keyword Arguments

  • maxiter::Int=100: Maximum iterations for optimization
  • tol::Float64=1e-8: Convergence tolerance

Returns

  • REMResult: Fitted model results
source
fit_rem(seq::EventSequence, stats::Vector{<:AbstractStatistic}; kwargs...) -> REMResult

Fit a relational event model directly from an event sequence.

Arguments

  • seq::EventSequence: The event sequence
  • stats::Vector{<:AbstractStatistic}: Statistics to include in the model

Keyword Arguments

  • n_controls::Int=100: Number of controls per case
  • decay::Float64=0.0: Exponential decay rate
  • exclude_self_loops::Bool=true: Exclude self-loops from risk set
  • seed::Union{Int,Nothing}=nothing: Random seed
  • maxiter::Int=100: Maximum iterations
  • tol::Float64=1e-8: Convergence tolerance

Returns

  • REMResult: Fitted model results
source

REMResult

REM.REMResultType
REMResult

Results from fitting a relational event model.

Fields

  • coefficients::Vector{Float64}: Estimated coefficients
  • std_errors::Vector{Float64}: Standard errors of coefficients
  • z_values::Vector{Float64}: Z-statistics
  • p_values::Vector{Float64}: P-values (two-sided)
  • stat_names::Vector{String}: Names of statistics
  • n_events::Int: Number of events in the model
  • n_observations::Int: Total number of observations
  • log_likelihood::Float64: Log-likelihood at convergence
  • converged::Bool: Whether the optimization converged
source

Result Accessors

REM.coefFunction
coef(result::REMResult) -> Vector{Float64}

Extract coefficients from a fitted model.

source
REM.stderrorFunction
stderror(result::REMResult) -> Vector{Float64}

Extract standard errors from a fitted model.

source
REM.coeftableFunction
coeftable(result::REMResult) -> DataFrame

Return coefficients as a DataFrame.

source

Utility Functions

Time Decay

REM.halflife_to_decayFunction
halflife_to_decay(halflife::Real) -> Float64

Convert a halflife parameter to an exponential decay rate. The decay rate λ is such that weight = exp(-λ * elapsed_time). At time = halflife, the weight is 0.5.

source
REM.decay_to_halflifeFunction
decay_to_halflife(decay::Real) -> Float64

Convert an exponential decay rate to a halflife parameter.

source
REM.compute_decay_weightFunction
compute_decay_weight(elapsed_time::Real, decay::Real) -> Float64

Compute the exponential decay weight for a given elapsed time.

source

Risk Set Utilities

Missing docstring.

Missing docstring for n_dyads. Check Documenter's build log for details.