Description Usage Arguments Details Author(s) Examples
View source: R/plotContWeights.R
Plots weights for assessment.
1 | plotContWeights(fr, stopTimeName = "to", startStatusName = "from.state", endStatusName = "to.state", idName = "id")
|
fr |
Data with weight column |
stopTimeName |
Name of column with stop time of the at risk period, |
startStatusName |
Name of the variable that contains the name of start state for each at-risk interval, |
endStatusName |
Name of the variable that contains the name of end state for each at-risk interval, |
idName |
Name of column in |
The mean should be close to 1, and the individual trajectories should not be extreme(i.e. negative or large).
Pål Christie Ryalen <p.c.ryalen@medisin.uio.no>
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 | ##---- 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 (fr, stopTimeName = "to", startStatusName = "from.state",
endStatusName = "to.state", idName = "id")
{
namesMatch <- match(c(startStatusName, endStatusName, stopTimeName,
idName), names(fr))
names(fr)[namesMatch] <- c("from.state", "to.state", "to",
"id")
fr <- as.data.table(fr)
tms <- sort(unique(fr$to))
tmx <- max(tms)
idNs <- unique(fr$id)
numIds <- length(idNs)
fr[, `:=`(weights, c(weights[-1], weights[length(weights)])),
by = id]
wtIn <- fr$weights[fr$id == idNs[1]]
wt <- rep(NA, length(tms))
wt[1] <- 1
wt[match(fr[id == idNs[1]]$to, tms)] <- wtIn
wt <- naReplace(wt)
wpr <- wt
ylm <- c(max(c(0, min(fr$weights))), min(c(5, max(fr$weights))))
plot(tms, wt, type = "l", xlim = c(0, tmx), ylim = ylm, col = "grey",
xlab = "time", ylab = "weights")
for (i in 2:numIds) {
wtIn <- fr$weights[fr$id == idNs[i]]
wt <- rep(NA, length(tms))
wt[1] <- 1
wt[match(fr[id == idNs[i]]$to, tms)] <- wtIn
wt <- naReplace(wt)
lines(tms, wt, col = "grey")
if (any(is.na(wt)))
break
wpr <- wpr + wt
}
wpr <- wpr/numIds
lines(tms, wpr, col = "red")
cat("Mean weights: ", mean(wpr))
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.