Question: Arguments for z in simEventData() #9
-
First of all, this is an amazing versatile package. It is very useful, especially for simulating event data. I am currently looking at the following example from this vignette.
I was trying to modify this code to fix the values of
However, this does not work. Any suggestions how to have different but deterministic values for inputs of |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Thanks for the question. I do not have a good solution to it now. But the library(reda)
zFun3 <- function(time, a, b) cbind(time / 10 + a, as.numeric(time > b))
## workaround
set.seed(123)
a <- seq(0.1, by = 0.1, length.out = 3)
helper <- reda:::simEvent2data
simDat <- lapply(seq_along(a), function(i) {
res <- simEvent(z = zFun3,
zCoef = c(- 0.1, 0.5),
arguments = list(
z = list(a = a[i],
b = quote(runif(1, 1, 3)))))
helper(ID = i, res)
}) |> do.call(rbind, args = _)
str(simDat)
#> 'data.frame': 13 obs. of 6 variables:
#> $ ID : int 1 1 1 1 1 1 1 1 2 2 ...
#> $ time : num 0.582 1.925 1.957 2.013 2.333 ...
#> $ event : num 1 1 1 1 1 1 1 0 1 1 ...
#> $ origin: num 0 0 0 0 0 0 0 0 0 0 ...
#> $ X.1 : num 0.158 0.292 0.296 0.301 0.333 ...
#> $ X.2 : num 0 1 1 1 1 1 1 1 0 0 ...
#> - attr(*, "recurrent")= logi TRUE
## check the underlying "a"
with(simDat, cbind(ID, a = X.1 - time / 10))
#> ID a
#> [1,] 1 0.1
#> [2,] 1 0.1
#> [3,] 1 0.1
#> [4,] 1 0.1
#> [5,] 1 0.1
#> [6,] 1 0.1
#> [7,] 1 0.1
#> [8,] 1 0.1
#> [9,] 2 0.2
#> [10,] 2 0.2
#> [11,] 2 0.2
#> [12,] 2 0.2
#> [13,] 3 0.3 Created on 2023-04-14 with reprex v2.0.2 A note to myself: it seems that it would be helpful to have an internal variable such as |
Beta Was this translation helpful? Give feedback.
Thanks for the question. I do not have a good solution to it now. But the
simEventData()
is a simple wrapper function for thesimEvent()
function. Thus, a quick workaround can be as follows: