Estimation API Reference
This page documents the functions for data loading, observation generation, and model fitting.
Data Loading
load_events
REM.load_events — Function
load_events(filepath::String; kwargs...) -> EventSequenceLoad events from a CSV file.
Arguments
filepath: Path to the CSV file
Keyword Arguments
sender_col::Symbol=:sender: Column name for sender IDsreceiver_col::Symbol=:receiver: Column name for receiver IDstime_col::Symbol=:time: Column name for timestampstype_col::Union{Symbol,Nothing}=nothing: Column name for event typesweight_col::Union{Symbol,Nothing}=nothing: Column name for event weightstime_type::Type=Float64: Type to parse timestamps asactor_names::Bool=false: If true, treat sender/receiver as names and assign numeric IDs
Returns
EventSequence: Sequence of loaded events
load_events(df::DataFrame; kwargs...) -> EventSequenceLoad events from a DataFrame.
Observation Generation
CaseControlSampler
REM.CaseControlSampler — Type
CaseControlSamplerGenerates 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 caseexclude_self_loops::Bool: Whether to exclude self-loops from samplingseed::Union{Int, Nothing}: Random seed for reproducibility
generate_observations
REM.generate_observations — Function
generate_observations(seq::EventSequence, stats::Vector{<:AbstractStatistic},
sampler::CaseControlSampler; kwargs...) -> DataFrameGenerate observations for model estimation using case-control sampling.
Arguments
seq::EventSequence: The event sequence to analyzestats::Vector{<:AbstractStatistic}: Statistics to computesampler::CaseControlSampler: Sampling configuration
Keyword Arguments
start_index::Int=1: Index of first event to includeend_index::Int=length(seq): Index of last event to includedecay::Float64=0.0: Exponential decay rate for network stateat_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
compute_statistics
REM.compute_statistics — Function
compute_statistics(seq::EventSequence, stats::Vector{<:AbstractStatistic};
decay::Float64=0.0) -> DataFrameCompute statistics for all events in a sequence (without sampling controls).
Returns
DataFrame: One row per event with computed statistics
Model Fitting
fit_rem
REM.fit_rem — Function
fit_rem(observations::DataFrame, stat_names::Vector{String}; kwargs...) -> REMResultFit a relational event model using stratified Cox regression.
Arguments
observations::DataFrame: Output fromgenerate_observationsstat_names::Vector{String}: Names of statistic columns to include in the model
Keyword Arguments
maxiter::Int=100: Maximum iterations for optimizationtol::Float64=1e-8: Convergence tolerance
Returns
REMResult: Fitted model results
fit_rem(seq::EventSequence, stats::Vector{<:AbstractStatistic}; kwargs...) -> REMResultFit a relational event model directly from an event sequence.
Arguments
seq::EventSequence: The event sequencestats::Vector{<:AbstractStatistic}: Statistics to include in the model
Keyword Arguments
n_controls::Int=100: Number of controls per casedecay::Float64=0.0: Exponential decay rateexclude_self_loops::Bool=true: Exclude self-loops from risk setseed::Union{Int,Nothing}=nothing: Random seedmaxiter::Int=100: Maximum iterationstol::Float64=1e-8: Convergence tolerance
Returns
REMResult: Fitted model results
REMResult
REM.REMResult — Type
REMResultResults from fitting a relational event model.
Fields
coefficients::Vector{Float64}: Estimated coefficientsstd_errors::Vector{Float64}: Standard errors of coefficientsz_values::Vector{Float64}: Z-statisticsp_values::Vector{Float64}: P-values (two-sided)stat_names::Vector{String}: Names of statisticsn_events::Int: Number of events in the modeln_observations::Int: Total number of observationslog_likelihood::Float64: Log-likelihood at convergenceconverged::Bool: Whether the optimization converged
Result Accessors
REM.stderror — Function
stderror(result::REMResult) -> Vector{Float64}Extract standard errors from a fitted model.
REM.coeftable — Function
coeftable(result::REMResult) -> DataFrameReturn coefficients as a DataFrame.
Utility Functions
Time Decay
REM.halflife_to_decay — Function
halflife_to_decay(halflife::Real) -> Float64Convert 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.
REM.decay_to_halflife — Function
decay_to_halflife(decay::Real) -> Float64Convert an exponential decay rate to a halflife parameter.
REM.compute_decay_weight — Function
compute_decay_weight(elapsed_time::Real, decay::Real) -> Float64Compute the exponential decay weight for a given elapsed time.