File: splitLexisDT.Rd

package info (click to toggle)
r-cran-popepi 0.4.13%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,656 kB
  • sloc: sh: 13; makefile: 2
file content (85 lines) | stat: -rw-r--r-- 2,977 bytes parent folder | download
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/splitLexisDT.R
\name{splitLexisDT}
\alias{splitLexisDT}
\title{Split case-level observations}
\usage{
splitLexisDT(lex, breaks, timeScale, merge = TRUE, drop = TRUE)
}
\arguments{
\item{lex}{a Lexis object, split or not}

\item{breaks}{a vector of \verb{[a,b)} breaks to split \code{data} by}

\item{timeScale}{a character string; name of the time scale to split by}

\item{merge}{logical; if \code{TRUE}, retains all variables
from the original data - i.e. original variables are
repeated for all the rows by original subject}

\item{drop}{logical; if \code{TRUE}, drops all resulting rows
after expansion that reside outside the time window
defined by the given breaks}
}
\value{
A \code{data.table} or \code{data.frame}
(depending on \code{options("popEpi.datatable")}; see \code{?popEpi})
object expanded to accommodate split observations.
}
\description{
Split a \code{Lexis} object along one time scale
(as \verb{[Epi::splitLexis]}) with speed
}
\details{
\code{splitLexisDT} is in essence a \pkg{data.table} version of
\code{splitLexis} or \code{survSplit} for splitting along a single
time scale. It requires a Lexis object as input, which may have already
been split along some time scale.

Unlike \code{splitLexis}, \code{splitLexisDT} drops observed time outside
the roof and floor of \code{breaks} by default - with \code{drop = FALSE}
the functions have identical behaviour.

The \code{Lexis} time scale variables can be of any arbitrary
format, e.g. \code{Date},
fractional years (see \verb{[Epi::cal.yr]}) and \verb{[get.yrs]}.
}
\examples{
library(Epi)
data("sire", package = "popEpi")
x <- Lexis(data=sire[1000:1100, ],
           entry = list(fot=0, per=get.yrs(dg_date), age=dg_age),
           exit=list(per=get.yrs(ex_date)), exit.status=status)
BL <- list(fot=seq(0, 5, by = 3/12), per=c(2008, 2013))

x2 <- splitMulti(x, breaks = BL, drop = FALSE)

x3 <- splitLexisDT(x, breaks = BL$fot, timeScale = "fot", drop = FALSE)
x3 <- splitLexisDT(x3, breaks = BL$per, timeScale = "per", drop = FALSE)

x4 <- splitLexis(x,  breaks = BL$fot, time.scale = "fot")
x4 <- splitLexis(x4, breaks = BL$per, time.scale = "per")
## all produce identical results

## using Date variables
x <- Lexis(data=sire[1000:1100, ],
           entry = list(fot=0, per=dg_date, age=dg_date-bi_date),
           exit=list(per=ex_date), exit.status=status)
BL <- list(fot = 0:5*365.25, per = as.Date(c("2008-01-01", "2013-01-01")))

x2 <- splitMulti(x, breaks = BL, drop = FALSE)

x3 <- splitLexisDT(x, breaks = BL$fot, timeScale = "fot", drop = FALSE)
x3 <- splitLexisDT(x3, breaks = BL$per, timeScale = "per", drop = FALSE)

## splitLexis may not work when using Dates
}
\seealso{
Other splitting functions: 
\code{\link{lexpand}()},
\code{\link{splitMulti}()}
}
\author{
Joonas Miettinen
}
\concept{splitting functions}