> library('epicalc')
> followup.plot(c$prontuario,c$dias,c$CD,by=c$iris)
Erro em get(search()[2]) : objeto 'package:rms' não encontrado
> followup.plot
function (id, time, outcome, by = NULL, n.of.lines = NULL, legend = TRUE,
legend.site = "topright", lty = "auto", line.col = "auto",
stress = NULL, stress.labels = FALSE, label.col = 1, stress.col = NULL,
stress.width = NULL, stress.type = NULL, lwd = 1, xlab, ylab,
...)
{
if (missing(xlab)) {
xlab <- as.character(substitute(time))
if (any(class(get(search()[2])) == "data.frame")) {
if (any(attr(get(search()[2]), "names") == as.character(substitute(xlab)))) {
if (!is.null(attr(get(search()[2]), "var.labels")[attr(get(search()[2]),
"names") == as.character(substitute(xlab))])) {
if (attr(get(search()[2]), "var.labels")[attr(get(search()[2]),
"names") == as.character(substitute(xlab))] !=
"") {
xlab <- attr(get(search()[2]), "var.labels")[attr(get(search()[2]),
"names") == as.character(substitute(xlab))]
}
}
}
}
}
if (missing(ylab)) {
ylab <- as.character(substitute(outcome))
if (any(class(get(search()[2])) == "data.frame")) {
if (any(attr(get(search()[2]), "names") == as.character(substitute(ylab)))) {
if (!is.null(attr(get(search()[2]), "var.labels")[attr(get(search()[2]),
"names") == as.character(substitute(ylab))])) {
if (attr(get(search()[2]), "var.labels")[attr(get(search()[2]),
"names") == as.character(substitute(ylab))] !=
"") {
ylab <- attr(get(search()[2]), "var.labels")[attr(get(search()[2]),
"names") == as.character(substitute(ylab))]
}
}
}
}
}
plot(time, outcome, xlab = xlab, ylab = ylab, type = "n",
lwd = lwd, ...)
if (any(lty == "auto"))
lty <- rep(1, length(id))
id1 <- id
time1 <- time
by1 <- by
outcome1 <- outcome
if (is.null(n.of.lines)) {
if (!is.null(by)) {
id <- id[order(id1, time1, by1)]
id.factor <- factor(id)
time <- time[order(id1, time1, by1)]
outcome <- outcome[order(id1, time1, by1)]
by <- by[order(id1, time1, by1)]
by.factor <- factor(by)
if (any(line.col == "auto")) {
line.col <- 1:length(levels(by.factor))
}
for (i in 1:length(levels(by.factor))) {
for (j in 1:length(levels(id.factor))) {
lines(time[id.factor == levels(id.factor)[j] &
by.factor == levels(by.factor)[i]], outcome[id.factor ==
levels(id.factor)[j] & by.factor == levels(by.factor)[i]],
col = line.col[i], lty = i, lwd = lwd)
}
}
if (legend) {
legend(x = legend.site, legend = levels(factor(by)),
col = line.col, bg = "white", lty = 1:length(levels(factor(by))),
lwd = lwd)
}
}
else {
id <- id[order(id1, time1)]
id.factor <- factor(id)
time <- time[order(id1, time1)]
outcome <- outcome[order(id1, time1)]
if (length(levels(factor(id))) < 8) {
if (any(line.col == "auto"))
line.col <- 1:length(levels(id.factor))
for (j in 1:length(levels(id.factor))) {
lines(time[id.factor == levels(id.factor)[j]],
outcome[id.factor == levels(id.factor)[j]],
col = line.col[j], lwd = lwd, lty = lty[j])
}
if (legend) {
legend(x = legend.site, legend = levels(factor(id[order(id1)])),
col = line.col[1:length(levels(factor(id)))],
bg = "white", lty = lty, lwd = lwd)
}
}
else {
for (j in 1:length(levels(id.factor))) {
if (any(line.col == "multicolor")) {
lines(time[id.factor == levels(id.factor)[j]],
outcome[id.factor == levels(id.factor)[j]],
col = j, lwd = lwd)
}
else {
if (any(line.col == "auto"))
line.col <- "blue"
lines(time[id.factor == levels(id.factor)[j]],
outcome[id.factor == levels(id.factor)[j]],
col = line.col, lwd = lwd)
}
}
}
}
}
else {
order.id.selected <- sample(c(rep(TRUE, n.of.lines),
rep(FALSE, length(levels(factor(id))) - n.of.lines)))
if (!is.null(by)) {
id <- id[order(id1, time1, by1)]
time <- time[order(id1, time1, by1)]
outcome <- outcome[order(id1, time1, by1)]
by <- by[order(id1, time1, by1)]
id.factor <- factor(id)
by.factor <- factor(by)
if (any(line.col == "auto"))
line.col <- 1:length(levels(by.factor))
for (i in 1:length(levels(by.factor))) {
for (j in 1:length(levels(id.factor))) {
lines(time[id.factor == levels(id.factor)[j] &
by.factor == levels(by.factor)[i]] * order.id.selected[j],
outcome[id.factor == levels(id.factor)[j] &
by.factor == levels(by.factor)[i]] * order.id.selected[j],
col = line.col[i], lty = i, lwd = lwd)
}
}
if (legend) {
legend(x = legend.site, legend = levels(factor(by)),
col = line.col[1:length(levels(factor(by)))],
lty = 1:length(levels(factor(by))), bg = "white",
lwd = lwd)
}
}
else {
id <- id[order(id1, time1)]
id.factor <- factor(id)
time <- time[order(id1, time1)]
outcome <- outcome[order(id1, time1)]
for (j in 1:length(levels(id.factor))) {
if (any(line.col == "multicolor")) {
lines(time[id.factor == levels(id.factor)[j]] *
order.id.selected[j], outcome[id.factor ==
levels(id.factor)[j]] * order.id.selected[j],
col = j, lwd = lwd)
}
else {
if (any(line.col == "auto")) {
line.col <- "blue"
}
lines(time[id.factor == levels(id.factor)[j]] *
order.id.selected[j], outcome[id.factor ==
levels(id.factor)[j]] * order.id.selected[j],
col = line.col, lwd = lwd)
}
}
}
}
for (j in 1:length(levels(id.factor))) {
text(time[id.factor == levels(id.factor)[j]], outcome[id.factor ==
levels(id.factor)[j]], labels = j, col = any(stress.labels *
stress %in% j) * label.col)
}
for (j in 1:length(levels(id.factor))) {
lines(time[id.factor == levels(id.factor)[j]], outcome[id.factor ==
levels(id.factor)[j]], col = any(stress %in% j) *
stress.col, lwd = stress.width, lty = stress.type)
}
}
|