age2dx: Constructing 'dx' from individual ages/times at deaths

Description Usage Arguments Author(s) See Also Examples

Description

The function converts ages/times at death into dx.. Notice that all ages at death are assumed to be exactly observed.

Internal function

Usage

1
age2dx(times, x)

Arguments

times

vector with age/times at deaths.

x

Beginning of the Age/time class. The resulting vector of dx will have the same length.

Author(s)

Maciej J. Danko <danko@demogr.mpg.de> <maciej.danko@gmail.com>

See Also

lx2dx, dx2lx, and dx2age.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# ************************** REMOVE THIS ******************************
# Some functions will not work as they are not in the namespace
# Before integrating with pash please add "pash:::" in front of them. 
# To test them just run all functions in the bootpash.r 
# ***************************** END ***********************************
## Not run: 

# ************************************************************************
# Data:
x <- c(0,0.5,2,5,10,13,15)
dx <- c(1,2,6,15,22,6,1)

# Should give the same vector as in dx.
age2dx(dx2age(dx,x),x)

# ************************************************************************
# Benchmark test for different procedures
library(microbenchmark)

# A dataset
times <- sample(0:1000, size = 100000, replace = TRUE) + 0.5
x <- 0:1000

# Default age2dx method based on hist()
age2dx.hist <- function(times, x) hist(x = times, plot = FALSE, 
               right = FALSE, breaks = c(x, x[length(x)] * 2))$counts
# Method based on cut()
age2dx.cut <- function(times, x) table(cut(times, c(x, x[length(x)] * 2), right = FALSE))
# Method based on findInterval()
age2dx.fi <- function(times, x) table(findInterval(times, x))

A <- age2dx.hist(times, x)
B <- age2dx.cut(times, x)
C <- age2dx.fi(times, x)

sum(abs(A-B)) # must be zero
sum(abs(B-C)) # must be zero

# hist() based method wins
microbenchmark(age2dx.hist(times, x), age2dx.cut(times, x), age2dx.fi(times, x))


## End(Not run)

MaciejDanko/BootstrapLT documentation built on May 14, 2019, 2:40 p.m.