xcutLexis | R Documentation |
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
".
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
xcutLexis(Lx, cut, timescale = 1, sep = ".")
Lx |
A |
cut |
A data frame with at most one row per
|
timescale |
The timescale that |
sep |
Character; string used in forming new state names by joining original
state names in |
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
.
A Lexis
object with states as in Lx
plus states named by
concatenating Lx
state names with names in cut$new.state
Bendix Carstensen, Steno Diabetes Center Copenhagen, b@bxc.dk, http://bendixcarstensen.com
mcutLexis
,
rcutLexis
,
addCov.Lexis
,
splitLexis
,
Lexis
,
summary.Lexis
,
timeSince
,
boxes.Lexis
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.