
Compare candidate specifications with smooth (TV / NL / TVNL) effects
Source:R/compare_models_smooth.R
compare_models_smooth.RdSuperseded by rem(), which fits the same smooth (TV / NL / TVNL)
effects on preprocessed case-control data. compare_models_smooth() remains
fully supported.
Mirrors compare_models() but lets each statistic in a specification
take one of four effect types instead of a single linear coefficient:
linear, time-varying (TV), non-linear (NL), or jointly time-varying
non-linear (TVNL). The smooth machinery follows
Boschi, Lerner & Wit (2025); the matrix-of-event-vs-non-event trick
is documented in their Section 3.3.
For each specification:
One case-control sample is drawn from
event_logwithn_controls = 1(paired event / non-event design).For every requested statistic, both the case (event) and the control (non-event) features are computed via
endogenous_features().The mgcv design uses the case-vs-control matrix trick:
linear -> a single coefficient on
case - control(columnd_stat).tv ->
s(time, by = d_stat)— smooth in time, multiplied byd_stat.nl ->
s(stat_mat, by = I_mat)wherestat_matis a two-column matrixcbind(case, control)andI_matiscbind(1, -1).tvnl ->
te(time_mat, stat_mat, by = I_mat)tensor product smooth, with time_mat both columns equal to the event time vector.
The model is fitted with
mgcv::gamand a degenerate logistic likelihood: response =rep(1, n), formula =one ~ -1 + ...,family = binomial. This matches Boschi et al. equation 8.
AIC values are directly comparable across specifications because every
fit uses the same case-control sample. Returns the same tidy
data.frame as compare_models().
Arguments
- event_log
Data frame with
sender,receiver,timecolumns.- models
Named list of specifications. Each entry is itself a named character vector (or named list) mapping statistic names to effect types:
"linear","tv","nl", or"tvnl". Example:- scope, mode
Passed through to
sample_non_events().- half_life
Required when an exp-decay statistic is requested.
- k
Optional integer: knot count for
s()andte()terms. DefaultNULLletsmgcvchoose (-1).- seed
Integer seed for the case-control sample.
- keep_fits
Logical; when
TRUE, the returned table carries the fitted model objects (one per spec, named by model,NULLfor specs that failed) asattr(result, "fits"), e.g. for plotting estimated effects. Defaults toFALSE.
Value
Data frame with one row per specification and columns
model, n_terms, n_obs, log_lik, AIC, delta_AIC.
References
Boschi M, Lerner J, Wit EC (2025). Beyond Linearity and Time-Homogeneity: Relational Hyper Event Models with Time-Varying Non-Linear Effects. arXiv:2509.05289.
See also
compare_models() for the linear-only variant.
Examples
# \donttest{
data(classroom_events)
compare_models_smooth(
classroom_events,
models = list(
linear = c(reciprocity_time_recent = "linear",
transitivity_time_recent = "linear"),
nl = c(reciprocity_time_recent = "nl",
transitivity_time_recent = "nl"),
tvnl = c(reciprocity_time_recent = "tvnl",
transitivity_time_recent = "tvnl")),
seed = 11)
#> model n_terms n_obs log_lik AIC delta_AIC
#> 1 nl 2 691 -418.0982 845.8892 0.0000000
#> 2 linear 2 691 -421.1231 846.2462 0.3570575
#> 3 tvnl 2 691 -417.4186 848.6513 2.7620675
# }