arrivalTimeContinuous: arrivalTimeContinuous

Description Usage Arguments Examples

Description

A function for generating event times from a continuous rate function. For speed it requires the integral of the rate function. This can easily be zero inflated but will only keep the zero inflation if t0 = 0. It uses a random number from the uniform distribution followed by a binary search for the event time.

Usage

1
arrivalTimeContinuous(fun, t0 = 0, tmax = 10, acc = 0.05)

Arguments

fun

A function for the integral of the rate parameter. This should take exactly one input value for the time

t0

The time of the last arrival

tmax

The length of time to do the search in it will return a value in the interval t0 + tmax - acc < time < t0 + tmax if the time is right censored by tmax.

acc

The size of the interval to search for. The middle value of the interval is returned

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
# start time of 5 showing that for function(x) = x it matches the exponential distribution.
integralFun = function(x) x
par(mfrow = c(1,2))
hist(sapply(1:10000,function(x) arrivalTimeContinuous(integralFun,5,15)), freq = FALSE, breaks = 20,
     main = "Using arrivalTimeContinuous")
hist(rexp(10000,1), freq = FALSE, breaks = 20, main = "Using rexp")

integralFun = function(x) x^2/2
par(mfrow = c(1,2))
hist(sapply(1:10000,function(x) arrivalTimeContinuous(integralFun)), freq = FALSE, breaks = 20,
     main = "Using arrivalTimeContinuous")
hist(rexp(10000,1), freq = FALSE, breaks = 20, main = "Using rexp")

finite2/trialSim documentation built on May 16, 2019, 12:54 p.m.