Learn R Programming

Epi (version 2.61)

xcutLexis: Cut follow-up in a Lexis object by event date(s) while preserving the original states. This is essentially a cross-classification of the original states and the new ones, hence the "x".

Description

With a multistate Lexis object we might want a classification of the follow-up according to a set of events independent of the states in the Lexis object, while keeping the the original states. This is what xcutLexis

Usage

xcutLexis(Lx, cut, timescale = 1, sep = ".")

Value

A Lexis object with states as in Lx plus states named by concatenating Lx state names with names in cut$new.state

Arguments

Lx

A Lexis object

cut

A data frame with at most one row per lex.id, columns must be:

  • lex.id: person-id referring to lex.id in Lx

  • cut, a numeric; times of event om the time scale timescale

  • new.state, character or factor; name of the new state occurring at time cut

timescale

The timescale that cut refers to. Numeric or character.

sep

Character; string used in forming new state names by joining original state names in Lx and state names in cut$new.states

Author

Bendix Carstensen, Steno Diabetes Center Copenhagen, b@bxc.dk, http://bendixcarstensen.com

Details

The function was motivated by a follow-up through states of multimorbidity with state names 0morb, 1morb, 2morb, etc. where we wanted a subdivision of each state by the presence of T2 diabetes, resulting in states 0morb, 1morb, 2morb, 0morb.T2, 1morb.T2, 2morb.T2.

At most 1 transition per person is allowed in cut.

See Also

mcutLexis, rcutLexis, addCov.Lexis, splitLexis, Lexis, summary.Lexis, timeSince, boxes.Lexis

Examples

Run this code
example(DMlate)
levels(dmi)
#
# show transitions between states in dmi
boxes(dmi, boxpos = list(x = rep(50, 4),
                         y = c(65, 35, 95, 5)),
           scale.R = 1000,
           show.BE = TRUE)
#
# randomly generated intermediate events X and Y
set.seed(1952)
cutXY <- data.frame(lex.id = unique(dmi$lex.id),          # one row per id
                       cut = runif(nid(dmi), 1995, 2008), # event dates
                 new.state = sample(c("X","Y"),           # event types
                                    nid(dmi),             # only 4 in 10 has an event
                                    repl = TRUE))[runif(nid(dmi)) < 0.4, ]
#
# cut at these event dates but also keep original states
Lxy <- xcutLexis(dmi, cutXY)
levels(Lxy)
#
# reorder the levels for easier specification of box places
Lxy <- Relevel(Lxy, as.vector(t(outer(levels(dmi),
                                      c("", ".X", ".Y"),
                                      paste0))))
levels(Lxy)
summary(Lxy)
#
# resulting transitions between boxes
boxes(Lxy, boxpos = list(x = rep(c(50, 15, 85), 4),
                         y = rep(c(65,35,95,5), each = 3)),
           scale.R = 1000,
           show.BE = TRUE,
           cex = 0.8)

Run the code above in your browser using DataLab