RefineTimeScale: Subdivide interval data.

Description Usage Arguments Details Value Author(s) Examples

Description

Subdivides interval data on long-format into shorter intervals such that every value in intTimes is a boundary point of the subdivided intervals.

Usage

1
RefineTimeScale(A, startTimeName, stopTimeName, intTimes, endStatusName, intStatusName=NULL)

Arguments

A

Data frame with interval data on 'long-format'.

startTimeName

Name of column in A that contains the left boundaries for the intervals.

stopTimeName

Name of column in A that contains the right boundaries for the intervals.

intTimes

The time points that should subdivide the intervals in A.

endStatusNames

The names of the columns in A that contain the states that are observed at the right boundaries.

intStatusNames

The names of the columns in A that contain the interval states, i.e. the states at the interior and left boundaries for each interval. If this is left NULL, then the interval states are assumed to take the value FALSE.

Details

Each row represents a transition, that occurs at the end of the interval, from the interval state to the right boundary state. If endStatusName is NULL then the state at the imputed right boundaries are set to FALSE, otherwise they are set to the corresponding interval states. The remaining observations are assumed to occur at the left boundaries.

Value

Data frame with subdivided intervals.

Author(s)

Kjetil Røysland <kjetil.roysland@medisin.uio.no>

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
##---- Should be DIRECTLY executable !! ----
##-- ==>  Define data, use random,
##--	or do  help(data=index)  for the standard data sets.

## The function is currently defined as
function (A, startTimeName, stopTimeName, intTimes, endStatusName) 
{
    N <- nrow(A)
    q <- N * (length(intTimes) + 1)
    r <- .C("intersect", as.double(A[, startTimeName]), as.double(A[, 
        stopTimeName]), as.integer(N), as.double(intTimes), as.integer(length(intTimes)), 
        newIntStart = double(q), newIntStop = double(q), newOLine = integer(q), 
        newNRows = integer(1))
    W <- data.frame(r$newOLine, r$newIntStart, r$newIntStop)
    if (r$newNRows < q) 
        W <- W[-((r$newNRows + 1):q), ]
    names(W) <- c("imputation", startTimeName, stopTimeName)
    A <- A[, !(names(A) %in% c(startTimeName, stopTimeName))]
    A <- cbind(A, imputation = 1:N)
    A <- merge(W, A, by.x = "imputation", by.y = "imputation", 
        sort = FALSE)
    A$imputation <- duplicated(A$imputation, fromLast = TRUE)
    A[A$imputation, names(A) %in% as.character(endStatusName)] <- FALSE
    A <- subset(A, select = -imputation)
    return(A)
  }

kjetilroysland/ahw documentation built on May 20, 2019, 10:25 a.m.