TilburgNetworkGroup / remify

Processing and Transforming Relational Event History Data
https://tilburgnetworkgroup.github.io/remify/
Other
4 stars 1 forks source link

Time scale (for timestamps only) #25

Open jupepis opened 1 year ago

jupepis commented 1 year ago

We want to allow the user to define the scale of the waiting times, especially when the time variable is provided as timestamp

If the time variable is a timestamp, the reh$intereventTime will be measured in seconds by default.

We want to allow the user to specify a different scale for the interevent time:

For instance if the waiting time between t[m] and t[m-1] is, t[m]-t[m-1] = 2126 seconds, the user can convert it to:

Consider the loglikelihood of a tie-oriented model (but this consideration can also be adapted to the actor-oriented model)

$$ \log{\mathscr{L}}(\beta; E_{tM})=\sum{m=1}^{M}{\Bigg[X_{[e_m,.,m]}\beta-\left(tm-t{m-1}\right)\sum{e\in\mathcal{R}}^{}{\exp{\left\lbrace X{[e,.,m]}\beta\right\rbrace} }}\Bigg] $$

when waiting times are measured in seconds, at each time point the log-survival contribute from the risk set will tend to assume very large values.

$$ -\left(tm-t{m-1}\right)\sum{e\in\mathcal{R}}^{}{\exp{\left\lbrace X{[e,.,m]}\beta\right\rbrace}} $$

The conversion from seconds to minutes, to hours, or to days will affect the MLEs.

If we introduce the parameter $\kappa$ as a conversion factor

$$ \log{\mathscr{L}}(\beta; E_{tM}, \kappa)=\sum{m=1}^{M}{\Bigg[X_{[e_m,.,m]}\beta-\left(tm-t{m-1}\right)\kappa\sum{e\in\mathcal{R}}^{}{\exp{\left\lbrace X{[e,.,m]}\beta\right\rbrace} }}\Bigg] $$

Then

$$ \log{\mathscr{L}}(\beta; E_{tM})- \log{\mathscr{L}}(\beta; E{tM}, \kappa) = -\Bigg[\sum{m=1}^{M}{\left(tm-t{m-1}\right)\sum{e\in\mathcal{R}}^{}{\exp{\left\lbrace X{[e,.,m]}\beta\right\rbrace}}}\Bigg] + \kappa \Bigg[\sum_{m=1}^{M}{\left(tm-t{m-1}\right)\sum{e\in\mathcal{R}}^{}{\exp{\left\lbrace X{[e,.,m]}\beta\right\rbrace}}}\Bigg] = $$

$$ =\left(1-\kappa\right)\Bigg[-\sum_{m=1}^{M}{\left(tm-t{m-1}\right)\sum{e\in\mathcal{R}}^{}{\exp{\left\lbrace X{[e,.,m]}\beta\right\rbrace}}}\Bigg] $$

# waiting time as in the example
wt_seconds <- 2126 

# plotting in R
par(mfrow=c(2,2))
title_vec <- c("seconds", "minutes", "hours", "days")
kappa <- 1/c(1, 60, 60*60, 60*60*24)
for(p in 1:length(title_vec)) curve(-(wt_seconds*kappa[p])*exp(x),
                                                        from = -5,
                                                        to = 5,
                                                        main = title_vec[p],
                                                        xlab = "survival of one dyad",
                                                        ylab = "contribute to the likelihood")